1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
46
47
48
49
52
53
54
55
56
57
58
59
60
61
62
64
65
66
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
136
137
138
139
149
150
157
158
163
164
165
166
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
218
219
220
229
230
239
240
247
248
249
250
251
252
253
254
257
258
259
260
261
262
263
270
271
272
273
274
275
276
277
281
282
283
284
286
290
295
298
303
304
305
306
307
308
309
310
311
312
313
314
315
316
320
321
339
340
341
342
343
344
345
350
351
356
357
358
359
360
361
362
363
364
365
366
367
370
371
372
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
392
393
400
403
404
405
406
407
408
409
412
413
414
415
416
417
423
424
425
426
427
428
429
430
434
435
438
439
440
441
442
443
444
447
448
449
456
457
458
459
460
461
462
475
476
482
483
487
488
496
497
505
506
507
508
509
510
513
514
515
516
517
523
524
530
531
537
538
544
545
546
547
548
549
550
553
554
555
556
557
564
565
571
572
577
578
579
584
585
586
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
637
638
639
640
641
642
643
644
645
646
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
672
673
674
675
676
677
681
682
683
684
685
686
687
688
689
690
691
692
693
697
698
699
700
701
702
703
706
707
708
709
710
711
712
716
717
718
719
720
721
722
723
724
727
728
729
730
731
732
733
734
735
738
739
740
741
742
766
767
771
772
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
797
798
799
800
801
802
803
804
805
806
812
813
819
820
826
827
833
834
840
841
847
848
854
855
861
862
863
864
865
866
867
868
869
870
871
872
873
874
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
981
982
983
987
988
989
990
991
992
993
994
997
998
999
1000
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1050
1051
1052
1053
1056
1057
1058
1059
1060
1061
1062
1065
1066
1067
1068
1069
1070
1071
1075
1076
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1164
1165
1166
1167
1168
1169
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1185
1186
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1278
1279
1281
1285
1286
1287
1288
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1309
1310
1311
1312
1313
1314
1315
1320
1321
1327
1328
1329
1330
1331
1332
1333
1334
1335
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1385
1386
1387
1388
1389
1390
1391
1392
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1478
1479
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1624
1625
1626
1627
1628
1629
1630
1631
1632
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1670
1671
1672
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1726
1727
1728
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1819
1820
1821
1825
1826
1827
1832
1833
1834
1835
1836
1837
1838
1839
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1859
1860
1861
1862
/* ... */
#include <string.h>
#include <stdio.h>
#include "bta/bta_hf_client_api.h"
#include "bta_hf_client_int.h"
#include "stack/port_api.h"
#include "osi/allocator.h"6 includes
#if (BTA_HF_INCLUDED == TRUE)
#define BTA_HF_CLIENT_AT_EVENT_MIN_LEN 3
#define BTA_HF_CLIENT_AT_TIMEOUT 29989
#define BTA_HF_CLIENT_AT_HOLD_TIMEOUT 41
/* ... */
extern tBTA_HF_CLIENT_CB bta_hf_client_cb;
/* ... */
#define BTA_HF_CLIENT_INDICATOR_BATTERYCHG "battchg"
#define BTA_HF_CLIENT_INDICATOR_SIGNAL "signal"
#define BTA_HF_CLIENT_INDICATOR_SERVICE "service"
#define BTA_HF_CLIENT_INDICATOR_CALL "call"
#define BTA_HF_CLIENT_INDICATOR_ROAM "roam"
#define BTA_HF_CLIENT_INDICATOR_CALLSETUP "callsetup"
#define BTA_HF_CLIENT_INDICATOR_CALLHELD "callheld"
#define MIN(a, b) \
({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); (_a < _b) ? _a : _b; })...
8 defines
typedef struct {
char *name;
UINT8 min;
UINT8 max;
UINT8 namelen;
}{...} tBTA_HF_CLIENT_INDICATOR;
#define BTA_HF_CLIENT_AT_SUPPORTED_INDICATOR_COUNT 7
static const tBTA_HF_CLIENT_INDICATOR bta_hf_client_indicators[BTA_HF_CLIENT_AT_SUPPORTED_INDICATOR_COUNT] = {
{BTA_HF_CLIENT_INDICATOR_CALL, 0, 1, sizeof(BTA_HF_CLIENT_INDICATOR_CALL)},
{BTA_HF_CLIENT_INDICATOR_CALLSETUP, 0, 3, sizeof(BTA_HF_CLIENT_INDICATOR_CALLSETUP)},
{BTA_HF_CLIENT_INDICATOR_SERVICE, 0, 1, sizeof(BTA_HF_CLIENT_INDICATOR_SERVICE)},
{BTA_HF_CLIENT_INDICATOR_SIGNAL, 0, 5, sizeof(BTA_HF_CLIENT_INDICATOR_SIGNAL)},
{BTA_HF_CLIENT_INDICATOR_ROAM, 0, 1, sizeof(BTA_HF_CLIENT_INDICATOR_ROAM)},
{BTA_HF_CLIENT_INDICATOR_BATTERYCHG, 0, 5, sizeof(BTA_HF_CLIENT_INDICATOR_BATTERYCHG)},
{BTA_HF_CLIENT_INDICATOR_CALLHELD, 0, 2, sizeof(BTA_HF_CLIENT_INDICATOR_CALLHELD)}
}{...};
#define BTA_HF_CLIENT_VGS_MIN 0
#define BTA_HF_CLIENT_VGS_MAX 15
#define BTA_HF_CLIENT_VGM_MIN 0
#define BTA_HF_CLIENT_VGM_MAX 15
UINT32 service_index = 0;
BOOLEAN service_availability = TRUE;
static void bta_hf_client_handle_ok(void);
static void bta_hf_client_clear_queued_at(void)
{
tBTA_HF_CLIENT_AT_QCMD *cur = bta_hf_client_cb.scb.at_cb.queued_cmd;
tBTA_HF_CLIENT_AT_QCMD *next;
while (cur != NULL) {
next = cur->next;
osi_free(cur);
cur = next;
}{...}
bta_hf_client_cb.scb.at_cb.queued_cmd = NULL;
}{...}
static void bta_hf_client_queue_at(tBTA_HF_CLIENT_AT_CMD cmd, const char *buf, UINT16 buf_len)
{
tBTA_HF_CLIENT_AT_QCMD *new_cmd;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if ((new_cmd = (tBTA_HF_CLIENT_AT_QCMD *) osi_malloc(sizeof(tBTA_HF_CLIENT_AT_QCMD))) != NULL) {
new_cmd->cmd = cmd;
new_cmd->buf_len = buf_len;
new_cmd->next = NULL;
memcpy(new_cmd->buf, buf, buf_len);
if (bta_hf_client_cb.scb.at_cb.queued_cmd != NULL) {
tBTA_HF_CLIENT_AT_QCMD *qcmd = bta_hf_client_cb.scb.at_cb.queued_cmd;
while (qcmd->next != NULL) {
qcmd = qcmd->next;
}{...}
qcmd->next = new_cmd;
}{...} else {
bta_hf_client_cb.scb.at_cb.queued_cmd = new_cmd;
}{...}
}{...}
}{...}
static void bta_hf_client_at_resp_timer_cback (TIMER_LIST_ENT *p_tle)
{
if (p_tle) {
bta_hf_client_cb.scb.at_cb.resp_timer_on = FALSE;
APPL_TRACE_ERROR("HFPClient: AT response timeout, disconnecting");
bta_hf_client_sm_execute(BTA_HF_CLIENT_API_CLOSE_EVT, NULL);
}{...}
}{...}
static void bta_hf_client_stop_at_resp_timer(void)
{
if (bta_hf_client_cb.scb.at_cb.resp_timer_on) {
bta_hf_client_cb.scb.at_cb.resp_timer_on = FALSE;
bta_sys_stop_timer (&bta_hf_client_cb.scb.at_cb.resp_timer);
}{...}
}{...}
static void bta_hf_client_free_at_resp_timer(void)
{
bta_hf_client_cb.scb.at_cb.resp_timer_on = FALSE;
bta_sys_free_timer (&bta_hf_client_cb.scb.at_cb.resp_timer);
}{...}
static void bta_hf_client_start_at_resp_timer(void)
{
if (bta_hf_client_cb.scb.at_cb.resp_timer_on) {
bta_sys_stop_timer (&bta_hf_client_cb.scb.at_cb.resp_timer);
}{...}
bta_hf_client_cb.scb.at_cb.resp_timer.p_cback = (TIMER_CBACK *)&bta_hf_client_at_resp_timer_cback;
bta_sys_start_timer(&bta_hf_client_cb.scb.at_cb.resp_timer, 0, BTA_HF_CLIENT_AT_TIMEOUT);
bta_hf_client_cb.scb.at_cb.resp_timer_on = TRUE;
}{...}
static void bta_hf_client_send_at(tBTA_HF_CLIENT_AT_CMD cmd, char *buf, UINT16 buf_len)
{
if ((bta_hf_client_cb.scb.at_cb.current_cmd == BTA_HF_CLIENT_AT_NONE ||
bta_hf_client_cb.scb.svc_conn == FALSE) &&
bta_hf_client_cb.scb.at_cb.hold_timer_on == FALSE) {
UINT16 len;
#ifdef BTA_HF_CLIENT_AT_DUMP
APPL_TRACE_DEBUG("%s %.*s", __FUNCTION__, buf_len - 1, buf);
#endif
bta_hf_client_cb.scb.at_cb.current_cmd = cmd;
if (!service_availability &&
(cmd == BTA_HF_CLIENT_AT_CNUM || cmd == BTA_HF_CLIENT_AT_COPS)) {
APPL_TRACE_WARNING("%s: No service, skipping %d command", __FUNCTION__, cmd);
bta_hf_client_handle_ok();
return;
}{...}
PORT_WriteData(bta_hf_client_cb.scb.conn_handle, buf, buf_len, &len);
bta_hf_client_start_at_resp_timer();
return;
}{...}
bta_hf_client_queue_at(cmd, buf, buf_len);
}{...}
static void bta_hf_client_send_queued_at(void)
{
tBTA_HF_CLIENT_AT_QCMD *cur = bta_hf_client_cb.scb.at_cb.queued_cmd;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (cur != NULL) {
bta_hf_client_cb.scb.at_cb.queued_cmd = cur->next;
bta_hf_client_send_at(cur->cmd, cur->buf, cur->buf_len);
osi_free(cur);
}{...}
}{...}
static void bta_hf_client_at_hold_timer_cback(TIMER_LIST_ENT *p_tle)
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (p_tle) {
bta_hf_client_cb.scb.at_cb.hold_timer_on = FALSE;
bta_hf_client_send_queued_at();
}{...}
}{...}
static void bta_hf_client_stop_at_hold_timer(void)
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (bta_hf_client_cb.scb.at_cb.hold_timer_on) {
bta_hf_client_cb.scb.at_cb.hold_timer_on = FALSE;
bta_sys_stop_timer (&bta_hf_client_cb.scb.at_cb.hold_timer);
}{...}
}{...}
static void bta_hf_client_free_at_hold_timer(void)
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
bta_hf_client_cb.scb.at_cb.hold_timer_on = FALSE;
bta_sys_free_timer(&bta_hf_client_cb.scb.at_cb.hold_timer);
}{...}
static void bta_hf_client_start_at_hold_timer(void)
{
TIMER_LIST_ENT *timer = &bta_hf_client_cb.scb.at_cb.hold_timer;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (bta_hf_client_cb.scb.at_cb.hold_timer_on) {
bta_sys_stop_timer (timer);
}{...}
timer->p_cback = (TIMER_CBACK *)&bta_hf_client_at_hold_timer_cback;
bta_sys_start_timer(timer, 0, BTA_HF_CLIENT_AT_HOLD_TIMEOUT);
bta_hf_client_cb.scb.at_cb.hold_timer_on = TRUE;
}{...}
/* ... */
static void bta_hf_client_handle_ok(void)
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
bta_hf_client_stop_at_resp_timer();
if (!bta_hf_client_cb.scb.svc_conn) {
bta_hf_client_slc_seq(FALSE);
return;
}{...}
switch (bta_hf_client_cb.scb.at_cb.current_cmd) {
case BTA_HF_CLIENT_AT_BIA:
case BTA_HF_CLIENT_AT_BCC:
break;...
case BTA_HF_CLIENT_AT_BCS:
bta_hf_client_start_at_hold_timer();
bta_hf_client_cb.scb.at_cb.current_cmd = BTA_HF_CLIENT_AT_NONE;
return;...
case BTA_HF_CLIENT_AT_CLIP:
if (bta_hf_client_cb.scb.send_at_reply == FALSE) {
bta_hf_client_cb.scb.send_at_reply = TRUE;
}{...}
break;...
case BTA_HF_CLIENT_AT_NONE:
bta_hf_client_stop_at_hold_timer();
break;...
default:
if (bta_hf_client_cb.scb.send_at_reply) {
bta_hf_client_at_result(BTA_HF_CLIENT_AT_RESULT_OK, 0);
}{...}
break;...
}{...}
bta_hf_client_cb.scb.at_cb.current_cmd = BTA_HF_CLIENT_AT_NONE;
bta_hf_client_send_queued_at();
}{...}
static void bta_hf_client_handle_error(tBTA_HF_CLIENT_AT_RESULT_TYPE type, UINT16 cme)
{
APPL_TRACE_DEBUG("%s %u %u", __FUNCTION__, type, cme);
bta_hf_client_stop_at_resp_timer();
if (!bta_hf_client_cb.scb.svc_conn) {
bta_hf_client_slc_seq(TRUE);
return;
}{...}
switch (bta_hf_client_cb.scb.at_cb.current_cmd) {
case BTA_HF_CLIENT_AT_BIA:
break;...
case BTA_HF_CLIENT_AT_BCC:
case BTA_HF_CLIENT_AT_BCS:
bta_hf_client_cback_sco(BTA_HF_CLIENT_AUDIO_CLOSE_EVT);
break;...
case BTA_HF_CLIENT_AT_CLIP:
if (bta_hf_client_cb.scb.send_at_reply == FALSE) {
bta_hf_client_cb.scb.send_at_reply = TRUE;
}{...}
break;...
default:
if (bta_hf_client_cb.scb.send_at_reply) {
bta_hf_client_at_result(type, cme);
}{...}
break;...
}{...}
bta_hf_client_cb.scb.at_cb.current_cmd = BTA_HF_CLIENT_AT_NONE;
bta_hf_client_send_queued_at();
}{...}
static void bta_hf_client_handle_ring(void)
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
bta_hf_client_evt_val(BTA_HF_CLIENT_RING_INDICATION, 0);
}{...}
static void bta_hf_client_handle_brsf(UINT32 value)
{
APPL_TRACE_DEBUG("%s 0x%x", __FUNCTION__, value);
bta_hf_client_cb.scb.peer_features = value;
}{...}
static void bta_hf_client_handle_cind_list_item(char *name, UINT32 min, UINT32 max, UINT32 index)
{
UINT8 i = 0;
APPL_TRACE_DEBUG("%s %u.%s <%u:%u>", __FUNCTION__, index, name, min, max);
for (i = 0; i < BTA_HF_CLIENT_AT_SUPPORTED_INDICATOR_COUNT; i++) {
if (strcmp(name, BTA_HF_CLIENT_INDICATOR_SERVICE) == 0) {
service_index = index;
}{...}
if (strncmp(name, bta_hf_client_indicators[i].name, bta_hf_client_indicators[i].namelen) != 0) {
continue;
}{...}
bta_hf_client_cb.scb.at_cb.indicator_lookup[index] = i;
return;
}{...}
}{...}
static void bta_hf_client_handle_cind_value(UINT32 index, UINT32 value)
{
APPL_TRACE_DEBUG("%s index: %u value: %u", __FUNCTION__, index, value);
if (index >= BTA_HF_CLIENT_AT_INDICATOR_COUNT) {
return;
}{...}
if (service_index == index) {
if (value == 0) {
service_availability = FALSE;
}{...} else {
service_availability = TRUE;
}{...}
}{...}
if (bta_hf_client_cb.scb.at_cb.indicator_lookup[index] == -1) {
return;
}{...}
index = bta_hf_client_cb.scb.at_cb.indicator_lookup[index];
if (value > bta_hf_client_indicators[index].max ||
value < bta_hf_client_indicators[index].min) {
return;
}{...}
bta_hf_client_ind(index, value);
}{...}
static void bta_hf_client_handle_chld(UINT32 mask)
{
APPL_TRACE_DEBUG("%s 0x%x", __FUNCTION__, mask);
bta_hf_client_cb.scb.chld_features |= mask;
}{...}
static void bta_hf_client_handle_ciev(UINT32 index, UINT32 value)
{
INT8 realind = -1;
APPL_TRACE_DEBUG("%s index: %u value: %u", __FUNCTION__, index, value);
if (index == 0 || index > BTA_HF_CLIENT_AT_INDICATOR_COUNT) {
APPL_TRACE_WARNING("%s: Invalid index %d", __FUNCTION__, index);
return;
}{...}
if (service_index == index - 1) {
service_availability = value == 0 ? FALSE : TRUE;
}{...}
realind = bta_hf_client_cb.scb.at_cb.indicator_lookup[index - 1];
if (realind >= 0 && realind < BTA_HF_CLIENT_AT_SUPPORTED_INDICATOR_COUNT) {
if (value > bta_hf_client_indicators[realind].max || value < bta_hf_client_indicators[realind].min) {
return;
}{...}
if (service_index == (index - 1)) {
if (value == 1) {
service_availability = TRUE;
}{...} else {
service_availability = FALSE;
}{...}
}{...}
bta_hf_client_ind(realind, value);
}{...}
}{...}
static void bta_hf_client_handle_bcs(UINT32 codec)
{
APPL_TRACE_DEBUG("%s %u", __FUNCTION__, codec);
if (codec == BTM_SCO_CODEC_CVSD ||
(codec == BTM_SCO_CODEC_MSBC && bta_hf_client_cb.msbc_enabled == TRUE)) {
bta_hf_client_cb.scb.negotiated_codec = codec;
bta_hf_client_send_at_bcs(codec);
}{...} else {
bta_hf_client_cb.scb.negotiated_codec = BTM_SCO_CODEC_CVSD;
bta_hf_client_send_at_bac();
}{...}
}{...}
static void bta_hf_client_handle_bsir(UINT32 provided)
{
APPL_TRACE_DEBUG("%s %u", __FUNCTION__, provided);
bta_hf_client_evt_val(BTA_HF_CLIENT_BSIR_EVT, provided);
}{...}
static void bta_hf_client_handle_cmeerror(UINT32 code)
{
bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_CME, code);
}{...}
static void bta_hf_client_handle_vgm(UINT32 value)
{
APPL_TRACE_DEBUG("%s %u", __FUNCTION__, value);
if (value <= BTA_HF_CLIENT_VGM_MAX) {
bta_hf_client_evt_val(BTA_HF_CLIENT_MIC_EVT, value);
}{...}
}{...}
static void bta_hf_client_handle_vgs(UINT32 value)
{
APPL_TRACE_DEBUG("%s %u", __FUNCTION__, value);
if (value <= BTA_HF_CLIENT_VGS_MAX) {
bta_hf_client_evt_val(BTA_HF_CLIENT_SPK_EVT, value);
}{...}
}{...}
static void bta_hf_client_handle_bvra(UINT32 value)
{
APPL_TRACE_DEBUG("%s %u", __FUNCTION__, value);
if (value > 1) {
return;
}{...}
bta_hf_client_evt_val(BTA_HF_CLIENT_VOICE_REC_EVT, value);
}{...}
static void bta_hf_client_handle_clip(char *numstr, UINT32 type)
{
APPL_TRACE_DEBUG("%s %u %s", __FUNCTION__, type, numstr);
bta_hf_client_clip(numstr);
}{...}
static void bta_hf_client_handle_ccwa(char *numstr, UINT32 type)
{
APPL_TRACE_DEBUG("%s %u %s", __FUNCTION__, type, numstr);
bta_hf_client_ccwa(numstr);
}{...}
static void bta_hf_client_handle_cops(char *opstr, UINT32 mode)
{
APPL_TRACE_DEBUG("%s %u %s", __FUNCTION__, mode, opstr);
bta_hf_client_operator_name(opstr);
}{...}
static void bta_hf_client_handle_binp(char *numstr)
{
APPL_TRACE_DEBUG("%s %s", __FUNCTION__, numstr);
bta_hf_client_binp(numstr);
}{...}
static void bta_hf_client_handle_clcc(UINT16 idx, UINT16 dir, UINT16 status, UINT16 mode, UINT16 mpty, char *numstr, UINT16 type)
{
APPL_TRACE_DEBUG("%s idx: %u dir: %u status: %u mode: %u mpty: %u",
__FUNCTION__, idx, dir, status, mode, mpty);
if (numstr) {
APPL_TRACE_DEBUG("%s number: %s type: %u", __FUNCTION__, numstr, type);
}{...}
bta_hf_client_clcc(idx, dir, status, mpty, numstr);
}{...}
static void bta_hf_client_handle_cnum( char *numstr, UINT16 type, UINT16 service)
{
APPL_TRACE_DEBUG("%s number: %s type: %u service: %u", __FUNCTION__, numstr, type, service);
bta_hf_client_cnum(numstr, service);
}{...}
static void bta_hf_client_handle_btrh( UINT16 code)
{
APPL_TRACE_DEBUG("%s %u", __FUNCTION__, code);
bta_hf_client_evt_val(BTA_HF_CLIENT_BTRH_EVT, code);
}{...}
/* ... */
#define AT_CHECK_EVENT(buf, event) \
if (strncmp("\r\n"event,buf,sizeof("\r\n"event) - 1) != 0) \
return buf; \
buf += sizeof("\r\n"event) - 1; \
while (*buf == ' ') buf++;...
#define AT_CHECK_RN(buf) \
if (strncmp("\r\n", buf, sizeof("\r\n") - 1) != 0) { \
APPL_TRACE_ERROR("%s missing end <cr><lf>", __FUNCTION__); \
return NULL;\
}{...} \
buf += sizeof("\r\n") - 1;...
#define AT_SKIP_REST(buf) while(*buf != '\r') buf++;
static char *bta_hf_client_parse_ok(char *buffer)
{
AT_CHECK_EVENT(buffer, "OK");
AT_CHECK_RN(buffer);
bta_hf_client_handle_ok();
return buffer;
}{...}
static char *bta_hf_client_parse_error(char *buffer)
{
AT_CHECK_EVENT(buffer, "ERROR");
AT_CHECK_RN(buffer);
bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_ERROR, 0);
return buffer;
}{...}
static char *bta_hf_client_parse_ring(char *buffer)
{
AT_CHECK_EVENT(buffer, "RING");
AT_CHECK_RN(buffer);
bta_hf_client_handle_ring();
return buffer;
}{...}
static char *bta_hf_client_parse_uint32(char *buffer, void (*handler_callback)(UINT32))
{
UINT32 value;
int res;
int offset;
res = sscanf(buffer, "%u%n", &value, &offset);
if (res < 1) {
return NULL;
}{...}
buffer += offset;
AT_CHECK_RN(buffer);
handler_callback(value);
return buffer;
}{...}
static char *bta_hf_client_parse_brsf(char *buffer)
{
AT_CHECK_EVENT(buffer, "+BRSF:");
return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_brsf);
}{...}
static char *bta_hf_client_parse_cind_values(char *buffer)
{
UINT16 index = 0;
UINT32 value = 0;
int offset;
int res;
while ((res = sscanf(buffer, "%u%n", &value, &offset)) > 0) {
bta_hf_client_handle_cind_value(index, value);
buffer += offset;
if (*buffer != ',') {
break;
}{...}
index++;
buffer++;
}{...}
if (res > 0) {
AT_CHECK_RN(buffer);
return buffer;
}{...}
return NULL;
}{...}
static char *bta_hf_client_parse_cind_list(char *buffer)
{
int offset;
char *name = osi_malloc(129);
UINT32 min, max;
UINT32 index = 0;
int res;
if (name == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return NULL;
}{...}
while ((res = sscanf(buffer, "(\"%128[^\"]\",(%u%*[-,]%u))%n", name, &min, &max, &offset)) > 2) {
bta_hf_client_handle_cind_list_item(name, min, max, index);
buffer += offset;
index++;
if (*buffer != ',') {
break;
}{...}
buffer++;
}{...}
osi_free(name);
if (res > 2) {
AT_CHECK_RN(buffer);
return buffer;
}{...}
return NULL;
}{...}
static char *bta_hf_client_parse_cind(char *buffer)
{
AT_CHECK_EVENT(buffer, "+CIND:");
if (*buffer == '(') {
return bta_hf_client_parse_cind_list(buffer);
}{...}
return bta_hf_client_parse_cind_values(buffer);
}{...}
static char *bta_hf_client_parse_chld(char *buffer)
{
AT_CHECK_EVENT(buffer, "+CHLD:");
if (*buffer != '(') {
return NULL;
}{...}
buffer++;
while (*buffer != '\0') {
if (strncmp("0", buffer, 1) == 0) {
bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_REL);
buffer++;
}{...} else if (strncmp("1x", buffer, 2) == 0) {
bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_REL_X);
buffer += 2;
}{...} else if (strncmp("1", buffer, 1) == 0) {
bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_REL_ACC);
buffer++;
}{...} else if (strncmp("2x", buffer, 2) == 0) {
bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_PRIV_X);
buffer += 2;
}{...} else if (strncmp("2", buffer, 1) == 0) {
bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_HOLD_ACC);
buffer++;
}{...} else if (strncmp("3", buffer, 1) == 0) {
bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_MERGE);
buffer++;
}{...} else if (strncmp("4", buffer, 1) == 0) {
bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_MERGE_DETACH);
buffer++;
}{...} else {
return NULL;
}{...}
if (*buffer == ',') {
buffer++;
continue;
}{...}
if (*buffer == ')') {
buffer++;
break;
}{...}
return NULL;
}{...}
AT_CHECK_RN(buffer);
return buffer;
}{...}
static char *bta_hf_client_parse_ciev(char *buffer)
{
UINT32 index, value;
int res;
int offset;
AT_CHECK_EVENT(buffer, "+CIEV:");
res = sscanf(buffer, "%u,%u%n", &index, &value, &offset);
if (res < 2) {
return NULL;
}{...}
buffer += offset;
AT_CHECK_RN(buffer);
bta_hf_client_handle_ciev(index, value);
return buffer;
}{...}
static char *bta_hf_client_parse_bcs(char *buffer)
{
AT_CHECK_EVENT(buffer, "+BCS:");
return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_bcs);
}{...}
static char *bta_hf_client_parse_bsir(char *buffer)
{
AT_CHECK_EVENT(buffer, "+BSIR:");
return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_bsir);
}{...}
static char *bta_hf_client_parse_cmeerror(char *buffer)
{
AT_CHECK_EVENT(buffer, "+CME ERROR:");
return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_cmeerror);
}{...}
static char *bta_hf_client_parse_vgm(char *buffer)
{
AT_CHECK_EVENT(buffer, "+VGM:");
return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_vgm);
}{...}
static char *bta_hf_client_parse_vgme(char *buffer)
{
AT_CHECK_EVENT(buffer, "+VGM=");
return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_vgm);
}{...}
static char *bta_hf_client_parse_vgs(char *buffer)
{
AT_CHECK_EVENT(buffer, "+VGS:");
return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_vgs);
}{...}
static char *bta_hf_client_parse_vgse(char *buffer)
{
AT_CHECK_EVENT(buffer, "+VGS=");
return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_vgs);
}{...}
static char *bta_hf_client_parse_bvra(char *buffer)
{
AT_CHECK_EVENT(buffer, "+BVRA:");
return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_bvra);
}{...}
static char *bta_hf_client_parse_clip(char *buffer)
{
char number[33];
UINT32 type = 0;
int res;
int offset;
AT_CHECK_EVENT(buffer, "+CLIP:");
res = sscanf(buffer, "\"%32[^\"]\",%u%n", number, &type, &offset);
if (res < 2) {
return NULL;
}{...}
buffer += offset;
AT_SKIP_REST(buffer);
AT_CHECK_RN(buffer);
bta_hf_client_handle_clip(number, type);
return buffer;
}{...}
static char *bta_hf_client_parse_ccwa(char *buffer)
{
char number[33];
UINT32 type = 0;
int res ;
int offset;
AT_CHECK_EVENT(buffer, "+CCWA:");
res = sscanf(buffer, "\"%32[^\"]\",%u%n", number, &type, &offset);
if (res < 2) {
return NULL;
}{...}
buffer += offset;
AT_SKIP_REST(buffer);
AT_CHECK_RN(buffer);
bta_hf_client_handle_ccwa(number, type);
return buffer;
}{...}
static char *bta_hf_client_parse_cops(char *buffer)
{
UINT8 mode;
char opstr[17];
int res;
int offset;
AT_CHECK_EVENT(buffer, "+COPS:");
res = sscanf(buffer, "%hhi,0,\"%16[^\"]\"%n", &mode, opstr, &offset);
if (res < 2) {
return NULL;
}{...}
buffer += offset;
AT_SKIP_REST(buffer);
AT_CHECK_RN(buffer);
bta_hf_client_handle_cops(opstr, mode);
return buffer;
}{...}
static char *bta_hf_client_parse_binp(char *buffer)
{
char numstr[33];
int res;
int offset;
AT_CHECK_EVENT(buffer, "+BINP:");
res = sscanf(buffer, "\"%32[^\"]\"\r\n%n", numstr, &offset);
if (res < 1) {
return NULL;
}{...}
buffer += offset;
AT_SKIP_REST(buffer);
AT_CHECK_RN(buffer);
bta_hf_client_handle_binp(numstr);
return buffer;
}{...}
static char *bta_hf_client_parse_clcc(char *buffer)
{
UINT16 idx, dir, status, mode, mpty;
char numstr[33];
UINT16 type;
int res;
int offset;
AT_CHECK_EVENT(buffer, "+CLCC:");
res = sscanf(buffer, "%hu,%hu,%hu,%hu,%hu%n",
&idx, &dir, &status, &mode, &mpty, &offset);
if (res < 5) {
return NULL;
}{...}
if (offset == 0) {
APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
return NULL;
}{...}
buffer += offset;
offset = 0;
if (*buffer == ',') {
int res2 = sscanf(buffer, ",\"%32[^\"]\",%hu%n", numstr, &type, &offset);
if (res2 < 0) {
return NULL;
}{...}
if (res2 == 0) {
res2 = sscanf(buffer, ",\"\",%hu%n", &type, &offset);
if (res2 < 0) {
return NULL;
}{...}
res2++;
numstr[0] = '\0';
}{...}
if (res2 >= 2) {
res += res2;
if (offset == 0) {
APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
return NULL;
}{...}
buffer += offset;
}{...}
}{...}
AT_SKIP_REST(buffer);
AT_CHECK_RN(buffer);
if (res > 6) {
bta_hf_client_handle_clcc(idx, dir, status, mode, mpty, numstr, type);
}{...} else {
bta_hf_client_handle_clcc(idx, dir, status, mode, mpty, NULL, 0);
}{...}
return buffer;
}{...}
static char *bta_hf_client_parse_cnum(char *buffer)
{
char numstr[33];
UINT16 type;
UINT16 service = 0;
int res;
int offset;
AT_CHECK_EVENT(buffer, "+CNUM:");
res = sscanf(buffer, ",\"%32[^\"]\",%hu%n,,%hu%n", numstr, &type, &offset, &service, &offset);
if (res < 0) {
return NULL;
}{...}
if (res == 0) {
res = sscanf(buffer, ",\"\",%hu%n,,%hu%n", &type, &offset, &service, &offset);
if (res < 0) {
return NULL;
}{...}
res++;
numstr[0] = '\0';
}{...}
if (res < 2) {
return NULL;
}{...}
buffer += offset;
AT_CHECK_RN(buffer);
if (res == 2) {
bta_hf_client_handle_cnum(numstr, type, service);
return buffer;
}{...}
if (service != 4 && service != 5) {
return NULL;
}{...}
bta_hf_client_handle_cnum(numstr, type, service);
return buffer;
}{...}
static char *bta_hf_client_parse_btrh(char *buffer)
{
UINT16 code = 0;
int res;
int offset;
AT_CHECK_EVENT(buffer, "+BTRH:");
res = sscanf(buffer, "%hu%n", &code, &offset);
if (res < 1) {
return NULL;
}{...}
buffer += offset;
AT_CHECK_RN(buffer);
bta_hf_client_handle_btrh(code);
return buffer;
}{...}
static char *bta_hf_client_parse_busy(char *buffer)
{
AT_CHECK_EVENT(buffer, "BUSY");
AT_CHECK_RN(buffer);
bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_BUSY, 0);
return buffer;
}{...}
static char *bta_hf_client_parse_delayed(char *buffer)
{
AT_CHECK_EVENT(buffer, "DELAYED");
AT_CHECK_RN(buffer);
bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_DELAY, 0);
return buffer;
}{...}
static char *bta_hf_client_parse_no_carrier(char *buffer)
{
AT_CHECK_EVENT(buffer, "NO CARRIER");
AT_CHECK_RN(buffer);
bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_NO_CARRIER, 0);
return buffer;
}{...}
static char *bta_hf_client_parse_no_answer(char *buffer)
{
AT_CHECK_EVENT(buffer, "NO ANSWER");
AT_CHECK_RN(buffer);
bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_NO_ANSWER, 0);
return buffer;
}{...}
static char *bta_hf_client_parse_blacklisted(char *buffer)
{
AT_CHECK_EVENT(buffer, "BLACKLISTED");
AT_CHECK_RN(buffer);
bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_BLACKLISTED, 0);
return buffer;
}{...}
static char *bta_hf_client_skip_unknown(char *buffer)
{
char *start;
char *tmp;
tmp = strstr(buffer, "\r\n");
if (tmp == NULL) {
return NULL;
}{...}
buffer += 2;
start = buffer;
tmp = strstr(buffer, "\r\n");
if (tmp == NULL) {
return NULL;
}{...}
buffer = tmp + 2;
APPL_TRACE_DEBUG("%s %.*s", __FUNCTION__, buffer - start - 2, start);
UNUSED(start);
return buffer;
}{...}
/* ... */
/* ... */
typedef char *(*tBTA_HF_CLIENT_PARSER_CALLBACK)(char *);
static const tBTA_HF_CLIENT_PARSER_CALLBACK bta_hf_client_parser_cb[] = {
bta_hf_client_parse_ok,
bta_hf_client_parse_error,
bta_hf_client_parse_ring,
bta_hf_client_parse_brsf,
bta_hf_client_parse_cind,
bta_hf_client_parse_ciev,
bta_hf_client_parse_chld,
bta_hf_client_parse_bcs,
bta_hf_client_parse_bsir,
bta_hf_client_parse_cmeerror,
bta_hf_client_parse_vgm,
bta_hf_client_parse_vgme,
bta_hf_client_parse_vgs,
bta_hf_client_parse_vgse,
bta_hf_client_parse_bvra,
bta_hf_client_parse_clip,
bta_hf_client_parse_ccwa,
bta_hf_client_parse_cops,
bta_hf_client_parse_binp,
bta_hf_client_parse_clcc,
bta_hf_client_parse_cnum,
bta_hf_client_parse_btrh,
bta_hf_client_parse_busy,
bta_hf_client_parse_delayed,
bta_hf_client_parse_no_carrier,
bta_hf_client_parse_no_answer,
bta_hf_client_parse_blacklisted,
bta_hf_client_skip_unknown
}{...};
static const UINT16 bta_hf_client_psraser_cb_count =
sizeof(bta_hf_client_parser_cb) / sizeof(bta_hf_client_parser_cb[0]);
#ifdef BTA_HF_CLIENT_AT_DUMP
static void bta_hf_client_dump_at(void)
{
char dump[(4 * BTA_HF_CLIENT_AT_PARSER_MAX_LEN) + 1];
char *p1, *p2;
p1 = bta_hf_client_cb.scb.at_cb.buf;
p2 = dump;
while (*p1 != '\0') {
if (*p1 == '\r') {
strlcpy(p2, "<cr>", 4);
p2 += 4;
}{...} else if (*p1 == '\n') {
strlcpy(p2, "<lf>", 4);
p2 += 4;
}{...} else {
*p2 = *p1;
p2++;
}{...}
p1++;
}{...}
*p2 = '\0';
APPL_TRACE_DEBUG("%s %s", __FUNCTION__, dump);
}{...}
/* ... */#endif
static void bta_hf_client_at_parse_start(void)
{
char *buf = bta_hf_client_cb.scb.at_cb.buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
#ifdef BTA_HF_CLIENT_AT_DUMP
bta_hf_client_dump_at();
#endif
while (*buf != '\0') {
int i;
char *tmp = NULL;
for (i = 0; i < bta_hf_client_psraser_cb_count; i++) {
tmp = bta_hf_client_parser_cb[i](buf);
if (tmp == NULL) {
APPL_TRACE_ERROR("HFPCient: AT event/reply parsing failed, skipping %d", i);
tmp = bta_hf_client_skip_unknown(buf);
break;
}{...}
/* ... */
if (tmp != buf) {
buf = tmp;
break;
}{...}
}{...}
if (tmp == NULL) {
APPL_TRACE_ERROR("HFPCient: could not skip unknown AT event, disconnecting");
bta_hf_client_at_reset();
bta_hf_client_sm_execute(BTA_HF_CLIENT_API_CLOSE_EVT, NULL);
return;
}{...}
buf = tmp;
}{...}
}{...}
static BOOLEAN bta_hf_client_check_at_complete(void)
{
BOOLEAN ret = FALSE;
tBTA_HF_CLIENT_AT_CB *at_cb = &bta_hf_client_cb.scb.at_cb;
if (at_cb->offset >= BTA_HF_CLIENT_AT_EVENT_MIN_LEN) {
if (at_cb->buf[at_cb->offset - 2] == '\r' && at_cb->buf[at_cb->offset - 1] == '\n') {
ret = TRUE;
}{...}
}{...}
APPL_TRACE_DEBUG("%s %d", __FUNCTION__, ret);
return ret;
}{...}
static void bta_hf_client_at_clear_buf(void)
{
memset(bta_hf_client_cb.scb.at_cb.buf, 0, sizeof(bta_hf_client_cb.scb.at_cb.buf));
bta_hf_client_cb.scb.at_cb.offset = 0;
}{...}
/* ... */
void bta_hf_client_at_parse(char *buf, unsigned int len)
{
APPL_TRACE_DEBUG("%s offset: %u len: %u", __FUNCTION__, bta_hf_client_cb.scb.at_cb.offset, len);
if (len + bta_hf_client_cb.scb.at_cb.offset > BTA_HF_CLIENT_AT_PARSER_MAX_LEN) {
unsigned int tmp = bta_hf_client_cb.scb.at_cb.offset;
unsigned int space_left = BTA_HF_CLIENT_AT_PARSER_MAX_LEN - bta_hf_client_cb.scb.at_cb.offset;
char *tmp_buff = osi_malloc(BTA_HF_CLIENT_AT_PARSER_MAX_LEN);
if (tmp_buff == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
APPL_TRACE_DEBUG("%s overrun, trying to recover", __FUNCTION__);
memcpy(bta_hf_client_cb.scb.at_cb.buf + bta_hf_client_cb.scb.at_cb.offset, buf, space_left);
len -= space_left;
buf += space_left;
bta_hf_client_cb.scb.at_cb.offset += space_left;
while (bta_hf_client_check_at_complete() == FALSE) {
if (bta_hf_client_cb.scb.at_cb.offset == 0) {
APPL_TRACE_ERROR("HFPClient: AT parser buffer overrun, disconnecting");
bta_hf_client_at_reset();
bta_hf_client_sm_execute(BTA_HF_CLIENT_API_CLOSE_EVT, NULL);
osi_free(tmp_buff);
return;
}{...}
bta_hf_client_cb.scb.at_cb.offset--;
}{...}
tmp += space_left - bta_hf_client_cb.scb.at_cb.offset;
memcpy(tmp_buff, bta_hf_client_cb.scb.at_cb.buf + bta_hf_client_cb.scb.at_cb.offset, tmp);
bta_hf_client_cb.scb.at_cb.buf[bta_hf_client_cb.scb.at_cb.offset] = '\0';
bta_hf_client_at_parse_start();
bta_hf_client_at_clear_buf();
memcpy(bta_hf_client_cb.scb.at_cb.buf, tmp_buff, tmp);
bta_hf_client_cb.scb.at_cb.offset += tmp;
osi_free(tmp_buff);
}{...}
memcpy(bta_hf_client_cb.scb.at_cb.buf + bta_hf_client_cb.scb.at_cb.offset, buf, len);
bta_hf_client_cb.scb.at_cb.offset += len;
if (bta_hf_client_check_at_complete() == TRUE) {
bta_hf_client_at_parse_start();
bta_hf_client_at_clear_buf();
}{...}
}{...}
void bta_hf_client_send_at_brsf(void)
{
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
int at_len;
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
APPL_TRACE_DEBUG("%s", __FUNCTION__);
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+BRSF=%u\r", bta_hf_client_cb.scb.features);
bta_hf_client_send_at(BTA_HF_CLIENT_AT_BRSF , buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_send_at_bac(void)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (bta_hf_client_cb.msbc_enabled) {
buf = "AT+BAC=1,2\r";
}{...} else {
buf = "AT+BAC=1\r";
}{...}
bta_hf_client_send_at(BTA_HF_CLIENT_AT_BAC, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_bcs(UINT32 codec)
{
char * buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
int at_len;
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+BCS=%u\r", codec);
bta_hf_client_send_at(BTA_HF_CLIENT_AT_BCS, buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_send_at_cind(BOOLEAN status)
{
char *buf;
tBTA_HF_CLIENT_AT_CMD cmd;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (status) {
buf = "AT+CIND?\r";
cmd = BTA_HF_CLIENT_AT_CIND_STATUS;
}{...} else {
buf = "AT+CIND=?\r";
cmd = BTA_HF_CLIENT_AT_CIND;
}{...}
bta_hf_client_send_at(cmd, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_cmer(BOOLEAN activate)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (activate) {
buf = "AT+CMER=3,0,0,1\r";
}{...} else {
buf = "AT+CMER=3,0,0,0\r";
}{...}
bta_hf_client_send_at(BTA_HF_CLIENT_AT_CMER, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_chld(char cmd, UINT32 idx)
{
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
int at_len;
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
if (idx > 0) {
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+CHLD=%c%u\r", cmd, idx);
}{...} else {
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+CHLD=%c\r", cmd);
}{...}
bta_hf_client_send_at(BTA_HF_CLIENT_AT_CHLD, buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_send_at_clip(BOOLEAN activate)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (activate) {
buf = "AT+CLIP=1\r";
}{...} else {
buf = "AT+CLIP=0\r";
}{...}
bta_hf_client_send_at(BTA_HF_CLIENT_AT_CLIP, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_ccwa(BOOLEAN activate)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (activate) {
buf = "AT+CCWA=1\r";
}{...} else {
buf = "AT+CCWA=0\r";
}{...}
bta_hf_client_send_at(BTA_HF_CLIENT_AT_CCWA, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_cmee(BOOLEAN activate)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (activate) {
buf = "AT+CMEE=1\r";
}{...} else {
buf = "AT+CMEE=0\r";
}{...}
bta_hf_client_send_at(BTA_HF_CLIENT_AT_CMEE, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_cops(BOOLEAN query)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (query) {
buf = "AT+COPS?\r";
}{...} else {
buf = "AT+COPS=3,0\r";
}{...}
bta_hf_client_send_at(BTA_HF_CLIENT_AT_COPS, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_clcc(void)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
buf = "AT+CLCC\r";
bta_hf_client_send_at(BTA_HF_CLIENT_AT_CLCC, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_xapl(char *information, UINT32 features)
{
APPL_TRACE_DEBUG("%s(%s, %u)", __FUNCTION__, information, features);
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
/* ... */
snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+XAPL=%s,%u\r", information, features);
bta_hf_client_send_at(BTA_HF_CLIENT_AT_XAPL, buf, strlen(buf));
osi_free(buf);
}{...}
void bta_hf_client_send_at_iphoneaccev(UINT32 bat_level, BOOLEAN docked)
{
APPL_TRACE_DEBUG("%s(%u, %s)", __FUNCTION__, bat_level, docked ? "docked" : "undocked");
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
/* ... */
snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+IPHONEACCEV=2,1,%u,2,%u\r", bat_level, docked ? 1 : 0);
bta_hf_client_send_at(BTA_HF_CLIENT_AT_IPHONEACCEV, buf, strlen(buf));
osi_free(buf);
}{...}
void bta_hf_client_send_at_bvra(BOOLEAN enable)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (enable) {
buf = "AT+BVRA=1\r";
}{...} else {
buf = "AT+BVRA=0\r";
}{...}
bta_hf_client_send_at(BTA_HF_CLIENT_AT_BVRA, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_vgs(UINT32 volume)
{
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
int at_len;
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
APPL_TRACE_DEBUG("%s", __FUNCTION__);
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+VGS=%u\r", volume);
bta_hf_client_send_at(BTA_HF_CLIENT_AT_VGS, buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_send_at_vgm(UINT32 volume)
{
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
int at_len;
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
APPL_TRACE_DEBUG("%s", __FUNCTION__);
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+VGM=%u\r", volume);
bta_hf_client_send_at(BTA_HF_CLIENT_AT_VGM, buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_send_at_atd(char *number, UINT32 memory)
{
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
int at_len;
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (number[0] != '\0') {
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "ATD%s;\r", number);
}{...} else {
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "ATD>%u;\r", memory);
}{...}
at_len = MIN(at_len, BTA_HF_CLIENT_AT_MAX_LEN);
bta_hf_client_send_at(BTA_HF_CLIENT_AT_ATD, buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_send_at_bldn(void)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
buf = "AT+BLDN\r";
bta_hf_client_send_at(BTA_HF_CLIENT_AT_BLDN, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_ata(void)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
buf = "ATA\r";
bta_hf_client_send_at(BTA_HF_CLIENT_AT_ATA, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_chup(void)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
buf = "AT+CHUP\r";
bta_hf_client_send_at(BTA_HF_CLIENT_AT_CHUP, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_btrh(BOOLEAN query, UINT32 val)
{
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
int at_len;
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (query == TRUE) {
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+BTRH?\r");
}{...} else {
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+BTRH=%u\r", val);
}{...}
bta_hf_client_send_at(BTA_HF_CLIENT_AT_BTRH, buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_send_at_vts(char code)
{
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
int at_len;
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
APPL_TRACE_DEBUG("%s", __FUNCTION__);
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+VTS=%c\r", code);
bta_hf_client_send_at(BTA_HF_CLIENT_AT_VTS, buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_send_at_bcc(void)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
buf = "AT+BCC\r";
bta_hf_client_send_at(BTA_HF_CLIENT_AT_BCC, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_cnum(void)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
buf = "AT+CNUM\r";
bta_hf_client_send_at(BTA_HF_CLIENT_AT_CNUM, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_nrec(void)
{
char *buf;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (!(bta_hf_client_cb.scb.peer_features & BTA_HF_CLIENT_PEER_FEAT_ECNR)) {
APPL_TRACE_ERROR("%s: Remote does not support NREC.", __FUNCTION__);
return;
}{...}
buf = "AT+NREC=0\r";
bta_hf_client_send_at(BTA_HF_CLIENT_AT_NREC, buf, strlen(buf));
}{...}
void bta_hf_client_send_at_binp(UINT32 action)
{
char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
int at_len;
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+BINP=%u\r", action);
bta_hf_client_send_at(BTA_HF_CLIENT_AT_BINP, buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_send_at_bia(void)
{
char *buf;
int at_len;
int i;
APPL_TRACE_DEBUG("%s", __FUNCTION__);
if (bta_hf_client_cb.scb.peer_version < HFP_VERSION_1_6) {
APPL_TRACE_DEBUG("Remote does not Support AT+BIA");
return;
}{...}
buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN);
if (buf == NULL) {
APPL_TRACE_ERROR("No mem %s", __FUNCTION__);
return;
}{...}
at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+BIA=");
for (i = 0; i < BTA_HF_CLIENT_AT_INDICATOR_COUNT; i++) {
int sup = bta_hf_client_cb.scb.at_cb.indicator_lookup[i] == -1 ? 0 : 1;
at_len += snprintf(buf + at_len, BTA_HF_CLIENT_AT_MAX_LEN - at_len, "%u,", sup);
}{...}
buf[at_len - 1] = '\r';
bta_hf_client_send_at(BTA_HF_CLIENT_AT_BIA, buf, at_len);
osi_free(buf);
}{...}
void bta_hf_client_at_init(void)
{
memset(&bta_hf_client_cb.scb.at_cb, 0, sizeof(tBTA_HF_CLIENT_AT_CB));
bta_hf_client_at_reset();
}{...}
void bta_hf_client_at_reset(void)
{
int i;
bta_hf_client_free_at_resp_timer();
bta_hf_client_free_at_hold_timer();
bta_hf_client_clear_queued_at();
bta_hf_client_at_clear_buf();
for (i = 0; i < BTA_HF_CLIENT_AT_INDICATOR_COUNT; i++) {
bta_hf_client_cb.scb.at_cb.indicator_lookup[i] = -1;
}{...}
bta_hf_client_cb.scb.at_cb.current_cmd = BTA_HF_CLIENT_AT_NONE;
}{...}
/* ... */#endif