1 /******************************************************************************
3 * Copyright (c) 2014 The Android Open Source Project
4 * Copyright (C) 2003-2012 Broadcom Corporation
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 ******************************************************************************/
20 #define LOG_TAG "bt_hf_client"
26 #include "osi/include/osi.h"
27 #include "bta_hf_client_api.h"
28 #include "bta_hf_client_int.h"
29 #include "osi/include/log.h"
32 /* Uncomment to enable AT traffic dumping */
33 /* #define BTA_HF_CLIENT_AT_DUMP 1 */
35 /* minimum length of AT event */
36 #define BTA_HF_CLIENT_AT_EVENT_MIN_LEN 3
38 /* timeout (in milliseconds) for AT response */
39 #define BTA_HF_CLIENT_AT_TIMEOUT 29989
41 /* timeout (in milliseconds) for AT hold timer */
42 #define BTA_HF_CLIENT_AT_HOLD_TIMEOUT 41
44 /******************************************************************************
46 ** DATA TYPES AND CONTAINERS
48 *******************************************************************************/
49 /* BRSF: store received values here */
50 extern tBTA_HF_CLIENT_CB bta_hf_client_cb;
52 extern fixed_queue_t *btu_bta_alarm_queue;
54 /******************************************************************************
55 ** SUPPORTED EVENT MESSAGES
56 *******************************************************************************/
58 /* CIND: supported indicator names */
59 #define BTA_HF_CLIENT_INDICATOR_BATTERYCHG "battchg"
60 #define BTA_HF_CLIENT_INDICATOR_SIGNAL "signal"
61 #define BTA_HF_CLIENT_INDICATOR_SERVICE "service"
62 #define BTA_HF_CLIENT_INDICATOR_CALL "call"
63 #define BTA_HF_CLIENT_INDICATOR_ROAM "roam"
64 #define BTA_HF_CLIENT_INDICATOR_CALLSETUP "callsetup"
65 #define BTA_HF_CLIENT_INDICATOR_CALLHELD "callheld"
68 ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); (_a < _b) ? _a : _b; })
70 /* CIND: represents each indicators boundaries */
77 } tBTA_HF_CLIENT_INDICATOR;
79 #define BTA_HF_CLIENT_AT_SUPPORTED_INDICATOR_COUNT 7
81 /* CIND: storage room for indicators value range and their statuses */
82 static const tBTA_HF_CLIENT_INDICATOR bta_hf_client_indicators[BTA_HF_CLIENT_AT_SUPPORTED_INDICATOR_COUNT] =
84 /* name | min | max | name length - used by parser */
85 {BTA_HF_CLIENT_INDICATOR_BATTERYCHG, 0, 5, sizeof(BTA_HF_CLIENT_INDICATOR_BATTERYCHG)},
86 {BTA_HF_CLIENT_INDICATOR_SIGNAL, 0, 5, sizeof(BTA_HF_CLIENT_INDICATOR_SIGNAL)},
87 {BTA_HF_CLIENT_INDICATOR_SERVICE, 0, 1, sizeof(BTA_HF_CLIENT_INDICATOR_SERVICE)},
88 {BTA_HF_CLIENT_INDICATOR_CALL, 0, 1, sizeof(BTA_HF_CLIENT_INDICATOR_CALL)},
89 {BTA_HF_CLIENT_INDICATOR_ROAM, 0, 1, sizeof(BTA_HF_CLIENT_INDICATOR_ROAM)},
90 {BTA_HF_CLIENT_INDICATOR_CALLSETUP, 0, 3, sizeof(BTA_HF_CLIENT_INDICATOR_CALLSETUP)},
91 {BTA_HF_CLIENT_INDICATOR_CALLHELD, 0, 2, sizeof(BTA_HF_CLIENT_INDICATOR_CALLHELD)}
94 /* +VGM/+VGS - gain min/max values */
95 #define BTA_HF_CLIENT_VGS_MIN 0
96 #define BTA_HF_CLIENT_VGS_MAX 15
97 #define BTA_HF_CLIENT_VGM_MIN 0
98 #define BTA_HF_CLIENT_VGM_MAX 15
100 UINT32 service_index = 0;
101 BOOLEAN service_availability = TRUE;
102 /* helper functions for handling AT commands queueing */
104 static void bta_hf_client_handle_ok();
106 static void bta_hf_client_clear_queued_at(void)
108 tBTA_HF_CLIENT_AT_QCMD *cur = bta_hf_client_cb.scb.at_cb.queued_cmd;
109 tBTA_HF_CLIENT_AT_QCMD *next;
111 while (cur != NULL) {
117 bta_hf_client_cb.scb.at_cb.queued_cmd = NULL;
120 static void bta_hf_client_queue_at(tBTA_HF_CLIENT_AT_CMD cmd, const char *buf, UINT16 buf_len)
122 tBTA_HF_CLIENT_AT_QCMD *new_cmd =
123 (tBTA_HF_CLIENT_AT_QCMD *)osi_malloc(sizeof(tBTA_HF_CLIENT_AT_QCMD));
125 APPL_TRACE_DEBUG("%s", __func__);
128 new_cmd->buf_len = buf_len;
129 new_cmd->next = NULL;
130 memcpy(new_cmd->buf, buf, buf_len);
132 if (bta_hf_client_cb.scb.at_cb.queued_cmd != NULL) {
133 tBTA_HF_CLIENT_AT_QCMD *qcmd = bta_hf_client_cb.scb.at_cb.queued_cmd;
135 while (qcmd->next != NULL)
138 qcmd->next = new_cmd;
140 bta_hf_client_cb.scb.at_cb.queued_cmd = new_cmd;
144 static void bta_hf_client_at_resp_timer_cback(UNUSED_ATTR void *data)
146 if (bta_hf_client_cb.scb.at_cb.current_cmd == BTA_HF_CLIENT_AT_CNUM) {
147 LOG_INFO(LOG_TAG, "%s timed out waiting for AT+CNUM response; spoofing OK.", __func__);
148 bta_hf_client_handle_ok();
150 APPL_TRACE_ERROR("HFPClient: AT response timeout, disconnecting");
151 bta_hf_client_sm_execute(BTA_HF_CLIENT_API_CLOSE_EVT, NULL);
155 static void bta_hf_client_start_at_resp_timer(void)
157 alarm_set_on_queue(bta_hf_client_cb.scb.at_cb.resp_timer,
158 BTA_HF_CLIENT_AT_TIMEOUT,
159 bta_hf_client_at_resp_timer_cback,
161 btu_bta_alarm_queue);
164 static void bta_hf_client_stop_at_resp_timer(void)
166 alarm_cancel(bta_hf_client_cb.scb.at_cb.resp_timer);
169 static void bta_hf_client_send_at(tBTA_HF_CLIENT_AT_CMD cmd, char *buf, UINT16 buf_len)
171 if ((bta_hf_client_cb.scb.at_cb.current_cmd == BTA_HF_CLIENT_AT_NONE ||
172 bta_hf_client_cb.scb.svc_conn == FALSE) &&
173 !alarm_is_scheduled(bta_hf_client_cb.scb.at_cb.hold_timer))
177 #ifdef BTA_HF_CLIENT_AT_DUMP
178 APPL_TRACE_DEBUG("%s %.*s", __FUNCTION__, buf_len - 1, buf);
181 bta_hf_client_cb.scb.at_cb.current_cmd = cmd;
182 /* Generate fake responses for these because they won't reliably work */
183 if (!service_availability &&
184 (cmd == BTA_HF_CLIENT_AT_CNUM || cmd == BTA_HF_CLIENT_AT_COPS))
186 APPL_TRACE_WARNING("%s: No service, skipping %d command", __FUNCTION__, cmd);
187 bta_hf_client_handle_ok();
191 PORT_WriteData(bta_hf_client_cb.scb.conn_handle, buf, buf_len, &len);
193 bta_hf_client_start_at_resp_timer();
198 bta_hf_client_queue_at(cmd, buf, buf_len);
201 static void bta_hf_client_send_queued_at(void)
203 tBTA_HF_CLIENT_AT_QCMD *cur = bta_hf_client_cb.scb.at_cb.queued_cmd;
205 APPL_TRACE_DEBUG("%s", __FUNCTION__);
209 bta_hf_client_cb.scb.at_cb.queued_cmd = cur->next;
211 bta_hf_client_send_at(cur->cmd, cur->buf, cur->buf_len);
217 static void bta_hf_client_at_hold_timer_cback(UNUSED_ATTR void *data)
219 APPL_TRACE_DEBUG("%s", __FUNCTION__);
220 bta_hf_client_send_queued_at();
223 static void bta_hf_client_stop_at_hold_timer(void)
225 APPL_TRACE_DEBUG("%s", __FUNCTION__);
226 alarm_cancel(bta_hf_client_cb.scb.at_cb.hold_timer);
229 static void bta_hf_client_start_at_hold_timer(void)
231 APPL_TRACE_DEBUG("%s", __FUNCTION__);
232 alarm_set_on_queue(bta_hf_client_cb.scb.at_cb.hold_timer,
233 BTA_HF_CLIENT_AT_HOLD_TIMEOUT,
234 bta_hf_client_at_hold_timer_cback,
236 btu_bta_alarm_queue);
239 /******************************************************************************
241 ** COMMON AT EVENT HANDLING FUNCTIONS
243 ** Receives data (strings, ints, etc.) from the parser and processes this data.
244 ** No buffer parsing is being done here.
245 *******************************************************************************/
247 static void bta_hf_client_handle_ok()
249 APPL_TRACE_DEBUG("%s", __FUNCTION__);
251 bta_hf_client_stop_at_resp_timer();
253 if (!bta_hf_client_cb.scb.svc_conn)
255 bta_hf_client_slc_seq(FALSE);
259 switch(bta_hf_client_cb.scb.at_cb.current_cmd)
261 case BTA_HF_CLIENT_AT_BIA:
262 case BTA_HF_CLIENT_AT_BCC:
264 case BTA_HF_CLIENT_AT_BCS:
265 bta_hf_client_start_at_hold_timer();
266 bta_hf_client_cb.scb.at_cb.current_cmd = BTA_HF_CLIENT_AT_NONE;
268 case BTA_HF_CLIENT_AT_CLIP: //last cmd is post slc seq
269 if (bta_hf_client_cb.scb.send_at_reply == FALSE)
271 bta_hf_client_cb.scb.send_at_reply = TRUE;
274 case BTA_HF_CLIENT_AT_NONE:
275 bta_hf_client_stop_at_hold_timer();
278 if (bta_hf_client_cb.scb.send_at_reply)
280 bta_hf_client_at_result(BTA_HF_CLIENT_AT_RESULT_OK, 0);
285 bta_hf_client_cb.scb.at_cb.current_cmd = BTA_HF_CLIENT_AT_NONE;
287 bta_hf_client_send_queued_at();
290 static void bta_hf_client_handle_error(tBTA_HF_CLIENT_AT_RESULT_TYPE type, UINT16 cme)
292 APPL_TRACE_DEBUG("%s %u %u", __FUNCTION__, type, cme);
294 bta_hf_client_stop_at_resp_timer();
296 if (!bta_hf_client_cb.scb.svc_conn)
298 bta_hf_client_slc_seq(TRUE);
302 switch(bta_hf_client_cb.scb.at_cb.current_cmd)
304 case BTA_HF_CLIENT_AT_BIA:
306 case BTA_HF_CLIENT_AT_BCC:
307 case BTA_HF_CLIENT_AT_BCS:
308 bta_hf_client_cback_sco(BTA_HF_CLIENT_AUDIO_CLOSE_EVT);
310 case BTA_HF_CLIENT_AT_CLIP: //last cmd is post slc seq
311 if (bta_hf_client_cb.scb.send_at_reply == FALSE)
313 bta_hf_client_cb.scb.send_at_reply = TRUE;
317 if (bta_hf_client_cb.scb.send_at_reply)
319 bta_hf_client_at_result(type, cme);
324 bta_hf_client_cb.scb.at_cb.current_cmd = BTA_HF_CLIENT_AT_NONE;
326 bta_hf_client_send_queued_at();
329 static void bta_hf_client_handle_ring()
331 APPL_TRACE_DEBUG("%s", __FUNCTION__);
332 bta_hf_client_evt_val(BTA_HF_CLIENT_RING_INDICATION,0);
335 static void bta_hf_client_handle_brsf(UINT32 value)
337 APPL_TRACE_DEBUG("%s 0x%x", __FUNCTION__, value);
338 bta_hf_client_cb.scb.peer_features = value;
341 /* handles a single indicator descriptor - registers it for value changing events */
342 static void bta_hf_client_handle_cind_list_item(char *name, UINT32 min, UINT32 max, UINT32 index)
347 APPL_TRACE_DEBUG("%s %lu.%s <%lu:%lu>", __FUNCTION__, index, name, min, max);
349 /* look for a matching indicator on list of supported ones */
350 for(i = 0; i < BTA_HF_CLIENT_AT_SUPPORTED_INDICATOR_COUNT; i++)
352 if (strcmp(name,BTA_HF_CLIENT_INDICATOR_SERVICE) == 0)
354 service_index = index;
356 /* look for a match - search one sign further than indicators name to check for string end */
357 /* It will distinguish 'callheld' which could be matched by strncmp as 'call'. */
358 if (strncmp(name, bta_hf_client_indicators[i].name, bta_hf_client_indicators[i].namelen) != 0)
361 /* index - enumerates value position in the incoming sequence */
362 /* if name matches one of the known indicators, add its incoming position */
363 /* to lookup table for easy value->indicator matching later, when only values come */
364 bta_hf_client_cb.scb.at_cb.indicator_lookup[index] = i;
370 static void bta_hf_client_handle_cind_value(UINT32 index, UINT32 value)
372 APPL_TRACE_DEBUG("%s index: %u value: %u", __FUNCTION__, index, value);
374 if (index >= BTA_HF_CLIENT_AT_INDICATOR_COUNT)
379 if (service_index == index)
383 service_availability = FALSE;
387 service_availability = TRUE;
390 if (bta_hf_client_cb.scb.at_cb.indicator_lookup[index] == -1)
395 /* get the real array index from lookup table */
396 index = bta_hf_client_cb.scb.at_cb.indicator_lookup[index];
398 /* Ignore out of range values */
399 if(value > bta_hf_client_indicators[index].max ||
400 value < bta_hf_client_indicators[index].min)
405 /* tBTA_HF_CLIENT_IND_TYPE match index in bta_hf_client_indicators */
406 bta_hf_client_ind(index, value);
409 static void bta_hf_client_handle_chld(UINT32 mask)
411 APPL_TRACE_DEBUG("%s 0x%x", __FUNCTION__, mask);
413 bta_hf_client_cb.scb.chld_features |= mask;
416 static void bta_hf_client_handle_ciev(UINT32 index, UINT32 value)
420 APPL_TRACE_DEBUG("%s index: %u value: %u", __FUNCTION__, index, value);
422 if(index == 0 || index > BTA_HF_CLIENT_AT_INDICATOR_COUNT)
427 if (service_index == index - 1)
429 service_availability = value == 0 ? FALSE : TRUE;
432 realind = bta_hf_client_cb.scb.at_cb.indicator_lookup[index - 1];
434 if(realind >= 0 && realind < BTA_HF_CLIENT_AT_SUPPORTED_INDICATOR_COUNT)
436 /* get the real in-array index from lookup table by index it comes at */
437 /* if there is no bug it should automatically be correctly calculated */
438 if(value > bta_hf_client_indicators[realind].max || value < bta_hf_client_indicators[realind].min)
443 /* update service availability on +ciev from AG. */
444 if (service_index == (index - 1))
448 service_availability = TRUE;
452 service_availability = FALSE;
456 /* tBTA_HF_CLIENT_IND_TYPE match index in bta_hf_client_indicators */
457 bta_hf_client_ind(realind, value);
461 static void bta_hf_client_handle_bcs(UINT32 codec)
463 APPL_TRACE_DEBUG("%s %u", __FUNCTION__, codec);
465 if (codec == BTM_SCO_CODEC_CVSD ||
466 (codec == BTM_SCO_CODEC_MSBC && bta_hf_client_cb.msbc_enabled == TRUE))
468 bta_hf_client_cb.scb.negotiated_codec = codec;
469 bta_hf_client_send_at_bcs(codec);
473 bta_hf_client_cb.scb.negotiated_codec = BTM_SCO_CODEC_CVSD;
474 bta_hf_client_send_at_bac();
478 static void bta_hf_client_handle_bsir(UINT32 provided)
480 APPL_TRACE_DEBUG("%s %u", __FUNCTION__, provided);
482 bta_hf_client_evt_val(BTA_HF_CLIENT_BSIR_EVT, provided);
485 static void bta_hf_client_handle_cmeerror(UINT32 code)
487 bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_CME, code);
490 static void bta_hf_client_handle_vgm(UINT32 value)
492 APPL_TRACE_DEBUG("%s %lu", __FUNCTION__, value);
494 if(value <= BTA_HF_CLIENT_VGM_MAX)
496 bta_hf_client_evt_val(BTA_HF_CLIENT_MIC_EVT, value);
500 static void bta_hf_client_handle_vgs(UINT32 value)
502 APPL_TRACE_DEBUG("%s %lu", __FUNCTION__, value);
504 if(value <= BTA_HF_CLIENT_VGS_MAX)
506 bta_hf_client_evt_val(BTA_HF_CLIENT_SPK_EVT, value);
510 static void bta_hf_client_handle_bvra(UINT32 value)
512 APPL_TRACE_DEBUG("%s %lu", __FUNCTION__, value);
519 bta_hf_client_evt_val(BTA_HF_CLIENT_VOICE_REC_EVT, value);
522 static void bta_hf_client_handle_clip(char *numstr, UINT32 type)
524 APPL_TRACE_DEBUG("%s %u %s", __FUNCTION__, type, numstr);
526 bta_hf_client_clip(numstr);
529 static void bta_hf_client_handle_ccwa(char *numstr, UINT32 type)
531 APPL_TRACE_DEBUG("%s %u %s", __FUNCTION__, type, numstr);
533 bta_hf_client_ccwa(numstr);
536 static void bta_hf_client_handle_cops(char *opstr, UINT32 mode)
538 APPL_TRACE_DEBUG("%s %u %s", __FUNCTION__, mode, opstr);
540 bta_hf_client_operator_name(opstr);
543 static void bta_hf_client_handle_binp(char *numstr)
545 APPL_TRACE_DEBUG("%s %s", __FUNCTION__, numstr);
547 bta_hf_client_binp(numstr);
550 static void bta_hf_client_handle_clcc(UINT16 idx, UINT16 dir, UINT16 status, UINT16 mode, UINT16 mpty, char *numstr, UINT16 type)
552 APPL_TRACE_DEBUG("%s idx: %u dir: %u status: %u mode: %u mpty: %u",
553 __FUNCTION__, idx, dir, status, mode, mpty);
557 APPL_TRACE_DEBUG("%s number: %s type: %u", __FUNCTION__, numstr, type);
560 bta_hf_client_clcc(idx, dir, status, mpty, numstr);
563 static void bta_hf_client_handle_cnum( char *numstr, UINT16 type, UINT16 service)
565 APPL_TRACE_DEBUG("%s number: %s type: %u service: %u", __FUNCTION__, numstr, type, service);
567 /* TODO: should number be modified according to type? */
568 bta_hf_client_cnum(numstr, service);
571 static void bta_hf_client_handle_btrh( UINT16 code)
573 APPL_TRACE_DEBUG("%s %lu", __FUNCTION__, code);
575 bta_hf_client_evt_val(BTA_HF_CLIENT_BTRH_EVT, code);
578 /******************************************************************************
580 ** COMMON AT EVENTS PARSING FUNCTIONS
582 *******************************************************************************/
584 /* Check if prefix match and skip spaces if any */
585 #define AT_CHECK_EVENT(buf, event) \
586 if (strncmp("\r\n"event, buf,sizeof("\r\n"event) - 1) != 0) return buf; \
587 buf += sizeof("\r\n"event) - 1; \
588 while (*buf == ' ') buf++;
590 /* check for <cr><lf> and forward buffer if match */
591 #define AT_CHECK_RN(buf) \
592 if (strncmp("\r\n", buf, sizeof("\r\n") - 1) != 0) { \
593 APPL_TRACE_DEBUG("%s missing end <cr><lf>", __FUNCTION__); \
595 buf += sizeof("\r\n") - 1;
597 /* skip rest of AT string up to <cr> */
598 #define AT_SKIP_REST(buf) while(*buf != '\r') buf++;
600 static char *bta_hf_client_parse_ok(char *buffer)
602 AT_CHECK_EVENT(buffer, "OK");
605 bta_hf_client_handle_ok();
610 static char *bta_hf_client_parse_error(char *buffer)
612 AT_CHECK_EVENT(buffer, "ERROR");
615 bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_ERROR, 0);
620 static char *bta_hf_client_parse_ring(char *buffer)
622 AT_CHECK_EVENT(buffer, "RING");
625 bta_hf_client_handle_ring();
630 /* generic uint32 parser */
631 static char *bta_hf_client_parse_uint32(char *buffer, void (*handler_callback)(UINT32))
637 res = sscanf(buffer, "%u%n", &value, &offset);
647 handler_callback(value);
651 static char *bta_hf_client_parse_brsf(char *buffer)
653 AT_CHECK_EVENT(buffer, "+BRSF:");
655 return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_brsf);
658 static char *bta_hf_client_parse_cind_values(char *buffer)
660 /* value and its position */
667 while((res = sscanf(buffer, "%u%n", &value, &offset)) > 0)
669 /* decides if its valid index and value, if yes stores it */
670 bta_hf_client_handle_cind_value(index, value);
674 /* check if more values are present */
693 static char *bta_hf_client_parse_cind_list(char *buffer)
701 while ((res = sscanf(buffer, "(\"%128[^\"]\",(%u%*[-,]%u))%n", name, &min, &max, &offset)) > 2)
703 bta_hf_client_handle_cind_list_item(name, min, max, index);
706 APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
730 static char *bta_hf_client_parse_cind(char *buffer)
732 AT_CHECK_EVENT(buffer, "+CIND:");
735 return bta_hf_client_parse_cind_list(buffer);
737 return bta_hf_client_parse_cind_values(buffer);
740 static char *bta_hf_client_parse_chld(char *buffer)
742 AT_CHECK_EVENT(buffer, "+CHLD:");
751 while(*buffer != '\0')
753 if(strncmp("0",buffer, 1) == 0)
755 bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_REL);
758 else if(strncmp("1x",buffer, 2) == 0)
760 bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_REL_X);
763 else if(strncmp("1",buffer, 1) == 0)
765 bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_REL_ACC);
768 else if(strncmp("2x",buffer, 2) == 0)
770 bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_PRIV_X);
773 else if(strncmp("2",buffer, 1) == 0)
775 bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_HOLD_ACC);
778 else if(strncmp("3",buffer, 1) == 0)
780 bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_MERGE);
783 else if(strncmp("4",buffer, 1) == 0)
785 bta_hf_client_handle_chld(BTA_HF_CLIENT_CHLD_MERGE_DETACH);
813 static char *bta_hf_client_parse_ciev(char *buffer)
819 AT_CHECK_EVENT(buffer, "+CIEV:");
821 res = sscanf(buffer, "%u,%u%n", &index, &value, &offset);
829 APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
837 bta_hf_client_handle_ciev(index, value);
841 static char *bta_hf_client_parse_bcs(char *buffer)
843 AT_CHECK_EVENT(buffer, "+BCS:");
845 return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_bcs);
848 static char *bta_hf_client_parse_bsir(char *buffer)
850 AT_CHECK_EVENT(buffer, "+BSIR:");
852 return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_bsir);
855 static char *bta_hf_client_parse_cmeerror(char *buffer)
857 AT_CHECK_EVENT(buffer, "+CME ERROR:");
859 return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_cmeerror);
862 static char *bta_hf_client_parse_vgm(char *buffer)
864 AT_CHECK_EVENT(buffer, "+VGM:");
866 return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_vgm);
869 static char *bta_hf_client_parse_vgme(char *buffer)
871 AT_CHECK_EVENT(buffer, "+VGM=");
873 return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_vgm);
876 static char *bta_hf_client_parse_vgs(char *buffer)
878 AT_CHECK_EVENT(buffer, "+VGS:");
880 return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_vgs);
883 static char *bta_hf_client_parse_vgse(char *buffer)
885 AT_CHECK_EVENT(buffer, "+VGS=");
887 return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_vgs);
890 static char *bta_hf_client_parse_bvra(char *buffer)
892 AT_CHECK_EVENT(buffer, "+BVRA:");
894 return bta_hf_client_parse_uint32(buffer, bta_hf_client_handle_bvra);
897 static char *bta_hf_client_parse_clip(char *buffer)
899 /* spec forces 32 chars, plus \0 here */
905 AT_CHECK_EVENT(buffer, "+CLIP:");
907 /* there might be something more after %lu but HFP doesn't care */
908 res = sscanf(buffer, "\"%32[^\"]\",%u%n", number, &type, &offset);
916 APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
922 AT_SKIP_REST(buffer);
926 bta_hf_client_handle_clip(number, type);
930 /* in HFP context there is no difference between ccwa and clip */
931 static char *bta_hf_client_parse_ccwa(char *buffer)
933 /* ac to spec 32 chars max, plus \0 here */
939 AT_CHECK_EVENT(buffer, "+CCWA:");
941 /* there might be something more after %lu but HFP doesn't care */
942 res = sscanf(buffer, "\"%32[^\"]\",%u%n", number, &type, &offset);
950 APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
956 AT_SKIP_REST(buffer);
960 bta_hf_client_handle_ccwa(number, type);
964 static char *bta_hf_client_parse_cops(char *buffer)
967 /* spec forces 16 chars max, plus \0 here */
972 AT_CHECK_EVENT(buffer, "+COPS:");
974 /* TODO: Not sure if operator string actually can contain escaped " char inside */
975 res = sscanf(buffer, "%hhi,0,\"%16[^\"]\"%n", &mode, opstr, &offset);
980 /* Abort in case offset not set because of format error */
983 APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
989 AT_SKIP_REST(buffer);
993 bta_hf_client_handle_cops(opstr, mode);
994 // check for OK Response in end
995 AT_CHECK_EVENT(buffer, "OK");
998 bta_hf_client_handle_ok();
1003 static char *bta_hf_client_parse_binp(char *buffer)
1005 /* HFP only supports phone number as BINP data */
1006 /* phone number is 32 chars plus one for \0*/
1011 AT_CHECK_EVENT(buffer, "+BINP:");
1013 res = sscanf(buffer, "\"%32[^\"]\"\r\n%n", numstr, &offset);
1019 /* Abort in case offset not set because of format error */
1022 APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
1028 /* some phones might sent type as well, just skip it */
1029 AT_SKIP_REST(buffer);
1031 AT_CHECK_RN(buffer);
1033 bta_hf_client_handle_binp(numstr);
1035 // check for OK response in end
1036 AT_CHECK_EVENT(buffer, "OK");
1037 AT_CHECK_RN(buffer);
1039 bta_hf_client_handle_ok();
1044 static char *bta_hf_client_parse_clcc(char *buffer)
1046 UINT16 idx, dir, status, mode, mpty;
1047 char numstr[33]; /* spec forces 32 chars, plus one for \0*/
1052 AT_CHECK_EVENT(buffer, "+CLCC:");
1054 res = sscanf(buffer, "%hu,%hu,%hu,%hu,%hu%n",
1055 &idx, &dir, &status, &mode, &mpty, &offset);
1061 /* Abort in case offset not set because of format error */
1064 APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
1071 /* check optional part */
1074 int res2 = sscanf(buffer, ",\"%32[^\"]\",%hu%n", numstr, &type, &offset);
1080 res2 = sscanf(buffer, ",\"\",%hu%n", &type, &offset);
1084 /* numstr is not matched in second attempt, correct this */
1092 /* Abort in case offset not set because of format error */
1095 APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
1103 /* Skip any remaing param,as they are not defined by BT HFP spec */
1104 AT_SKIP_REST(buffer);
1105 AT_CHECK_RN(buffer);
1109 /* we also have last two optional parameters */
1110 bta_hf_client_handle_clcc(idx, dir, status, mode, mpty, numstr, type);
1114 /* we didn't get the last two parameters */
1115 bta_hf_client_handle_clcc(idx, dir, status, mode, mpty, NULL, 0);
1118 // check for OK response in end
1119 AT_CHECK_EVENT(buffer, "OK");
1120 AT_CHECK_RN(buffer);
1122 bta_hf_client_handle_ok();
1126 static char *bta_hf_client_parse_cnum(char *buffer)
1128 char numstr[33]; /* spec forces 32 chars, plus one for \0*/
1130 UINT16 service = 0; /* 0 in case this optional parameter is not being sent */
1134 AT_CHECK_EVENT(buffer, "+CNUM:");
1136 res = sscanf(buffer, ",\"%32[^\"]\",%hu,,%hu%n", numstr, &type, &service, &offset);
1144 res = sscanf(buffer, ",\"\",%hu,,%hu%n", &type, &service, &offset);
1150 /* numstr is not matched in second attempt, correct this */
1160 /* Abort in case offset not set because of format error */
1163 APPL_TRACE_ERROR("%s: Format Error %s", __func__, buffer);
1169 AT_CHECK_RN(buffer);
1171 /* service is optional */
1174 bta_hf_client_handle_cnum(numstr, type, service);
1178 if (service != 4 && service != 5)
1183 bta_hf_client_handle_cnum(numstr, type, service);
1185 // check for OK response in end
1186 AT_CHECK_EVENT(buffer, "OK");
1187 AT_CHECK_RN(buffer);
1189 bta_hf_client_handle_ok();
1193 static char *bta_hf_client_parse_btrh(char *buffer)
1199 AT_CHECK_EVENT(buffer, "+BTRH:");
1201 res = sscanf(buffer, "%hu%n", &code, &offset);
1209 AT_CHECK_RN(buffer);
1211 bta_hf_client_handle_btrh(code);
1215 static char *bta_hf_client_parse_busy(char *buffer)
1217 AT_CHECK_EVENT(buffer, "BUSY");
1218 AT_CHECK_RN(buffer);
1220 bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_BUSY, 0);
1225 static char *bta_hf_client_parse_delayed(char *buffer)
1227 AT_CHECK_EVENT(buffer, "DELAYED");
1228 AT_CHECK_RN(buffer);
1230 bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_DELAY, 0);
1235 static char *bta_hf_client_parse_no_carrier(char *buffer)
1237 AT_CHECK_EVENT(buffer, "NO CARRIER");
1238 AT_CHECK_RN(buffer);
1240 bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_NO_CARRIER, 0);
1245 static char *bta_hf_client_parse_no_answer(char *buffer)
1247 AT_CHECK_EVENT(buffer, "NO ANSWER");
1248 AT_CHECK_RN(buffer);
1250 bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_NO_ANSWER, 0);
1255 static char *bta_hf_client_parse_blacklisted(char *buffer)
1257 AT_CHECK_EVENT(buffer, "BLACKLISTED");
1258 AT_CHECK_RN(buffer);
1260 bta_hf_client_handle_error(BTA_HF_CLIENT_AT_RESULT_BLACKLISTED, 0);
1265 static char *bta_hf_client_skip_unknown(char *buffer)
1270 tmp = strstr(buffer, "\r\n");
1279 tmp = strstr(buffer, "\r\n");
1287 APPL_TRACE_DEBUG("%s %.*s", __FUNCTION__, buffer - start - 2, start);
1293 /******************************************************************************
1294 ** SUPPORTED EVENT MESSAGES
1295 *******************************************************************************/
1297 /* returned values are as follow:
1298 * != NULL && != buf : match and parsed ok
1299 * == NULL : match but parse failed
1300 * != NULL && == buf : no match
1302 typedef char* (*tBTA_HF_CLIENT_PARSER_CALLBACK)(char*);
1304 static const tBTA_HF_CLIENT_PARSER_CALLBACK bta_hf_client_parser_cb[] =
1306 bta_hf_client_parse_ok,
1307 bta_hf_client_parse_error,
1308 bta_hf_client_parse_ring,
1309 bta_hf_client_parse_brsf,
1310 bta_hf_client_parse_cind,
1311 bta_hf_client_parse_ciev,
1312 bta_hf_client_parse_chld,
1313 bta_hf_client_parse_bcs,
1314 bta_hf_client_parse_bsir,
1315 bta_hf_client_parse_cmeerror,
1316 bta_hf_client_parse_vgm,
1317 bta_hf_client_parse_vgme,
1318 bta_hf_client_parse_vgs,
1319 bta_hf_client_parse_vgse,
1320 bta_hf_client_parse_bvra,
1321 bta_hf_client_parse_clip,
1322 bta_hf_client_parse_ccwa,
1323 bta_hf_client_parse_cops,
1324 bta_hf_client_parse_binp,
1325 bta_hf_client_parse_clcc,
1326 bta_hf_client_parse_cnum,
1327 bta_hf_client_parse_btrh,
1328 bta_hf_client_parse_busy,
1329 bta_hf_client_parse_delayed,
1330 bta_hf_client_parse_no_carrier,
1331 bta_hf_client_parse_no_answer,
1332 bta_hf_client_parse_blacklisted,
1333 bta_hf_client_skip_unknown
1336 /* calculate supported event list length */
1337 static const UINT16 bta_hf_client_psraser_cb_count =
1338 sizeof(bta_hf_client_parser_cb) / sizeof(bta_hf_client_parser_cb[0]);
1340 #ifdef BTA_HF_CLIENT_AT_DUMP
1341 static void bta_hf_client_dump_at(void)
1343 char dump[(4 * BTA_HF_CLIENT_AT_PARSER_MAX_LEN) + 1];
1346 p1 = bta_hf_client_cb.scb.at_cb.buf;
1353 strlcpy(p2, "<cr>", 4);
1356 else if (*p1 == '\n')
1358 strlcpy(p2, "<lf>", 4);
1371 APPL_TRACE_DEBUG("%s %s", __FUNCTION__, dump);
1375 static void bta_hf_client_at_parse_start(void)
1377 char *buf = bta_hf_client_cb.scb.at_cb.buf;
1379 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1381 #ifdef BTA_HF_CLIENT_AT_DUMP
1382 bta_hf_client_dump_at();
1390 for(i = 0; i < bta_hf_client_psraser_cb_count; i++)
1392 tmp = bta_hf_client_parser_cb[i](buf);
1395 APPL_TRACE_ERROR("HFPCient: AT event/reply parsing failed, skipping");
1396 tmp = bta_hf_client_skip_unknown(buf);
1400 /* matched or unknown skipped, if unknown failed tmp is NULL so
1401 this is also handled */
1409 /* could not skip unknown (received garbage?)... disconnect */
1412 APPL_TRACE_ERROR("HFPCient: could not skip unknown AT event, disconnecting");
1413 bta_hf_client_at_reset();
1414 bta_hf_client_sm_execute(BTA_HF_CLIENT_API_CLOSE_EVT, NULL);
1422 static BOOLEAN bta_hf_client_check_at_complete(void)
1424 BOOLEAN ret = FALSE;
1425 tBTA_HF_CLIENT_AT_CB *at_cb = &bta_hf_client_cb.scb.at_cb;
1427 if (at_cb->offset >= BTA_HF_CLIENT_AT_EVENT_MIN_LEN)
1429 if (at_cb->buf[at_cb->offset - 2] == '\r' && at_cb->buf[at_cb->offset - 1] == '\n')
1435 APPL_TRACE_DEBUG("%s %d", __FUNCTION__, ret);
1440 static void bta_hf_client_at_clear_buf(void)
1442 memset(bta_hf_client_cb.scb.at_cb.buf, 0, sizeof(bta_hf_client_cb.scb.at_cb.buf));
1443 bta_hf_client_cb.scb.at_cb.offset = 0;
1446 /******************************************************************************
1448 ** MAIN PARSING FUNCTION
1451 *******************************************************************************/
1452 void bta_hf_client_at_parse(char *buf, unsigned int len)
1454 APPL_TRACE_DEBUG("%s offset: %u len: %u", __FUNCTION__, bta_hf_client_cb.scb.at_cb.offset, len);
1456 if (len + bta_hf_client_cb.scb.at_cb.offset > BTA_HF_CLIENT_AT_PARSER_MAX_LEN)
1458 char tmp_buff[BTA_HF_CLIENT_AT_PARSER_MAX_LEN];
1459 unsigned int tmp = bta_hf_client_cb.scb.at_cb.offset;
1460 unsigned int space_left = BTA_HF_CLIENT_AT_PARSER_MAX_LEN - bta_hf_client_cb.scb.at_cb.offset;
1462 APPL_TRACE_DEBUG("%s overrun, trying to recover", __FUNCTION__);
1464 /* fill up parser buffer */
1465 memcpy(bta_hf_client_cb.scb.at_cb.buf + bta_hf_client_cb.scb.at_cb.offset, buf, space_left);
1468 bta_hf_client_cb.scb.at_cb.offset += space_left;
1470 /* find end of last complete command before proceeding */
1471 while(bta_hf_client_check_at_complete() == FALSE)
1473 if (bta_hf_client_cb.scb.at_cb.offset == 0) {
1474 APPL_TRACE_ERROR("HFPClient: AT parser buffer overrun, disconnecting");
1476 bta_hf_client_at_reset();
1477 bta_hf_client_sm_execute(BTA_HF_CLIENT_API_CLOSE_EVT, NULL);
1481 bta_hf_client_cb.scb.at_cb.offset--;
1484 /* cut buffer to complete AT event and keep cut data */
1485 tmp += space_left - bta_hf_client_cb.scb.at_cb.offset;
1486 memcpy(tmp_buff, bta_hf_client_cb.scb.at_cb.buf + bta_hf_client_cb.scb.at_cb.offset, tmp);
1487 bta_hf_client_cb.scb.at_cb.buf[bta_hf_client_cb.scb.at_cb.offset] = '\0';
1490 bta_hf_client_at_parse_start();
1491 bta_hf_client_at_clear_buf();
1493 /* recover cut data */
1494 memcpy(bta_hf_client_cb.scb.at_cb.buf, tmp_buff, tmp);
1495 bta_hf_client_cb.scb.at_cb.offset += tmp;
1498 memcpy(bta_hf_client_cb.scb.at_cb.buf + bta_hf_client_cb.scb.at_cb.offset, buf, len);
1499 bta_hf_client_cb.scb.at_cb.offset += len;
1501 /* If last event is complete, parsing can be started */
1502 if (bta_hf_client_check_at_complete() == TRUE)
1504 bta_hf_client_at_parse_start();
1505 bta_hf_client_at_clear_buf();
1509 void bta_hf_client_send_at_brsf(void)
1511 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1514 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1516 at_len = snprintf(buf, sizeof(buf), "AT+BRSF=%u\r", bta_hf_client_cb.scb.features);
1519 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1523 bta_hf_client_send_at(BTA_HF_CLIENT_AT_BRSF , buf, at_len);
1526 void bta_hf_client_send_at_bac(void)
1530 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1532 if (bta_hf_client_cb.msbc_enabled)
1534 buf = "AT+BAC=1,2\r";
1541 bta_hf_client_send_at(BTA_HF_CLIENT_AT_BAC, buf, strlen(buf));
1544 void bta_hf_client_send_at_bcs(UINT32 codec)
1546 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1549 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1551 at_len = snprintf(buf, sizeof(buf), "AT+BCS=%u\r", codec);
1554 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1558 bta_hf_client_send_at(BTA_HF_CLIENT_AT_BCS, buf, at_len);
1561 void bta_hf_client_send_at_cind(BOOLEAN status)
1564 tBTA_HF_CLIENT_AT_CMD cmd;
1566 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1571 cmd = BTA_HF_CLIENT_AT_CIND_STATUS;
1575 buf = "AT+CIND=?\r";
1576 cmd = BTA_HF_CLIENT_AT_CIND;
1579 bta_hf_client_send_at(cmd, buf, strlen(buf));
1582 void bta_hf_client_send_at_cmer(BOOLEAN activate)
1586 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1589 buf = "AT+CMER=3,0,0,1\r";
1591 buf = "AT+CMER=3,0,0,0\r";
1593 bta_hf_client_send_at(BTA_HF_CLIENT_AT_CMER, buf, strlen(buf));
1596 void bta_hf_client_send_at_chld(char cmd, UINT32 idx)
1598 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1601 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1604 at_len = snprintf(buf, sizeof(buf), "AT+CHLD=%c%u\r", cmd, idx);
1606 at_len = snprintf(buf, sizeof(buf), "AT+CHLD=%c\r", cmd);
1610 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1614 bta_hf_client_send_at(BTA_HF_CLIENT_AT_CHLD, buf, at_len);
1617 void bta_hf_client_send_at_clip(BOOLEAN activate)
1621 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1624 buf = "AT+CLIP=1\r";
1626 buf = "AT+CLIP=0\r";
1628 bta_hf_client_send_at(BTA_HF_CLIENT_AT_CLIP, buf, strlen(buf));
1631 void bta_hf_client_send_at_ccwa(BOOLEAN activate)
1635 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1638 buf = "AT+CCWA=1\r";
1640 buf = "AT+CCWA=0\r";
1642 bta_hf_client_send_at(BTA_HF_CLIENT_AT_CCWA, buf, strlen(buf));
1646 void bta_hf_client_send_at_cmee(BOOLEAN activate)
1650 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1653 buf = "AT+CMEE=1\r";
1655 buf = "AT+CMEE=0\r";
1657 bta_hf_client_send_at(BTA_HF_CLIENT_AT_CMEE, buf, strlen(buf));
1660 void bta_hf_client_send_at_cops(BOOLEAN query)
1664 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1669 buf = "AT+COPS=3,0\r";
1671 bta_hf_client_send_at(BTA_HF_CLIENT_AT_COPS, buf, strlen(buf));
1674 void bta_hf_client_send_at_clcc(void)
1678 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1682 bta_hf_client_send_at(BTA_HF_CLIENT_AT_CLCC, buf, strlen(buf));
1685 void bta_hf_client_send_at_bvra(BOOLEAN enable)
1689 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1692 buf = "AT+BVRA=1\r";
1694 buf = "AT+BVRA=0\r";
1696 bta_hf_client_send_at(BTA_HF_CLIENT_AT_BVRA, buf, strlen(buf));
1699 void bta_hf_client_send_at_vgs(UINT32 volume)
1701 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1704 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1706 at_len = snprintf(buf, sizeof(buf), "AT+VGS=%u\r", volume);
1709 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1713 bta_hf_client_send_at(BTA_HF_CLIENT_AT_VGS, buf, at_len);
1716 void bta_hf_client_send_at_vgm(UINT32 volume)
1718 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1721 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1723 at_len = snprintf(buf, sizeof(buf), "AT+VGM=%u\r", volume);
1726 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1730 bta_hf_client_send_at(BTA_HF_CLIENT_AT_VGM, buf, at_len);
1733 void bta_hf_client_send_at_atd(char *number, UINT32 memory)
1735 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1738 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1740 if (number[0] != '\0') {
1741 at_len = snprintf(buf, sizeof(buf), "ATD%s;\r", number);
1743 at_len = snprintf(buf, sizeof(buf), "ATD>%u;\r", memory);
1747 APPL_TRACE_ERROR("%s: error preparing ATD command", __func__);
1751 at_len = MIN((size_t)at_len, sizeof(buf));
1755 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1758 bta_hf_client_send_at(BTA_HF_CLIENT_AT_ATD, buf, at_len);
1761 void bta_hf_client_send_at_bldn(void)
1765 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1769 bta_hf_client_send_at(BTA_HF_CLIENT_AT_BLDN, buf, strlen(buf));
1772 void bta_hf_client_send_at_ata(void)
1776 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1780 bta_hf_client_send_at(BTA_HF_CLIENT_AT_ATA, buf, strlen(buf));
1783 void bta_hf_client_send_at_chup(void)
1787 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1791 bta_hf_client_send_at(BTA_HF_CLIENT_AT_CHUP, buf, strlen(buf));
1794 void bta_hf_client_send_at_btrh(BOOLEAN query, UINT32 val)
1796 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1799 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1803 at_len = snprintf(buf, sizeof(buf), "AT+BTRH?\r");
1807 at_len = snprintf(buf, sizeof(buf), "AT+BTRH=%u\r", val);
1812 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1816 bta_hf_client_send_at(BTA_HF_CLIENT_AT_BTRH, buf, at_len);
1819 void bta_hf_client_send_at_vts(char code)
1821 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1824 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1826 at_len = snprintf(buf, sizeof(buf), "AT+VTS=%c\r", code);
1830 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1834 bta_hf_client_send_at(BTA_HF_CLIENT_AT_VTS, buf, at_len);
1837 void bta_hf_client_send_at_bcc(void)
1841 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1845 bta_hf_client_send_at(BTA_HF_CLIENT_AT_BCC, buf, strlen(buf));
1848 void bta_hf_client_send_at_cnum(void)
1852 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1856 bta_hf_client_send_at(BTA_HF_CLIENT_AT_CNUM, buf, strlen(buf));
1859 void bta_hf_client_send_at_nrec(void)
1863 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1865 if (!(bta_hf_client_cb.scb.peer_features & BTA_HF_CLIENT_PEER_FEAT_ECNR))
1867 APPL_TRACE_ERROR("%s: Remote does not support NREC.", __FUNCTION__);
1871 buf = "AT+NREC=0\r";
1873 bta_hf_client_send_at(BTA_HF_CLIENT_AT_NREC, buf, strlen(buf));
1876 void bta_hf_client_send_at_binp(UINT32 action)
1878 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1881 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1883 at_len = snprintf(buf, sizeof(buf), "AT+BINP=%u\r", action);
1887 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1891 bta_hf_client_send_at(BTA_HF_CLIENT_AT_BINP, buf, at_len);
1894 void bta_hf_client_send_at_bia(void)
1896 char buf[BTA_HF_CLIENT_AT_MAX_LEN];
1900 APPL_TRACE_DEBUG("%s", __FUNCTION__);
1901 if (bta_hf_client_cb.scb.peer_version < HFP_VERSION_1_6)
1903 APPL_TRACE_DEBUG("Remote does not Support AT+BIA");
1907 at_len = snprintf(buf, sizeof(buf), "AT+BIA=");
1909 for(i = 0; i < BTA_HF_CLIENT_AT_INDICATOR_COUNT; i++)
1911 int sup = bta_hf_client_cb.scb.at_cb.indicator_lookup[i] == -1 ? 0 : 1;
1913 at_len += snprintf(buf + at_len, sizeof(buf) - at_len, "%u,", sup);
1916 buf[at_len - 1] = '\r';
1920 APPL_TRACE_ERROR("%s: AT command Framing error", __func__);
1924 bta_hf_client_send_at(BTA_HF_CLIENT_AT_BIA, buf, at_len);
1927 void bta_hf_client_at_init(void)
1929 alarm_free(bta_hf_client_cb.scb.at_cb.resp_timer);
1930 alarm_free(bta_hf_client_cb.scb.at_cb.hold_timer);
1931 memset(&bta_hf_client_cb.scb.at_cb, 0, sizeof(tBTA_HF_CLIENT_AT_CB));
1932 bta_hf_client_cb.scb.at_cb.resp_timer =
1933 alarm_new("bta_hf_client.scb_at_resp_timer");
1934 bta_hf_client_cb.scb.at_cb.hold_timer =
1935 alarm_new("bta_hf_client.scb_at_hold_timer");
1936 bta_hf_client_at_reset();
1939 void bta_hf_client_at_reset(void)
1943 bta_hf_client_stop_at_resp_timer();
1944 bta_hf_client_stop_at_hold_timer();
1946 bta_hf_client_clear_queued_at();
1948 bta_hf_client_at_clear_buf();
1950 for (i = 0; i < BTA_HF_CLIENT_AT_INDICATOR_COUNT; i++)
1952 bta_hf_client_cb.scb.at_cb.indicator_lookup[i] = -1;
1955 bta_hf_client_cb.scb.at_cb.current_cmd = BTA_HF_CLIENT_AT_NONE;