141d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/******************************************************************************
241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *
341d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  Copyright (c) 2014 The Android Open Source Project
441d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  Copyright (C) 2003-2012 Broadcom Corporation
541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *
641d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  Licensed under the Apache License, Version 2.0 (the "License");
741d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  you may not use this file except in compliance with the License.
841d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  You may obtain a copy of the License at:
941d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *
1041d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  http://www.apache.org/licenses/LICENSE-2.0
1141d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *
1241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  Unless required by applicable law or agreed to in writing, software
1341d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  distributed under the License is distributed on an "AS IS" BASIS,
1441d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  See the License for the specific language governing permissions and
1641d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *  limitations under the License.
1741d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta *
1841d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta ******************************************************************************/
1941d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
2041d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta#include "bta_api.h"
2141d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta#include "bta_hf_client_api.h"
2241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta#include "bta_hf_client_at.h"
23cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson#include "bta_sys.h"
2441d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
2541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/*****************************************************************************
268af480e24549ba51a3f6858d9d9af504715e0beaMyles Watson *  Constants
278af480e24549ba51a3f6858d9d9af504715e0beaMyles Watson ****************************************************************************/
28cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson#define HFP_VERSION_1_1 0x0101
29cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson#define HFP_VERSION_1_5 0x0105
30cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson#define HFP_VERSION_1_6 0x0106
3141d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
3241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* RFCOMM MTU SIZE */
33cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson#define BTA_HF_CLIENT_MTU 256
3441d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
3541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* profile role for connection */
36cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson#define BTA_HF_CLIENT_ACP 0 /* accepted connection */
37cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson#define BTA_HF_CLIENT_INT 1 /* initiating connection */
3841d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
3978bcff79e1b1f0efce436b33bdd6da88745bfc8aPavlin Radoslavov/* Time (in milliseconds) to wait for retry in case of collision */
4078bcff79e1b1f0efce436b33bdd6da88745bfc8aPavlin Radoslavov#ifndef BTA_HF_CLIENT_COLLISION_TIMER_MS
41cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson#define BTA_HF_CLIENT_COLLISION_TIMER_MS 2411
4241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta#endif
4341d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
445eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal/* Maximum number of HF devices supported simultaneously */
455eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal#define HF_CLIENT_MAX_DEVICES 10
465eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal
47cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonenum {
48cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  /* these events are handled by the state machine */
49bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_API_OPEN_EVT = BTA_SYS_EVT_START(BTA_ID_HS),
50cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_API_CLOSE_EVT,
51cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_API_AUDIO_OPEN_EVT,
52cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_API_AUDIO_CLOSE_EVT,
53cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_RFC_OPEN_EVT,
54cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_RFC_CLOSE_EVT,
55cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_RFC_SRV_CLOSE_EVT,
56cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_RFC_DATA_EVT,
57cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_DISC_ACP_RES_EVT,
58cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_DISC_INT_RES_EVT,
59cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_DISC_OK_EVT,
60cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_DISC_FAIL_EVT,
61cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_SCO_OPEN_EVT,
62cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_SCO_CLOSE_EVT,
63cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_SEND_AT_CMD_EVT,
64cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_MAX_EVT,
6541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
66cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  /* these events are handled outside of the state machine */
67cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_API_ENABLE_EVT,
68cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BTA_HF_CLIENT_API_DISABLE_EVT
6941d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta};
7041d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
71bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal/* AT Command enum */
72bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalenum {
73bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_NONE,
74bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_BRSF,
75bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_BAC,
76bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CIND,
77bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CIND_STATUS,
78bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CMER,
79bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CHLD,
80bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CMEE,
81bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_BIA,
82bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CLIP,
83bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CCWA,
84bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_COPS,
85bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CLCC,
86bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_BVRA,
87bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_VGS,
88bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_VGM,
89bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_ATD,
90bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_BLDN,
91bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_ATA,
92bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CHUP,
93bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_BTRH,
94bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_VTS,
95bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_BCC,
96bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_BCS,
97bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_CNUM,
98bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_NREC,
99bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  BTA_HF_CLIENT_AT_BINP,
100bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal};
101bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal
10241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/*****************************************************************************
1038af480e24549ba51a3f6858d9d9af504715e0beaMyles Watson *  Data types
1048af480e24549ba51a3f6858d9d9af504715e0beaMyles Watson ****************************************************************************/
10541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* data type for BTA_HF_CLIENT_API_OPEN_EVT */
106cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsontypedef struct {
107cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BT_HDR hdr;
1089e030fde05352ec4385d7baf6cc2af89e95e039cJakub Pawlowski  RawAddress bd_addr;
109bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  uint16_t* handle;
110cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_SEC sec_mask;
11141d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta} tBTA_HF_CLIENT_API_OPEN;
11241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
11341d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* data type for BTA_HF_CLIENT_DISC_RESULT_EVT */
114cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsontypedef struct {
115cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BT_HDR hdr;
116cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint16_t status;
11741d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta} tBTA_HF_CLIENT_DISC_RESULT;
11841d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
11941d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* data type for RFCOMM events */
120cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsontypedef struct {
121cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BT_HDR hdr;
122cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint16_t port_handle;
12341d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta} tBTA_HF_CLIENT_RFC;
12441d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
12541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* generic purpose data type for other events */
126cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsontypedef struct {
127cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BT_HDR hdr;
128cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  bool bool_val;
129cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint8_t uint8_val;
130cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint32_t uint32_val1;
131cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint32_t uint32_val2;
132cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  char str[BTA_HF_CLIENT_NUMBER_LEN + 1];
13341d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta} tBTA_HF_CLIENT_DATA_VAL;
13441d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
13541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* union of all event datatypes */
136cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsontypedef union {
137cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  BT_HDR hdr;
138cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_HF_CLIENT_API_OPEN api_open;
139cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_HF_CLIENT_DISC_RESULT disc_result;
140cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_HF_CLIENT_RFC rfc;
141cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_HF_CLIENT_DATA_VAL val;
14241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
14341d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta} tBTA_HF_CLIENT_DATA;
14441d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
145bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal/* First handle for the control block */
146bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal#define BTA_HF_CLIENT_CB_FIRST_HANDLE 1
147bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal
1485eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal/* sco states */
1495eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalenum {
1505eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  BTA_HF_CLIENT_SCO_SHUTDOWN_ST, /* no listening, no connection */
1515eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  BTA_HF_CLIENT_SCO_LISTEN_ST,   /* listening */
1525eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  BTA_HF_CLIENT_SCO_OPENING_ST,  /* connection opening */
1535eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  BTA_HF_CLIENT_SCO_OPEN_CL_ST,  /* opening connection being closed */
1545eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  BTA_HF_CLIENT_SCO_OPEN_ST,     /* open */
1555eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  BTA_HF_CLIENT_SCO_CLOSING_ST,  /* closing */
1565eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  BTA_HF_CLIENT_SCO_CLOSE_OP_ST, /* closing sco being opened */
1575eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  BTA_HF_CLIENT_SCO_SHUTTING_ST  /* sco shutting down */
1585eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal};
1595eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal
1605eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal/* type for HF control block */
161cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsontypedef struct {
1625eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  // Fields useful for particular control block.
163bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  uint8_t handle;               /* Handle of the control block to be
164bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                   used by upper layer */
1659e030fde05352ec4385d7baf6cc2af89e95e039cJakub Pawlowski  RawAddress peer_addr;         /* peer bd address */
166cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tSDP_DISCOVERY_DB* p_disc_db; /* pointer to discovery database */
167cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint16_t conn_handle;         /* RFCOMM handle of connected service */
168cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_SEC cli_sec_mask;        /* client security mask */
169cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_HF_CLIENT_PEER_FEAT peer_features; /* peer device features */
170cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_HF_CLIENT_CHLD_FEAT chld_features; /* call handling features */
171cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint16_t peer_version;                  /* profile version of peer device */
172cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint8_t peer_scn;                       /* peer scn */
173cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint8_t role;                           /* initiator/acceptor role */
174cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint16_t sco_idx;                       /* SCO handle */
175cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint8_t sco_state;                      /* SCO state variable */
176cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  bool sco_close_rfc; /* true if also close RFCOMM after SCO */
1775eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  tBTM_SCO_CODEC_TYPE negotiated_codec; /* negotiated codec */
178cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  bool svc_conn;      /* set to true when service level connection is up */
179cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  bool send_at_reply; /* set to true to notify framework about AT results */
180cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_HF_CLIENT_AT_CB at_cb;           /* AT Parser control block */
181cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint8_t state;                        /* state machine state */
182bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal  bool is_allocated; /* if the control block is already allocated */
183cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  alarm_t* collision_timer;             /* Collision timer */
1845eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal} tBTA_HF_CLIENT_CB;
18541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
186cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsontypedef struct {
1875eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  // Common fields, should be taken out.
188cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint32_t sdp_handle;
189cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  uint8_t scn;
190cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson  tBTA_HF_CLIENT_CBACK* p_cback; /* application callback */
1915eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  tBTA_HF_CLIENT_FEAT features;  /* features registered by application */
1925eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  tBTA_SEC serv_sec_mask;        /* server security mask */
1935eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  uint16_t serv_handle;          /* RFCOMM server handle */
1945eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  bool deregister;               /* true if service shutting down */
1955eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal
1965eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  // Maximum number of control blocks supported by the BTA layer.
1975eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal  tBTA_HF_CLIENT_CB cb[HF_CLIENT_MAX_DEVICES];
1985eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal} tBTA_HF_CLIENT_CB_ARR;
1995eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal
2005eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalextern tBTA_HF_CLIENT_CB_ARR bta_hf_client_cb_arr;
20141d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
20241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/*****************************************************************************
2038af480e24549ba51a3f6858d9d9af504715e0beaMyles Watson *  Function prototypes
2048af480e24549ba51a3f6858d9d9af504715e0beaMyles Watson ****************************************************************************/
20541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
20641d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* main functions */
207bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_handle(uint16_t handle);
208744eeca761b6d52d4e5fbbfa49c2d2adde0e6981Jakub Pawlowskiextern tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_bda(
2099e030fde05352ec4385d7baf6cc2af89e95e039cJakub Pawlowski    const RawAddress& bd_addr);
210bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_rfc_handle(uint16_t handle);
211bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_sco_handle(uint16_t handle);
212cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern bool bta_hf_client_hdl_event(BT_HDR* p_msg);
213e9e58ced195ec2c983c7723c9cbdabd45eb0f2fdMarie Janssenextern void bta_hf_client_sm_execute(uint16_t event,
214cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson                                     tBTA_HF_CLIENT_DATA* p_data);
215bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_slc_seq(tBTA_HF_CLIENT_CB* client_cb, bool error);
2169e030fde05352ec4385d7baf6cc2af89e95e039cJakub Pawlowskiextern bool bta_hf_client_allocate_handle(const RawAddress& bd_addr,
217bd3ae7cbf195caf91693046147b34d25b6317485Sanket Agarwal                                          uint16_t* p_handle);
2185eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalextern void bta_hf_client_app_callback(uint16_t event, tBTA_HF_CLIENT* data);
219cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_collision_cback(tBTA_SYS_CONN_STATUS status,
220cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson                                          uint8_t id, uint8_t app_id,
2219e030fde05352ec4385d7baf6cc2af89e95e039cJakub Pawlowski                                          const RawAddress* peer_addr);
2225eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalextern void bta_hf_client_resume_open(tBTA_HF_CLIENT_CB* client_cb);
223bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern tBTA_STATUS bta_hf_client_api_enable(tBTA_HF_CLIENT_CBACK* p_cback,
224bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                            tBTA_SEC sec_mask,
225bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                            tBTA_HF_CLIENT_FEAT features,
226bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                            const char* p_service_name);
227bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal
228bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_api_disable(void);
2295eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalextern void bta_hf_client_dump_statistics(int fd);
230bd3ae7cbf195caf91693046147b34d25b6317485Sanket Agarwalextern void bta_hf_client_cb_arr_init(void);
23141d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
23241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* SDP functions */
233cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern bool bta_hf_client_add_record(char* p_service_name, uint8_t scn,
234cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson                                     tBTA_HF_CLIENT_FEAT features,
235cd1fd07f1306e08fe048682dd5918987e579f937Myles Watson                                     uint32_t sdp_handle);
2365eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalextern void bta_hf_client_create_record(tBTA_HF_CLIENT_CB_ARR* client_cb,
237bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                        const char* p_data);
2385eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalextern void bta_hf_client_del_record(tBTA_HF_CLIENT_CB_ARR* client_cb);
239bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern bool bta_hf_client_sdp_find_attr(tBTA_HF_CLIENT_CB* client_cb);
240bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_do_disc(tBTA_HF_CLIENT_CB* client_cb);
241cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_free_db(tBTA_HF_CLIENT_DATA* p_data);
24241d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
24341d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* RFCOMM functions */
244e9e58ced195ec2c983c7723c9cbdabd45eb0f2fdMarie Janssenextern void bta_hf_client_setup_port(uint16_t handle);
2455eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalextern void bta_hf_client_start_server();
2465eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalextern void bta_hf_client_close_server();
247cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_rfc_do_open(tBTA_HF_CLIENT_DATA* p_data);
248cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_rfc_do_close(tBTA_HF_CLIENT_DATA* p_data);
24941d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
25041d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* SCO functions */
251cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_sco_listen(tBTA_HF_CLIENT_DATA* p_data);
252cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_sco_conn_open(tBTA_HF_CLIENT_DATA* p_data);
253cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_sco_conn_close(tBTA_HF_CLIENT_DATA* p_data);
254cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_sco_open(tBTA_HF_CLIENT_DATA* p_data);
255cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_sco_close(tBTA_HF_CLIENT_DATA* p_data);
256bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_sco_shutdown(tBTA_HF_CLIENT_CB* client_cb);
257bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_cback_sco(tBTA_HF_CLIENT_CB* client_cb,
258bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                    uint8_t event);
25941d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
26041d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* AT command functions */
261bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_at_parse(tBTA_HF_CLIENT_CB* client_cb, char* buf,
262bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                   unsigned int len);
2635eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwalextern void bta_hf_client_send_at_brsf(tBTA_HF_CLIENT_CB* client_cb,
2645eccd90936d606e0070872b247fd3462e9c9c19bSanket Agarwal                                       tBTA_HF_CLIENT_FEAT features);
265bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_bac(tBTA_HF_CLIENT_CB* client_cb);
266bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_cind(tBTA_HF_CLIENT_CB* client_cb,
267bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       bool status);
268bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_cmer(tBTA_HF_CLIENT_CB* client_cb,
269bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       bool activate);
270bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_chld(tBTA_HF_CLIENT_CB* client_cb, char cmd,
271bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       uint32_t idx);
272bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_clip(tBTA_HF_CLIENT_CB* client_cb,
273bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       bool activate);
274bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_ccwa(tBTA_HF_CLIENT_CB* client_cb,
275bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       bool activate);
276bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_cmee(tBTA_HF_CLIENT_CB* client_cb,
277bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       bool activate);
278bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_cops(tBTA_HF_CLIENT_CB* client_cb,
279bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       bool query);
280bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_clcc(tBTA_HF_CLIENT_CB* client_cb);
281bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_bvra(tBTA_HF_CLIENT_CB* client_cb,
282bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       bool enable);
283bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_vgs(tBTA_HF_CLIENT_CB* client_cb,
284bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                      uint32_t volume);
285bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_vgm(tBTA_HF_CLIENT_CB* client_cb,
286bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                      uint32_t volume);
287bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_atd(tBTA_HF_CLIENT_CB* client_cb,
288bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                      char* number, uint32_t memory);
289bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_bldn(tBTA_HF_CLIENT_CB* client_cb);
290bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_ata(tBTA_HF_CLIENT_CB* client_cb);
291bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_chup(tBTA_HF_CLIENT_CB* client_cb);
292bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_btrh(tBTA_HF_CLIENT_CB* client_cb, bool query,
293bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       uint32_t val);
294bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_vts(tBTA_HF_CLIENT_CB* client_cb, char code);
295bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_bcc(tBTA_HF_CLIENT_CB* client_cb);
296bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_bcs(tBTA_HF_CLIENT_CB* client_cb,
297bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                      uint32_t codec);
298bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_cnum(tBTA_HF_CLIENT_CB* client_cb);
299bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_nrec(tBTA_HF_CLIENT_CB* client_cb);
300bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_binp(tBTA_HF_CLIENT_CB* client_cb,
301bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                       uint32_t action);
302bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_send_at_bia(tBTA_HF_CLIENT_CB* client_cb);
303bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal
304bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal/* AT API Functions */
305bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalvoid bta_hf_client_at_init(tBTA_HF_CLIENT_CB* client_cb);
306bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalvoid bta_hf_client_at_reset(tBTA_HF_CLIENT_CB* client_cb);
307bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_ind(tBTA_HF_CLIENT_CB* client_cb,
308bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                              tBTA_HF_CLIENT_IND_TYPE type, uint16_t value);
309bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_evt_val(tBTA_HF_CLIENT_CB* client_cb,
310bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                  tBTA_HF_CLIENT_EVT type, uint16_t value);
311bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_operator_name(tBTA_HF_CLIENT_CB* client_name,
312bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                        char* name);
313bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_clip(tBTA_HF_CLIENT_CB* client_cb, char* number);
314bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_ccwa(tBTA_HF_CLIENT_CB* client_cb, char* number);
315bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_at_result(tBTA_HF_CLIENT_CB* client_cb,
316bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                    tBTA_HF_CLIENT_AT_RESULT_TYPE type,
317bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                                    uint16_t cme);
318bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_clcc(tBTA_HF_CLIENT_CB* client_cb, uint32_t idx,
319bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                               bool incoming, uint8_t status, bool mpty,
320bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                               char* number);
321bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_cnum(tBTA_HF_CLIENT_CB* client_cb, char* number,
322bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwal                               uint16_t service);
323bdcfc045f9d21afc1510cdad4fddd97a93c26477Sanket Agarwalextern void bta_hf_client_binp(tBTA_HF_CLIENT_CB* client_cb, char* number);
32441d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
32541d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* Action functions */
326cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_start_close(tBTA_HF_CLIENT_DATA* p_data);
327cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_start_open(tBTA_HF_CLIENT_DATA* p_data);
328cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_rfc_acp_open(tBTA_HF_CLIENT_DATA* p_data);
329cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_rfc_open(tBTA_HF_CLIENT_DATA* p_data);
330cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_rfc_fail(tBTA_HF_CLIENT_DATA* p_data);
331cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_disc_fail(tBTA_HF_CLIENT_DATA* p_data);
332cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_open_fail(tBTA_HF_CLIENT_DATA* p_data);
333cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_rfc_close(tBTA_HF_CLIENT_DATA* p_data);
334cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_disc_acp_res(tBTA_HF_CLIENT_DATA* p_data);
335cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_rfc_data(tBTA_HF_CLIENT_DATA* p_data);
336cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_disc_int_res(tBTA_HF_CLIENT_DATA* p_data);
337cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_svc_conn_open(tBTA_HF_CLIENT_DATA* p_data);
33841d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta
33941d4a266ceca77bb09ab1bf5c04c30d15f3ded3aHemant Gupta/* Commands handling functions */
340cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_dial(tBTA_HF_CLIENT_DATA* p_data);
341cd1fd07f1306e08fe048682dd5918987e579f937Myles Watsonextern void bta_hf_client_send_at_cmd(tBTA_HF_CLIENT_DATA* p_data);
342