1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
66
67
68
69
73
74
75
79
80
81
82
91
92
93
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
133
134
135
136
139
140
143
144
145
146
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
174
175
176
179
180
181
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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
241
242
246
247
248
249
258
259
260
264
265
266
267
268
269
270
271
272
275
276
279
280
283
284
287
288
289
290
291
292
293
294
295
298
299
305
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
336
337
338
339
340
341
342
343
344
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
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
405
406
410
411
412
416
417
418
419
420
421
424
425
428
429
432
433
436
437
438
439
440
441
444
445
446
447
448
449
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
484
485
486
489
490
491
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
534
535
538
539
540
541
544
547
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
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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
633
634
635
636
637
641
644
645
646
647
648
649
650
651
655
656
657
661
662
663
664
665
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
697
698
703
704
705
709
710
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
736
737
740
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
774
775
779
780
781
782
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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
897
898
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
929
930
931
935
936
940
941
942
943
944
945
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
1003
1004
1008
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1043
1044
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
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
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
1145
1146
1152
1153
1156
1157
1158
1159
1160
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1181
1182
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
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
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
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
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
1324
1325
1330
1331
1332
1337
1338
1339
1340
1341
1342
1343
1355
1356
1357
1358
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1395
1396
1397
1398
1399
1400
1403
1404
1405
1408
1409
1410
1411
1414
1415
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
1450
1451
1452
1453
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1473
1474
1475
1476
1477
1482
1483
1484
1485
1486
1487
1490
1491
1492
1500
1501
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
1548
1549
1550
1551
1556
1557
1558
1563
1564
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
1604
1605
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
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
1666
1667
1668
1672
1673
1674
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1690
1694
1695
1696
1702
1703
1704
1705
1709
1710
1711
1717
1718
1719
1720
1721
1722
1723
1724
1725
1729
1730
1731
1732
1738
1739
1741
1742
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
1777
1778
1779
1780
1785
1786
1787
1792
1793
1794
1795
1796
1801
1802
1803
1804
1805
1806
1809
1813
1814
1819
1820
1821
1822
1823
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1849
1850
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
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
1910
1911
1912
1916
1917
1918
1919
1920
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1962
1963
1966
1967
1968
1969
1970
1971
1972
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
2009
2012
2013
2014
2015
2020
2021
2022
2023
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
2065
2068
2071
2074
2077
2080
2081
2082
2083
2084
2085
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
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
2250
2251
2259
2260
2261
2262
2263
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2302
2303
2304
2307
2308
2309
2310
2311
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
2351
2352
2353
2359
2365
2371
2377
2378
2379
2380
2381
2382
2383
2384
2389
2390
2395
2396
2397
2402
2403
2404
2409
2410
2411
2412
2417
2418
2423
2424
2425
2426
2427
2428
2429
2430
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2452
2454
2455
2456
/* ... */
/* ... */
#include <string.h>
#include <stdio.h>
#include "common/bt_trace.h"
#include "stack/bt_types.h"
#include "stack/hcidefs.h"
#include "stack/hcimsgs.h"
#include "stack/l2cdefs.h"
#include "l2c_int.h"
#include "stack/btu.h"
#include "stack/btm_api.h"
#include "osi/allocator.h"
#include "gatt_int.h"12 includes
#if (CLASSIC_BT_INCLUDED == TRUE)
/* ... */
UINT16 L2CA_Register (UINT16 psm, tL2CAP_APPL_INFO *p_cb_info)
{
tL2C_RCB *p_rcb;
UINT16 vpsm = psm;
/* ... */
if ((!p_cb_info->pL2CA_ConfigCfm_Cb)
|| (!p_cb_info->pL2CA_ConfigInd_Cb)
|| (!p_cb_info->pL2CA_DataInd_Cb)
|| (!p_cb_info->pL2CA_DisconnectInd_Cb)) {
L2CAP_TRACE_ERROR ("L2CAP - no cb registering PSM: 0x%04x", psm);
return (0);
}{...}
if (L2C_INVALID_PSM(psm)) {
L2CAP_TRACE_ERROR ("L2CAP - invalid PSM value, PSM: 0x%04x", psm);
return (0);
}{...}
if ( (psm >= 0x1001) && (p_cb_info->pL2CA_ConnectInd_Cb == NULL) ) {
for (vpsm = 0x1002; vpsm < 0x8000; vpsm += 2) {
if ((p_rcb = l2cu_find_rcb_by_psm (vpsm)) == NULL) {
break;
}{...}
}{...}
}{...}
if ((p_rcb = l2cu_find_rcb_by_psm (vpsm)) == NULL) {
if ((p_rcb = l2cu_allocate_rcb (vpsm)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no RCB available, PSM: 0x%04x vPSM: 0x%04x", psm, vpsm);
return (0);
}{...}
}{...}
p_rcb->api = *p_cb_info;
p_rcb->real_psm = psm;
return (vpsm);
}{...}
/* ... */
void L2CA_Deregister (UINT16 psm)
{
tL2C_RCB *p_rcb;
tL2C_CCB *p_ccb;
tL2C_LCB *p_lcb;
list_node_t *p_node = NULL;
if ((p_rcb = l2cu_find_rcb_by_psm (psm)) != NULL) {
for (p_node = list_begin(l2cb.p_lcb_pool); p_node; p_node = list_next(p_node)) {
p_lcb = list_node(p_node);
if (p_lcb->in_use) {
if (((p_ccb = p_lcb->ccb_queue.p_first_ccb) == NULL)
|| (p_lcb->link_state == LST_DISCONNECTING)) {
continue;
}{...}
if ((p_ccb->in_use) &&
((p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP) ||
(p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP))) {
continue;
}{...}
if (p_ccb->p_rcb == p_rcb) {
l2c_csm_execute (p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL);
}{...}
}{...}
}{...}
l2cu_release_rcb (p_rcb);
}{...} else {
L2CAP_TRACE_WARNING ("L2CAP - PSM: 0x%04x not found for deregistration", psm);
}{...}
}{...}
/* ... */
UINT16 L2CA_AllocatePSM(void)
{
BOOLEAN done = FALSE;
UINT16 psm = l2cb.dyn_psm;
while (!done) {
psm += 2;
if (psm > 0xfeff) {
psm = 0x1001;
}{...} else if (psm & 0x0100) {
psm += 0x0100;
}{...}
if ((BRCM_RESERVED_PSM_START <= psm) && (psm <= BRCM_RESERVED_PSM_END)) {
continue;
}{...}
if ((l2cu_find_rcb_by_psm (psm)) == NULL) {
done = TRUE;
}{...}
}{...}
l2cb.dyn_psm = psm;
return (psm);
}{...}
/* ... */
UINT16 L2CA_ConnectReq (UINT16 psm, BD_ADDR p_bd_addr)
{
return L2CA_ErtmConnectReq (psm, p_bd_addr, NULL);
}{...}
/* ... */
UINT16 L2CA_ErtmConnectReq (UINT16 psm, BD_ADDR p_bd_addr, tL2CAP_ERTM_INFO *p_ertm_info)
{
tL2C_LCB *p_lcb;
tL2C_CCB *p_ccb;
tL2C_RCB *p_rcb;
L2CAP_TRACE_API ("L2CA_ErtmConnectReq() PSM: 0x%04x BDA: %08x%04x p_ertm_info: %p allowed:0x%x preferred:%d", psm,
(p_bd_addr[0] << 24) + (p_bd_addr[1] << 16) + (p_bd_addr[2] << 8) + p_bd_addr[3],
(p_bd_addr[4] << 8) + p_bd_addr[5], p_ertm_info,
(p_ertm_info) ? p_ertm_info->allowed_modes : 0,
(p_ertm_info) ? p_ertm_info->preferred_mode : 0);
if (!BTM_IsDeviceUp()) {
L2CAP_TRACE_WARNING ("L2CAP connect req - BTU not ready");
return (0);
}{...}
if ((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no RCB for L2CA_conn_req, PSM: 0x%04x", psm);
return (0);
}{...}
if ((p_lcb = l2cu_find_lcb_by_bd_addr (p_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) {
if ( ((p_lcb = l2cu_allocate_lcb (p_bd_addr, FALSE, BT_TRANSPORT_BR_EDR)) == NULL)
|| (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == FALSE) ) {
L2CAP_TRACE_WARNING ("L2CAP - conn not started for PSM: 0x%04x p_lcb: %p", psm, p_lcb);
return (0);
}{...}
}{...}
if ((p_ccb = l2cu_allocate_ccb (p_lcb, 0)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_conn_req, PSM: 0x%04x", psm);
return (0);
}{...}
p_ccb->p_rcb = p_rcb;
if (p_ertm_info) {
p_ccb->ertm_info = *p_ertm_info;
if (p_ccb->ertm_info.fcr_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) {
p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE;
}{...}
if (p_ccb->ertm_info.fcr_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) {
p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE;
}{...}
if (p_ccb->ertm_info.user_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) {
p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE;
}{...}
if (p_ccb->ertm_info.user_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) {
p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE;
}{...}
p_ccb->max_rx_mtu = p_ertm_info->user_rx_buf_size -
(L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN);
}{...}
if (p_lcb->link_state == LST_CONNECTED) {
l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_REQ, NULL);
}{...}
/* ... */
else if (p_lcb->link_state == LST_DISCONNECTING) {
L2CAP_TRACE_DEBUG ("L2CAP API - link disconnecting: RETRY LATER");
p_lcb->p_pending_ccb = p_ccb;
}{...}
L2CAP_TRACE_API ("L2CAP - L2CA_conn_req(psm: 0x%04x) returned CID: 0x%04x", psm, p_ccb->local_cid);
return (p_ccb->local_cid);
}{...}
bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *callbacks)
{
assert(callbacks != NULL);
assert(callbacks->pL2CA_ConnectInd_Cb == NULL);
assert(callbacks->pL2CA_ConnectCfm_Cb != NULL);
assert(callbacks->pL2CA_ConfigInd_Cb != NULL);
assert(callbacks->pL2CA_ConfigCfm_Cb != NULL);
assert(callbacks->pL2CA_DisconnectInd_Cb != NULL);
assert(callbacks->pL2CA_DisconnectCfm_Cb != NULL);
assert(callbacks->pL2CA_CongestionStatus_Cb != NULL);
assert(callbacks->pL2CA_DataInd_Cb != NULL);
assert(callbacks->pL2CA_TxComplete_Cb != NULL);
tL2C_CCB *channel_control_block = l2cu_find_ccb_by_cid(NULL, local_cid);
if (!channel_control_block) {
L2CAP_TRACE_ERROR("%s no channel control block found for L2CAP LCID=0x%04x.", __func__, local_cid);
return false;
}{...}
tL2C_RCB *registration_control_block = channel_control_block->p_rcb;
if (!channel_control_block->should_free_rcb) {
registration_control_block = (tL2C_RCB *)osi_calloc(sizeof(tL2C_RCB));
if (!registration_control_block) {
L2CAP_TRACE_ERROR("%s unable to allocate registration control block.", __func__);
return false;
}{...}
*registration_control_block = *channel_control_block->p_rcb;
channel_control_block->p_rcb = registration_control_block;
channel_control_block->should_free_rcb = true;
}{...}
registration_control_block->api = *callbacks;
return true;
}{...}
/* ... */
BOOLEAN L2CA_ConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
UINT16 result, UINT16 status)
{
return L2CA_ErtmConnectRsp (p_bd_addr, id, lcid, result, status, NULL);
}{...}
/* ... */
BOOLEAN L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, UINT16 result,
UINT16 status, tL2CAP_ERTM_INFO *p_ertm_info)
{
tL2C_LCB *p_lcb;
tL2C_CCB *p_ccb;
L2CAP_TRACE_API ("L2CA_ErtmConnectRsp() CID: 0x%04x Result: %d Status: %d BDA: %08x%04x p_ertm_info:%p",
lcid, result, status,
(p_bd_addr[0] << 24) + (p_bd_addr[1] << 16) + (p_bd_addr[2] << 8) + p_bd_addr[3],
(p_bd_addr[4] << 8) + p_bd_addr[5], p_ertm_info);
if ((p_lcb = l2cu_find_lcb_by_bd_addr (p_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no LCB for L2CA_conn_rsp");
return (FALSE);
}{...}
if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_conn_rsp");
return (FALSE);
}{...}
if (p_ccb->remote_id != id) {
L2CAP_TRACE_WARNING ("L2CAP - bad id in L2CA_conn_rsp. Exp: %d Got: %d", p_ccb->remote_id, id);
return (FALSE);
}{...}
if (p_ertm_info) {
p_ccb->ertm_info = *p_ertm_info;
if (p_ccb->ertm_info.fcr_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) {
p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE;
}{...}
if (p_ccb->ertm_info.fcr_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) {
p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE;
}{...}
if (p_ccb->ertm_info.user_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) {
p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE;
}{...}
if (p_ccb->ertm_info.user_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) {
p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE;
}{...}
p_ccb->max_rx_mtu = p_ertm_info->user_rx_buf_size -
(L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN);
}{...}
if (result == L2CAP_CONN_OK) {
l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_RSP, NULL);
}{...} else {
tL2C_CONN_INFO conn_info;
conn_info.l2cap_result = result;
conn_info.l2cap_status = status;
if (result == L2CAP_CONN_PENDING) {
l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_RSP, &conn_info);
}{...} else {
l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_RSP_NEG, &conn_info);
}{...}
}{...}
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_ConfigReq (UINT16 cid, tL2CAP_CFG_INFO *p_cfg)
{
tL2C_CCB *p_ccb;
L2CAP_TRACE_API ("L2CA_ConfigReq() CID 0x%04x: fcr_present:%d (mode %d) mtu_present:%d (%d)",
cid, p_cfg->fcr_present, p_cfg->fcr.mode, p_cfg->mtu_present, p_cfg->mtu);
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_cfg_req, CID: %d", cid);
return (FALSE);
}{...}
if (!l2c_fcr_adj_our_req_options(p_ccb, p_cfg)) {
return (FALSE);
}{...}
if ((!p_cfg->fcr_present) || (p_cfg->fcr.mode == L2CAP_FCR_BASIC_MODE)) {
p_cfg->fcs_present = FALSE;
p_cfg->ext_flow_spec_present = FALSE;
if ( (p_cfg->mtu_present) && (p_cfg->mtu > L2CAP_MTU_SIZE) ) {
L2CAP_TRACE_WARNING ("L2CAP - adjust MTU: %u too large", p_cfg->mtu);
p_cfg->mtu = L2CAP_MTU_SIZE;
}{...}
}{...}
p_ccb->our_cfg = *p_cfg;
l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONFIG_REQ, p_cfg);
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_ConfigRsp (UINT16 cid, tL2CAP_CFG_INFO *p_cfg)
{
tL2C_CCB *p_ccb;
L2CAP_TRACE_API ("L2CA_ConfigRsp() CID: 0x%04x Result: %d MTU present:%d Flush TO:%d FCR:%d FCS:%d",
cid, p_cfg->result, p_cfg->mtu_present, p_cfg->flush_to_present, p_cfg->fcr_present, p_cfg->fcs_present);
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_cfg_rsp, CID: %d", cid);
return (FALSE);
}{...}
if ( (p_cfg->result == L2CAP_CFG_OK) || (p_cfg->result == L2CAP_CFG_PENDING) ) {
l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONFIG_RSP, p_cfg);
}{...} else {
p_cfg->fcr_present = FALSE;
if (p_cfg->mtu_present) {
p_ccb->peer_cfg.mtu_present = FALSE;
}{...}
if (p_cfg->flush_to_present) {
p_ccb->peer_cfg.flush_to_present = FALSE;
}{...}
if (p_cfg->qos_present) {
p_ccb->peer_cfg.qos_present = FALSE;
}{...}
l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONFIG_RSP_NEG, p_cfg);
}{...}
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_DisconnectReq (UINT16 cid)
{
tL2C_CCB *p_ccb;
L2CAP_TRACE_API ("L2CA_DisconnectReq() CID: 0x%04x", cid);
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_disc_req, CID: %d", cid);
return (FALSE);
}{...}
l2c_csm_execute (p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL);
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_DisconnectRsp (UINT16 cid)
{
tL2C_CCB *p_ccb;
L2CAP_TRACE_API ("L2CA_DisconnectRsp() CID: 0x%04x", cid);
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_disc_rsp, CID: %d", cid);
return (FALSE);
}{...}
l2c_csm_execute (p_ccb, L2CEVT_L2CA_DISCONNECT_RSP, NULL);
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_callback)
{
tL2C_LCB *p_lcb;
L2CAP_TRACE_API ("L2CA_Ping() BDA: %02x-%02x-%02x-%02x-%02x-%02x",
p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], p_bd_addr[3], p_bd_addr[4], p_bd_addr[5]);
if (!BTM_IsDeviceUp()) {
return (FALSE);
}{...}
if ((p_lcb = l2cu_find_lcb_by_bd_addr (p_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) {
if ((p_lcb = l2cu_allocate_lcb (p_bd_addr, FALSE, BT_TRANSPORT_BR_EDR)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no LCB for L2CA_ping");
return (FALSE);
}{...}
if (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == FALSE) {
return (FALSE);
}{...}
p_lcb->p_echo_rsp_cb = p_callback;
return (TRUE);
}{...}
if (p_lcb->p_echo_rsp_cb != NULL) {
L2CAP_TRACE_WARNING ("L2CAP - rejected second L2CA_ping");
return (FALSE);
}{...}
if (p_lcb->link_state == LST_DISCONNECTING) {
L2CAP_TRACE_WARNING ("L2CAP - L2CA_ping rejected - link disconnecting");
return (FALSE);
}{...}
p_lcb->p_echo_rsp_cb = p_callback;
if (p_lcb->link_state == LST_CONNECTED) {
l2cu_adj_id(p_lcb, L2CAP_ADJ_BRCM_ID);
l2cu_send_peer_echo_req (p_lcb, NULL, 0);
btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_ECHO_RSP_TOUT);
}{...}
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_Echo (BD_ADDR p_bd_addr, BT_HDR *p_data, tL2CA_ECHO_DATA_CB *p_callback)
{
tL2C_LCB *p_lcb;
UINT8 *pp;
L2CAP_TRACE_API ("L2CA_Echo() BDA: %08X%04X",
((p_bd_addr[0] << 24) + (p_bd_addr[1] << 16) + (p_bd_addr[2] << 8) + (p_bd_addr[3])),
((p_bd_addr[4] << 8) + (p_bd_addr[5])));
if (!BTM_IsDeviceUp()) {
return (FALSE);
}{...}
if ((memcmp(BT_BD_ANY, p_bd_addr, BD_ADDR_LEN) == 0) && (p_data == NULL)) {
l2cb.p_echo_data_cb = p_callback;
return TRUE;
}{...}
if ((p_lcb = l2cu_find_lcb_by_bd_addr (p_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) {
L2CAP_TRACE_ERROR ("L2CA_Echo ERROR : link not established");
return FALSE;
}{...}
if (p_lcb->link_state != LST_CONNECTED) {
L2CAP_TRACE_ERROR ("L2CA_Echo ERROR : link is not connected");
return FALSE;
}{...}
l2cb.p_echo_data_cb = p_callback;
pp = (UINT8 *)(p_data + 1) + p_data->offset;
l2cu_adj_id(p_lcb, L2CAP_ADJ_BRCM_ID);
l2cu_send_peer_echo_req (p_lcb, pp, p_data->len);
return (TRUE);
}{...}
/* ... */
#endif
bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t *rcid, uint16_t *handle)
{
tL2C_CCB *control_block = l2cu_find_ccb_by_cid(NULL, lcid);
if (!control_block) {
return false;
}{...}
if (rcid) {
*rcid = control_block->remote_cid;
}{...}
if (handle) {
*handle = control_block->p_lcb->handle;
}{...}
return true;
}{ ... }
/* ... */
BOOLEAN L2CA_SetIdleTimeout (UINT16 cid, UINT16 timeout, BOOLEAN is_global)
{
tL2C_CCB *p_ccb;
tL2C_LCB *p_lcb;
if (is_global) {
l2cb.idle_timeout = timeout;
}{...} else {
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SetIdleTimeout, CID: %d", cid);
return (FALSE);
}{...}
p_lcb = p_ccb->p_lcb;
if ((p_lcb) && (p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) {
p_lcb->idle_timeout = timeout;
}{...} else {
return (FALSE);
}{...}
}{...}
return (TRUE);
}{ ... }
/* ... */
BOOLEAN L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, UINT16 timeout, tBT_TRANSPORT transport)
{
tL2C_LCB *p_lcb;
list_node_t *p_node = NULL;
if (memcmp (BT_BD_ANY, bd_addr, BD_ADDR_LEN)) {
p_lcb = l2cu_find_lcb_by_bd_addr( bd_addr, transport);
if ((p_lcb) && (p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) {
p_lcb->idle_timeout = timeout;
if (!p_lcb->ccb_queue.p_first_ccb) {
l2cu_no_dynamic_ccbs (p_lcb);
}{...}
}{...} else {
return FALSE;
}{...}
}{...} else {
for (p_node = list_begin(l2cb.p_lcb_pool); p_node; p_node = list_next(p_node)) {
p_lcb = list_node(p_node);
if ((p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) {
p_lcb->idle_timeout = timeout;
if (!p_lcb->ccb_queue.p_first_ccb) {
l2cu_no_dynamic_ccbs (p_lcb);
}{...}
}{...}
}{...}
}{...}
return TRUE;
}{ ... }
/* ... */
UINT8 L2CA_SetTraceLevel (UINT8 new_level)
{
if (new_level != 0xFF) {
l2cb.l2cap_trace_level = new_level;
}{...}
return (l2cb.l2cap_trace_level);
}{ ... }
/* ... */
UINT8 L2CA_SetDesireRole (UINT8 new_role)
{
L2CAP_TRACE_API ("L2CA_SetDesireRole() new:x%x, disallow_switch:%d",
new_role, l2cb.disallow_switch);
if (L2CAP_ROLE_CHECK_SWITCH != (L2CAP_ROLE_CHECK_SWITCH & new_role)) {
if (new_role & L2CAP_ROLE_ALLOW_SWITCH) {
l2cb.disallow_switch = FALSE;
}{...}
if (new_role & L2CAP_ROLE_DISALLOW_SWITCH) {
l2cb.disallow_switch = TRUE;
}{...}
}{...}
if (new_role == HCI_ROLE_MASTER || new_role == HCI_ROLE_SLAVE) {
l2cb.desire_role = new_role;
}{...}
return (l2cb.desire_role);
}{ ... }
#if (CLASSIC_BT_INCLUDED == TRUE)
/* ... */
UINT16 L2CA_LocalLoopbackReq (UINT16 psm, UINT16 handle, BD_ADDR p_bd_addr)
{
tL2C_LCB *p_lcb;
tL2C_CCB *p_ccb;
tL2C_RCB *p_rcb;
L2CAP_TRACE_API ("L2CA_LocalLoopbackReq() PSM: %d Handle: 0x%04x", psm, handle);
if (!BTM_IsDeviceUp()) {
L2CAP_TRACE_WARNING ("L2CAP loop req - BTU not ready");
return (0);
}{...}
if ((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no RCB for L2CA_conn_req, PSM: %d", psm);
return (0);
}{...}
if ((p_lcb = l2cu_allocate_lcb (p_bd_addr, FALSE, BT_TRANSPORT_BR_EDR)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no LCB for L2CA_conn_req");
return (0);
}{...}
p_lcb->link_state = LST_CONNECTED;
p_lcb->handle = handle;
if ((p_ccb = l2cu_allocate_ccb (p_lcb, 0)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_conn_req");
return (0);
}{...}
p_ccb->p_rcb = p_rcb;
p_ccb->chnl_state = CST_OPEN;
p_ccb->remote_cid = p_ccb->local_cid;
p_ccb->config_done = CFG_DONE_MASK;
return (p_ccb->local_cid);
}{...}
/* ... */
BOOLEAN L2CA_SetAclPriority (BD_ADDR bd_addr, UINT8 priority)
{
L2CAP_TRACE_API ("L2CA_SetAclPriority() bdaddr: %02x%02x%02x%02x%04x, priority:%d",
bd_addr[0], bd_addr[1], bd_addr[2],
bd_addr[3], (bd_addr[4] << 8) + bd_addr[5], priority);
return (l2cu_set_acl_priority(bd_addr, priority, FALSE));
}{...}
/* ... */
BOOLEAN L2CA_FlowControl (UINT16 cid, BOOLEAN data_enabled)
{
tL2C_CCB *p_ccb;
BOOLEAN on_off = !data_enabled;
L2CAP_TRACE_API ("L2CA_FlowControl(%d) CID: 0x%04x", on_off, cid);
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_FlowControl, CID: 0x%04x data_enabled: %d", cid, data_enabled);
return (FALSE);
}{...}
if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE) {
L2CAP_TRACE_EVENT ("L2CA_FlowControl() invalid mode:%d", p_ccb->peer_cfg.fcr.mode);
return (FALSE);
}{...}
if (p_ccb->fcrb.local_busy != on_off) {
p_ccb->fcrb.local_busy = on_off;
if ( (p_ccb->chnl_state == CST_OPEN) && (!p_ccb->fcrb.wait_ack) ) {
if (on_off) {
l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0);
}{...} else {
l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_P_BIT);
}{...}
}{...}
}{...}
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_SendTestSFrame (UINT16 cid, UINT8 sup_type, UINT8 back_track)
{
tL2C_CCB *p_ccb;
L2CAP_TRACE_API ("L2CA_SendTestSFrame() CID: 0x%04x Type: 0x%02x back_track: %u", cid, sup_type, back_track);
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SendTestSFrame, CID: %d", cid);
return (FALSE);
}{...}
if ( (p_ccb->chnl_state != CST_OPEN) || (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE) ) {
return (FALSE);
}{...}
p_ccb->fcrb.next_seq_expected -= back_track;
l2c_fcr_send_S_frame (p_ccb, (UINT16)(sup_type & 3), (UINT16)(sup_type & (L2CAP_FCR_P_BIT | L2CAP_FCR_F_BIT)));
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_SetTxPriority (UINT16 cid, tL2CAP_CHNL_PRIORITY priority)
{
tL2C_CCB *p_ccb;
L2CAP_TRACE_API ("L2CA_SetTxPriority() CID: 0x%04x, priority:%d", cid, priority);
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SetTxPriority, CID: %d", cid);
return (FALSE);
}{...}
l2cu_change_pri_ccb (p_ccb, priority);
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_SetChnlDataRate (UINT16 cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHNL_DATA_RATE rx)
{
tL2C_CCB *p_ccb;
L2CAP_TRACE_API ("L2CA_SetChnlDataRate() CID: 0x%04x, tx:%d, rx:%d", cid, tx, rx);
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SetChnlDataRate, CID: %d", cid);
return (FALSE);
}{...}
p_ccb->tx_data_rate = tx;
p_ccb->rx_data_rate = rx;
l2c_link_adjust_chnl_allocation ();
return (TRUE);
}{...}
/* ... */
BOOLEAN L2CA_SetFlushTimeout (BD_ADDR bd_addr, UINT16 flush_tout)
{
tL2C_LCB *p_lcb;
UINT16 hci_flush_to;
UINT32 temp;
if (flush_tout == 0x0000) {
hci_flush_to = flush_tout;
flush_tout = L2CAP_NO_AUTOMATIC_FLUSH;
}{...}
else if (flush_tout == L2CAP_NO_RETRANSMISSION) {
hci_flush_to = flush_tout;
}{...}
else if (flush_tout == L2CAP_NO_AUTOMATIC_FLUSH) {
hci_flush_to = 0x0000;
}{...} else {
temp = (((UINT32)flush_tout * 8) + 3) / 5;
if (temp > HCI_MAX_AUTO_FLUSH_TOUT) {
L2CAP_TRACE_WARNING("WARNING L2CA_SetFlushTimeout timeout(0x%x) is out of range", flush_tout);
return FALSE;
}{...} else {
hci_flush_to = (UINT16)temp;
}{...}
}{...}
if (memcmp (BT_BD_ANY, bd_addr, BD_ADDR_LEN)) {
p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_BR_EDR);
if ((p_lcb) && (p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) {
if (p_lcb->link_flush_tout != flush_tout) {
p_lcb->link_flush_tout = flush_tout;
L2CAP_TRACE_API ("L2CA_SetFlushTimeout 0x%04x ms for bd_addr [...;%02x%02x%02x]",
flush_tout, bd_addr[3], bd_addr[4], bd_addr[5]);
if (!btsnd_hcic_write_auto_flush_tout (p_lcb->handle, hci_flush_to)) {
return (FALSE);
}{...}
}{...}
}{...} else {
L2CAP_TRACE_WARNING ("WARNING L2CA_SetFlushTimeout No lcb for bd_addr [...;%02x%02x%02x]",
bd_addr[3], bd_addr[4], bd_addr[5]);
return (FALSE);
}{...}
}{...} else {
list_node_t *p_node = NULL;
for (p_node = list_begin(l2cb.p_lcb_pool); p_node; p_node = list_next(p_node)) {
p_lcb = list_node(p_node);
if ((p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) {
if (p_lcb->link_flush_tout != flush_tout) {
p_lcb->link_flush_tout = flush_tout;
L2CAP_TRACE_API ("L2CA_SetFlushTimeout 0x%04x ms for bd_addr [...;%02x%02x%02x]",
flush_tout, p_lcb->remote_bd_addr[3],
p_lcb->remote_bd_addr[4], p_lcb->remote_bd_addr[5]);
if (!btsnd_hcic_write_auto_flush_tout(p_lcb->handle, hci_flush_to)) {
return (FALSE);
}{...}
}{...}
}{...}
}{...}
}{...}
return (TRUE);
}{...}
/* ... */#endif
/* ... */
BOOLEAN L2CA_GetPeerFeatures (BD_ADDR bd_addr, UINT32 *p_ext_feat, UINT8 *p_chnl_mask)
{
tL2C_LCB *p_lcb;
if ((p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) {
L2CAP_TRACE_WARNING ("L2CA_GetPeerFeatures() No BDA: %08x%04x",
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
(bd_addr[4] << 8) + bd_addr[5]);
return (FALSE);
}{...}
L2CAP_TRACE_API ("L2CA_GetPeerFeatures() BDA: %08x%04x ExtFea: 0x%08x Chnl_Mask[0]: 0x%02x",
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
(bd_addr[4] << 8) + bd_addr[5], p_lcb->peer_ext_fea, p_lcb->peer_chnl_mask[0]);
*p_ext_feat = p_lcb->peer_ext_fea;
memcpy (p_chnl_mask, p_lcb->peer_chnl_mask, L2CAP_FIXED_CHNL_ARRAY_SIZE);
return (TRUE);
}{ ... }
/* ... */
BOOLEAN L2CA_GetBDAddrbyHandle (UINT16 handle, BD_ADDR bd_addr)
{
tL2C_LCB *p_lcb = NULL;
BOOLEAN found_dev = FALSE;
p_lcb = l2cu_find_lcb_by_handle (handle);
if (p_lcb) {
found_dev = TRUE;
memcpy (bd_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN);
}{...}
return found_dev;
}{ ... }
#if (CLASSIC_BT_INCLUDED == TRUE)
/* ... */
UINT8 L2CA_GetChnlFcrMode (UINT16 lcid)
{
tL2C_CCB *p_ccb = l2cu_find_ccb_by_cid (NULL, lcid);
if (p_ccb) {
L2CAP_TRACE_API ("L2CA_GetChnlFcrMode() returns mode %d", p_ccb->peer_cfg.fcr.mode);
return (p_ccb->peer_cfg.fcr.mode);
}{...}
L2CAP_TRACE_API ("L2CA_GetChnlFcrMode() returns mode L2CAP_FCR_BASIC_MODE");
return (L2CAP_FCR_BASIC_MODE);
}{...}
/* ... */
#endif
#if (BLE_L2CAP_COC_INCLUDED == TRUE)
/* ... */
UINT16 L2CA_RegisterLECoc(UINT16 psm, tL2CAP_APPL_INFO *p_cb_info)
{
L2CAP_TRACE_API("%s called for LE PSM: 0x%04x", __func__, psm);
/* ... */
if ((!p_cb_info->pL2CA_DataInd_Cb)
|| (!p_cb_info->pL2CA_DisconnectInd_Cb))
{
L2CAP_TRACE_ERROR("%s No cb registering BLE PSM: 0x%04x", __func__, psm);
return 0;
}{...}
if (!L2C_IS_VALID_LE_PSM(psm))
{
L2CAP_TRACE_ERROR("%s Invalid BLE PSM value, PSM: 0x%04x", __func__, psm);
return 0;
}{...}
tL2C_RCB *p_rcb;
UINT16 vpsm = psm;
if ((psm >= 0x0080) && (p_cb_info->pL2CA_ConnectInd_Cb == NULL))
{
for (vpsm = 0x0080; vpsm < 0x0100; vpsm++)
{
p_rcb = l2cu_find_ble_rcb_by_psm(vpsm);
if (p_rcb == NULL) {
break;
}{...}
}{...}
L2CAP_TRACE_API("%s Real PSM: 0x%04x Virtual PSM: 0x%04x", __func__, psm, vpsm);
}{...}
p_rcb = l2cu_find_ble_rcb_by_psm(vpsm);
if (p_rcb == NULL)
{
p_rcb = l2cu_allocate_ble_rcb(vpsm);
if (p_rcb == NULL)
{
L2CAP_TRACE_WARNING("%s No BLE RCB available, PSM: 0x%04x vPSM: 0x%04x",
__func__, psm, vpsm);
return 0;
}{...}
}{...}
p_rcb->api = *p_cb_info;
p_rcb->real_psm = psm;
return vpsm;
}{...}
/* ... */
void L2CA_DeregisterLECoc(UINT16 psm)
{
L2CAP_TRACE_API("%s called for PSM: 0x%04x", __func__, psm);
tL2C_RCB *p_rcb = l2cu_find_ble_rcb_by_psm(psm);
if (p_rcb == NULL)
{
L2CAP_TRACE_WARNING("%s PSM: 0x%04x not found for deregistration", __func__, psm);
return;
}{...}
tL2C_LCB *p_lcb = NULL;
list_node_t *p_node = NULL;
for (p_node = list_begin(l2cb.p_lcb_pool); p_node; p_node = list_next(p_node)) {
p_lcb = list_node(p_node);
if (!p_lcb->in_use || p_lcb->transport != BT_TRANSPORT_LE) {
continue;
}{...}
tL2C_CCB *p_ccb = p_lcb->ccb_queue.p_first_ccb;
if ((p_ccb == NULL) || (p_lcb->link_state == LST_DISCONNECTING)) {
continue;
}{...}
if (p_ccb->in_use &&
(p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP ||
p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP)) {
continue;
}{...}
if (p_ccb->p_rcb == p_rcb) {
l2c_csm_execute(p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL);
}{...}
}{...}
l2cu_release_rcb (p_rcb);
}{...}
/* ... */
UINT16 L2CA_ConnectLECocReq(UINT16 psm, BD_ADDR p_bd_addr, tL2CAP_LE_CFG_INFO *p_cfg)
{
L2CAP_TRACE_API("%s PSM: 0x%04x BDA: %02x:%02x:%02x:%02x:%02x:%02x", __func__, psm,
p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], p_bd_addr[3], p_bd_addr[4], p_bd_addr[5]);
if (!BTM_IsDeviceUp())
{
L2CAP_TRACE_WARNING("%s BTU not ready", __func__);
return 0;
}{...}
tL2C_RCB *p_rcb = l2cu_find_ble_rcb_by_psm(psm);
if (p_rcb == NULL)
{
L2CAP_TRACE_WARNING("%s No BLE RCB, PSM: 0x%04x", __func__, psm);
return 0;
}{...}
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_LE);
if (p_lcb == NULL)
{
p_lcb = l2cu_allocate_lcb(p_bd_addr, FALSE, BT_TRANSPORT_LE);
if ((p_lcb == NULL)
|| (l2cu_create_conn(p_lcb, BT_TRANSPORT_LE) == FALSE) )
{
L2CAP_TRACE_WARNING("%s conn not started for PSM: 0x%04x p_lcb: 0x%p",
__func__, psm, p_lcb);
return 0;
}{...}
}{...}
tL2C_CCB *p_ccb = l2cu_allocate_ccb(p_lcb, 0);
if (p_ccb == NULL)
{
L2CAP_TRACE_WARNING("%s no CCB, PSM: 0x%04x", __func__, psm);
return 0;
}{...}
p_ccb->p_rcb = p_rcb;
if (p_cfg) {
memcpy(&p_ccb->local_conn_cfg, p_cfg, sizeof(tL2CAP_LE_CFG_INFO));
}{...}
if (p_lcb->link_state == LST_CONNECTED)
{
if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE)
{
L2CAP_TRACE_DEBUG("%s LE Link is up", __func__);
l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_REQ, NULL);
}{...}
}{...}
/* ... */
else if (p_lcb->link_state == LST_DISCONNECTING)
{
L2CAP_TRACE_DEBUG("%s link disconnecting: RETRY LATER", __func__);
p_lcb->p_pending_ccb = p_ccb;
}{...}
L2CAP_TRACE_API("%s(psm: 0x%04x) returned CID: 0x%04x", __func__, psm, p_ccb->local_cid);
return p_ccb->local_cid;
}{...}
/* ... */
BOOLEAN L2CA_ConnectLECocRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, UINT16 result,
UINT16 status, tL2CAP_LE_CFG_INFO *p_cfg)
{
L2CAP_TRACE_API("%s CID: 0x%04x Result: %d Status: %d BDA: %02x:%02x:%02x:%02x:%02x:%02x",
__func__, lcid, result, status,
p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], p_bd_addr[3], p_bd_addr[4], p_bd_addr[5]);
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_LE);
if (p_lcb == NULL)
{
L2CAP_TRACE_WARNING("%s no LCB", __func__);
return FALSE;
}{...}
tL2C_CCB *p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid);
if (p_ccb == NULL)
{
L2CAP_TRACE_WARNING("%s no CCB", __func__);
return FALSE;
}{...}
if (p_ccb->remote_id != id)
{
L2CAP_TRACE_WARNING("%s bad id. Expected: %d Got: %d", __func__, p_ccb->remote_id, id);
return FALSE;
}{...}
if (p_cfg) {
memcpy(&p_ccb->local_conn_cfg, p_cfg, sizeof(tL2CAP_LE_CFG_INFO));
}{...}
if (result == L2CAP_CONN_OK)
l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_RSP, NULL);
else
{
tL2C_CONN_INFO conn_info;
memcpy(conn_info.bd_addr, p_bd_addr, BD_ADDR_LEN);
conn_info.l2cap_result = result;
conn_info.l2cap_status = status;
l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_RSP_NEG, &conn_info);
}{...}
return TRUE;
}{...}
/* ... */
BOOLEAN L2CA_GetPeerLECocConfig (UINT16 lcid, tL2CAP_LE_CFG_INFO* peer_cfg)
{
L2CAP_TRACE_API ("%s CID: 0x%04x", __func__, lcid);
tL2C_CCB *p_ccb = l2cu_find_ccb_by_cid(NULL, lcid);
if (p_ccb == NULL)
{
L2CAP_TRACE_ERROR("%s No CCB for CID:0x%04x", __func__, lcid);
return FALSE;
}{...}
if (peer_cfg != NULL) {
memcpy(peer_cfg, &p_ccb->peer_conn_cfg, sizeof(tL2CAP_LE_CFG_INFO));
}{...}
return TRUE;
}{...}
/* ... */#endif
#if (L2CAP_NUM_FIXED_CHNLS > 0)
/* ... */
BOOLEAN L2CA_RegisterFixedChannel (UINT16 fixed_cid, tL2CAP_FIXED_CHNL_REG *p_freg)
{
L2CAP_TRACE_DEBUG ("L2CA_RegisterFixedChannel() CID: 0x%04x, %p", fixed_cid,p_freg);
if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL) ) {
L2CAP_TRACE_ERROR ("L2CA_RegisterFixedChannel() Invalid CID: 0x%04x", fixed_cid);
return (FALSE);
}{...}
l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL] = *p_freg;
return (TRUE);
}{ ... }
/* ... */
BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda, tBLE_ADDR_TYPE bd_addr_type, BOOLEAN is_aux)
{
tL2C_LCB *p_lcb;
tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
L2CAP_TRACE_API ("%s() CID: 0x%04x BDA: %08x%04x", __func__, fixed_cid,
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5]);
if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL)
|| (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == NULL) ) {
L2CAP_TRACE_ERROR ("%s() Invalid CID: 0x%04x", __func__, fixed_cid);
return (FALSE);
}{...}
if (!BTM_IsDeviceUp()) {
L2CAP_TRACE_WARNING ("%s(0x%04x) - BTU not ready", __func__, fixed_cid);
return (FALSE);
}{...}
#if BLE_INCLUDED == TRUE
if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) {
transport = BT_TRANSPORT_LE;
}{...}
#endif/* ... */
tL2C_BLE_FIXED_CHNLS_MASK peer_channel_mask;
if ((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, transport)) != NULL) {
#if BLE_INCLUDED == TRUE
if (transport == BT_TRANSPORT_LE) {
peer_channel_mask = l2cb.l2c_ble_fixed_chnls_mask;
}{...} else
#endif
{
peer_channel_mask = p_lcb->peer_chnl_mask[0];
}{...}
if (!(peer_channel_mask & (1 << fixed_cid))) {
L2CAP_TRACE_EVENT ("%s() CID:0x%04x BDA: %08x%04x not supported", __func__,
fixed_cid, (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
(rem_bda[4] << 8) + rem_bda[5]);
return FALSE;
}{...}
if (!l2cu_initialize_fixed_ccb (p_lcb, fixed_cid,
&l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) {
L2CAP_TRACE_WARNING ("%s(0x%04x) - LCB but no CCB", __func__, fixed_cid);
return FALSE;
}{...}
if (p_lcb->link_state == LST_DISCONNECTING) {
L2CAP_TRACE_DEBUG ("%s() - link disconnecting: RETRY LATER", __func__);
p_lcb->p_pending_ccb = p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL];
return TRUE;
}{...}
(*l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedConn_Cb)
(fixed_cid, p_lcb->remote_bd_addr, TRUE, 0, transport);
return TRUE;
}{...}
if ((p_lcb = l2cu_allocate_lcb (rem_bda, FALSE, transport)) == NULL) {
L2CAP_TRACE_WARNING ("%s(0x%04x) - no LCB", __func__, fixed_cid);
return FALSE;
}{...}
if (!l2cu_initialize_fixed_ccb (p_lcb, fixed_cid,
&l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) {
p_lcb->disc_reason = L2CAP_CONN_NO_RESOURCES;
L2CAP_TRACE_WARNING ("%s(0x%04x) - no CCB", __func__, fixed_cid);
l2cu_release_lcb (p_lcb);
return FALSE;
}{...}
#if (BLE_INCLUDED == TRUE)
p_lcb->is_aux = is_aux;
p_lcb->open_addr_type = bd_addr_type;/* ... */
#endif
if (!l2cu_create_conn(p_lcb, transport)) {
L2CAP_TRACE_WARNING ("%s() - create_conn failed", __func__);
l2cu_release_lcb (p_lcb);
return FALSE;
}{...}
return TRUE;
}{ ... }
/* ... */
UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf)
{
tL2C_LCB *p_lcb;
tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
L2CAP_TRACE_API ("L2CA_SendFixedChnlData() CID: 0x%04x BDA: %08x%04x", fixed_cid,
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5]);
#if BLE_INCLUDED == TRUE
if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) {
transport = BT_TRANSPORT_LE;
}{...}
#endif/* ... */
if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL)
|| (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == NULL) ) {
L2CAP_TRACE_ERROR ("L2CA_SendFixedChnlData() Invalid CID: 0x%04x", fixed_cid);
osi_free (p_buf);
return (L2CAP_DW_FAILED);
}{...}
if (!BTM_IsDeviceUp()) {
L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData(0x%04x) - BTU not ready", fixed_cid);
osi_free (p_buf);
return (L2CAP_DW_FAILED);
}{...}
if ((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, transport)) == NULL ||
p_lcb->link_state == LST_DISCONNECTING) {
L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData(0x%04x) - no LCB", fixed_cid);
osi_free (p_buf);
return (L2CAP_DW_FAILED);
}{...}
tL2C_BLE_FIXED_CHNLS_MASK peer_channel_mask;
#if BLE_INCLUDED == TRUE
if (transport == BT_TRANSPORT_LE) {
peer_channel_mask = l2cb.l2c_ble_fixed_chnls_mask;
}{...} else
#endif
{
peer_channel_mask = p_lcb->peer_chnl_mask[0];
}{...}
if ((peer_channel_mask & (1 << fixed_cid)) == 0) {
L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData() - peer does not support fixed chnl: 0x%04x", fixed_cid);
osi_free (p_buf);
return (L2CAP_DW_FAILED);
}{...}
p_buf->event = 0;
p_buf->layer_specific = L2CAP_FLUSHABLE_CH_BASED;
if (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]) {
if (!l2cu_initialize_fixed_ccb (p_lcb, fixed_cid, &l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) {
L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData() - no CCB for chnl: 0x%4x", fixed_cid);
osi_free (p_buf);
return (L2CAP_DW_FAILED);
}{...}
}{...}
if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent && fixed_cid != L2CAP_SMP_CID) {
L2CAP_TRACE_DEBUG ("L2CAP - CID: 0x%04x cannot send, already congested\
xmit_hold_q.count: %u buff_quota: %u", fixed_cid,
fixed_queue_length(p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->xmit_hold_q),
p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->buff_quota);
osi_free(p_buf);
return (L2CAP_DW_CONGESTED);
}{...}
l2c_enqueue_peer_data (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL], p_buf);
l2c_link_check_send_pkts (p_lcb, NULL, NULL);
if (p_lcb->in_use && p_lcb->link_state == LST_CONNECTED && !p_lcb->ccb_queue.p_first_ccb) {
l2cu_no_dynamic_ccbs (p_lcb);
}{...}
if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent) {
return (L2CAP_DW_CONGESTED);
}{...}
return (L2CAP_DW_SUCCESS);
}{ ... }
BOOLEAN L2CA_CheckIsCongest(UINT16 fixed_cid, BD_ADDR addr)
{
tL2C_LCB *p_lcb;
p_lcb = l2cu_find_lcb_by_bd_addr(addr, BT_TRANSPORT_LE);
if (p_lcb != NULL && p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL] != NULL) {
return p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent;
}{...}
return TRUE;
}{ ... }
#if (BLE_INCLUDED == TRUE)
UINT16 L2CA_GetFreePktBufferNum_LE(void)
{
return l2cb.controller_le_xmit_window;
}{ ... }
UINT16 L2CA_GetCurFreePktBufferNum_LE(UINT16 conn_id)
{
uint16_t num = 0;
tl2c_buff_param_t param;
param.conn_id = conn_id;
param.get_num = #
l2ble_update_att_acl_pkt_num(L2CA_GET_ATT_NUM, ¶m);
return num;
}{ ... }
#endif/* ... */
/* ... */
BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda)
{
tL2C_LCB *p_lcb;
tL2C_CCB *p_ccb;
tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL)
|| (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == NULL) ) {
L2CAP_TRACE_ERROR ("L2CA_RemoveFixedChnl() Invalid CID: 0x%04x", fixed_cid);
return (FALSE);
}{...}
#if BLE_INCLUDED == TRUE
if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) {
transport = BT_TRANSPORT_LE;
}{...}
#endif/* ... */
p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, transport);
if ( ((p_lcb) == NULL) || (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]) ) {
L2CAP_TRACE_DEBUG ("L2CA_RemoveFixedChnl() CID: 0x%04x BDA: %08x%04x not connected", fixed_cid,
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5]);
return (FALSE);
}{...}
L2CAP_TRACE_API ("L2CA_RemoveFixedChnl() CID: 0x%04x BDA: %08x%04x", fixed_cid,
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5]);
p_ccb = p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL];
p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL] = NULL;
p_lcb->disc_reason = HCI_ERR_CONN_CAUSE_LOCAL_HOST;
#if BLE_INCLUDED == TRUE
if ((fixed_cid == L2CAP_ATT_CID ) && !p_lcb->ccb_queue.p_first_ccb) {
p_lcb->idle_timeout = 0;
}{...}
#endif/* ... */
l2cu_release_ccb (p_ccb);
return (TRUE);
}{ ... }
#if BLE_INCLUDED == TRUE
BOOLEAN L2CA_BleDisconnect (BD_ADDR rem_bda)
{
tL2C_LCB *p_lcb;
tGATT_TCB *p_tcb;
p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE);
if (p_lcb == NULL) {
return FALSE;
}{...}
if (p_lcb->link_state != LST_CONNECTED) {
return FALSE;
}{...}
p_lcb->disc_reason = HCI_ERR_CONN_CAUSE_LOCAL_HOST;
p_lcb->link_state = LST_DISCONNECTING;
btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER);
p_tcb = gatt_find_tcb_by_addr(rem_bda, BT_TRANSPORT_LE);
if (p_tcb == NULL) {
return FALSE;
}{...}
gatt_set_ch_state(p_tcb, GATT_CH_CLOSING);
return TRUE;
}{ ... }
/* ... */#endif
/* ... */
BOOLEAN L2CA_SetFixedChannelTout (BD_ADDR rem_bda, UINT16 fixed_cid, UINT16 idle_tout)
{
tL2C_LCB *p_lcb;
tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
#if BLE_INCLUDED == TRUE
if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) {
transport = BT_TRANSPORT_LE;
}{...}
#endif/* ... */
if (fixed_cid<L2CAP_FIRST_FIXED_CHNL) {
return (FALSE);
}{...}
p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, transport);
if ( ((p_lcb) == NULL) || (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]) ) {
L2CAP_TRACE_WARNING ("L2CA_SetFixedChannelTout() CID: 0x%04x BDA: %08x%04x not connected", fixed_cid,
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5]);
return (FALSE);
}{...}
p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->fixed_chnl_idle_tout = idle_tout;
if (p_lcb->in_use && p_lcb->link_state == LST_CONNECTED && !p_lcb->ccb_queue.p_first_ccb) {
l2cu_no_dynamic_ccbs (p_lcb);
}{...}
return TRUE;
}{ ... }
/* ... */#endif
#if (CLASSIC_BT_INCLUDED == TRUE)
/* ... */
BOOLEAN L2CA_GetCurrentConfig (UINT16 lcid,
tL2CAP_CFG_INFO **pp_our_cfg, tL2CAP_CH_CFG_BITS *p_our_cfg_bits,
tL2CAP_CFG_INFO **pp_peer_cfg, tL2CAP_CH_CFG_BITS *p_peer_cfg_bits)
{
tL2C_CCB *p_ccb;
L2CAP_TRACE_API ("L2CA_GetCurrentConfig() CID: 0x%04x", lcid);
p_ccb = l2cu_find_ccb_by_cid(NULL, lcid);
if (p_ccb) {
*pp_our_cfg = &(p_ccb->our_cfg);
*p_our_cfg_bits = 0;
if (p_ccb->our_cfg.mtu_present) {
*p_our_cfg_bits |= L2CAP_CH_CFG_MASK_MTU;
}{...}
if (p_ccb->our_cfg.qos_present) {
*p_our_cfg_bits |= L2CAP_CH_CFG_MASK_QOS;
}{...}
if (p_ccb->our_cfg.flush_to_present) {
*p_our_cfg_bits |= L2CAP_CH_CFG_MASK_FLUSH_TO;
}{...}
if (p_ccb->our_cfg.fcr_present) {
*p_our_cfg_bits |= L2CAP_CH_CFG_MASK_FCR;
}{...}
if (p_ccb->our_cfg.fcs_present) {
*p_our_cfg_bits |= L2CAP_CH_CFG_MASK_FCS;
}{...}
if (p_ccb->our_cfg.ext_flow_spec_present) {
*p_our_cfg_bits |= L2CAP_CH_CFG_MASK_EXT_FLOW_SPEC;
}{...}
*pp_peer_cfg = &(p_ccb->peer_cfg);
*p_peer_cfg_bits = p_ccb->peer_cfg_bits;
return TRUE;
}{...} else {
L2CAP_TRACE_ERROR ("No CCB for CID:0x%04x", lcid);
return FALSE;
}{...}
}{...}
/* ... */
BOOLEAN L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda)
{
tL2C_LCB *p_lcb;
p_lcb = l2cu_find_lcb_by_bd_addr (p_bda, BT_TRANSPORT_BR_EDR);
if (!p_lcb) {
return FALSE;
}{...}
p_lcb->p_nocp_cb = p_cb;
return TRUE;
}{...}
/* ... */#endif
/* ... */
#if (CLASSIC_BT_INCLUDED == TRUE)
UINT8 L2CA_DataWrite (UINT16 cid, BT_HDR *p_data)
{
L2CAP_TRACE_API ("L2CA_DataWrite() CID: 0x%04x Len: %d", cid, p_data->len);
return l2c_data_write (cid, p_data, L2CAP_FLUSHABLE_CH_BASED);
}{...}
/* ... */#endif
/* ... */
#if (BT_CLASSIC_BQB_INCLUDED == TRUE)
void l2cap_bqb_write_data(UINT16 cid)
{
BT_HDR *p_buf;
uint8_t *p;
if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) != NULL) {
p_buf->len = 30;
p_buf->offset = L2CAP_MIN_OFFSET;
p = (UINT8 *)(p_buf + 1) + p_buf->offset;
for(int i = 0 ; i < 10; i++) {
UINT8_TO_BE_STREAM(p, 0)
}{...}
L2CA_DataWrite(cid, p_buf);
}{...}
}{...}
/* ... */#endif
/* ... */
BOOLEAN L2CA_SetChnlFlushability (UINT16 cid, BOOLEAN is_flushable)
{
#if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE)
tL2C_CCB *p_ccb;
if ((p_ccb = l2cu_find_ccb_by_cid (NULL, cid)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SetChnlFlushability, CID: %d", cid);
return (FALSE);
}{...}
p_ccb->is_flushable = is_flushable;
L2CAP_TRACE_API ("L2CA_SetChnlFlushability() CID: 0x%04x is_flushable: %d", cid, is_flushable);
/* ... */
#endif
return (TRUE);
}{ ... }
/* ... */
#if (CLASSIC_BT_INCLUDED == TRUE)
UINT8 L2CA_DataWriteEx (UINT16 cid, BT_HDR *p_data, UINT16 flags)
{
L2CAP_TRACE_API ("L2CA_DataWriteEx() CID: 0x%04x Len: %d Flags:0x%04X",
cid, p_data->len, flags);
return l2c_data_write (cid, p_data, flags);
}{...}
/* ... */#endif
/* ... */
UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush)
{
tL2C_CCB *p_ccb;
tL2C_LCB *p_lcb;
UINT16 num_left = 0,
num_flushed1 = 0,
num_flushed2 = 0;
p_ccb = l2cu_find_ccb_by_cid(NULL, lcid);
if ( !p_ccb || ((p_lcb = p_ccb->p_lcb) == NULL) ) {
L2CAP_TRACE_WARNING ("L2CA_FlushChannel() abnormally returning 0 CID: 0x%04x", lcid);
return (0);
}{...}
if (num_to_flush != L2CAP_FLUSH_CHANS_GET) {
L2CAP_TRACE_API ("L2CA_FlushChannel (FLUSH) CID: 0x%04x NumToFlush: %d QC: %u pFirst: %p",
lcid, num_to_flush,
fixed_queue_length(p_ccb->xmit_hold_q),
fixed_queue_try_peek_first(p_ccb->xmit_hold_q));
}{...} else {
L2CAP_TRACE_API ("L2CA_FlushChannel (QUERY) CID: 0x%04x", lcid);
}{...}
if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE) {
#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
if (num_to_flush != L2CAP_FLUSH_CHANS_GET) {
if ( (HCI_NON_FLUSHABLE_PB_SUPPORTED(BTM_ReadLocalFeatures ()))
&& (BTM_GetNumScoLinks() == 0) ) {
if ( l2cb.is_flush_active == FALSE ) {
l2cb.is_flush_active = TRUE;
btsnd_hcic_enhanced_flush (p_lcb->handle, 0);
}{...}
}{...}
}{...}
#endif/* ... */
for (const list_node_t *node = list_begin(p_lcb->link_xmit_data_q);
(num_to_flush > 0) && node != list_end(p_lcb->link_xmit_data_q);) {
BT_HDR *p_buf = (BT_HDR *)list_node(node);
node = list_next(node);
if ((p_buf->layer_specific == 0) && (p_buf->event == lcid)) {
num_to_flush--;
num_flushed1++;
list_remove(p_lcb->link_xmit_data_q, p_buf);
osi_free(p_buf);
}{...}
}{...}
}{...}
while ( (num_to_flush != 0) && (!fixed_queue_is_empty(p_ccb->xmit_hold_q))) {
BT_HDR *p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->xmit_hold_q, 0);
if (p_buf) {
osi_free (p_buf);
}{...}
num_to_flush--;
num_flushed2++;
}{...}
if ( (p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_TxComplete_Cb) && (num_flushed2) ) {
(*p_ccb->p_rcb->api.pL2CA_TxComplete_Cb)(p_ccb->local_cid, num_flushed2);
}{...}
for (const list_node_t *node = list_begin(p_lcb->link_xmit_data_q);
node != list_end(p_lcb->link_xmit_data_q);
node = list_next(node)) {
BT_HDR *p_buf = (BT_HDR *)list_node(node);
if (p_buf->event == lcid) {
num_left++;
}{...}
}{...}
num_left += fixed_queue_length(p_ccb->xmit_hold_q);
L2CAP_TRACE_DEBUG ("L2CA_FlushChannel() flushed: %u + %u, num_left: %u", num_flushed1, num_flushed2, num_left);
l2cu_check_channel_congestion (p_ccb);
return (num_left);
}{ ... }
/* ... */
#if BLE_INCLUDED == TRUE
void l2ble_update_att_acl_pkt_num(UINT8 type, tl2c_buff_param_t *param)
{
static SemaphoreHandle_t buff_semaphore = NULL ;
static INT16 btc_buf;
static INT16 btu_buf;
if(buff_semaphore == NULL && type != L2CA_BUFF_INI){
L2CAP_TRACE_ERROR("%s buff_semaphore not init", __func__);
return;
}{...}
switch (type)
{
case L2CA_ADD_BTC_NUM:{
xSemaphoreTake(buff_semaphore, portMAX_DELAY);
btc_buf ++;
xSemaphoreGive(buff_semaphore);
break;
}{...}
case L2CA_DECREASE_BTC_NUM:{
xSemaphoreTake(buff_semaphore, portMAX_DELAY);
btc_buf --;
xSemaphoreGive(buff_semaphore);
break;
}{...}
case L2CA_ADD_BTU_NUM:{
xSemaphoreTake(buff_semaphore, portMAX_DELAY);
btu_buf ++;
xSemaphoreGive(buff_semaphore);
break;
}{...}
case L2CA_DECREASE_BTU_NUM:{
xSemaphoreTake(buff_semaphore, portMAX_DELAY);
btu_buf --;
xSemaphoreGive(buff_semaphore);
break;
}{...}
case L2CA_GET_ATT_NUM:{
xSemaphoreTake(buff_semaphore, portMAX_DELAY);
INT16 att_acl_pkt_num = 0;
INT16 att_max_num = 0;
*(param->get_num) = 0;
UINT8 tcb_idx = param->conn_id;
tGATT_TCB * p_tcb = gatt_get_tcb_by_idx(tcb_idx);
if (p_tcb == NULL){
L2CAP_TRACE_ERROR("%s not found p_tcb", __func__);
xSemaphoreGive(buff_semaphore);
break;
}{...}
if (!gatt_check_connection_state_by_tcb(p_tcb)) {
L2CAP_TRACE_ERROR("connection not established\n");
xSemaphoreGive(buff_semaphore);
break;
}{...}
tL2C_LCB * p_lcb = l2cu_find_lcb_by_bd_addr (p_tcb->peer_bda, BT_TRANSPORT_LE);
if (p_lcb == NULL){
L2CAP_TRACE_ERROR("%s not found p_lcb", __func__);
xSemaphoreGive(buff_semaphore);
break;
}{...}
tL2C_CCB *p_ccb = p_lcb->p_fixed_ccbs[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL];
if(p_ccb == NULL) {
L2CAP_TRACE_ERROR("%s not found p_ccb", __func__);
xSemaphoreGive(buff_semaphore);
break;
}{...}
fixed_queue_t * queue = p_ccb->xmit_hold_q;
att_max_num = MIN(p_lcb->link_xmit_quota, L2CAP_CACHE_ATT_ACL_NUM);
if (queue == NULL){
L2CAP_TRACE_ERROR("%s not found queue", __func__);
xSemaphoreGive(buff_semaphore);
break;
}{...}
att_acl_pkt_num = fixed_queue_length(queue);
if(att_acl_pkt_num < att_max_num){
if(btc_buf + btu_buf < att_max_num - att_acl_pkt_num){
*(param->get_num) = att_max_num - att_acl_pkt_num - (btc_buf + btu_buf);
}{...}
}{...}
xSemaphoreGive(buff_semaphore);
break;
}{...}
case L2CA_BUFF_INI:{
btc_buf = 0;
btu_buf = 0;
buff_semaphore = xSemaphoreCreateBinary();
if (buff_semaphore == NULL) {
L2CAP_TRACE_ERROR("%s NO MEMORY", __func__);
break;
}{...}
xSemaphoreGive(buff_semaphore);
break;
}{...}
case L2CA_BUFF_DEINIT:{
xSemaphoreTake(buff_semaphore, portMAX_DELAY);
btc_buf = 0;
btu_buf = 0;
xSemaphoreGive(buff_semaphore);
vSemaphoreDelete(buff_semaphore);
buff_semaphore = NULL;
break;
}{...}
case L2CA_BUFF_FREE:{
xSemaphoreTake(buff_semaphore, portMAX_DELAY);
xSemaphoreGive(buff_semaphore);
break;
}{...}
default:
break;...
}{...}
}{ ... }
/* ... */#endif