1/******************************************************************************
2 *
3 *  Copyright (C) 2009-2012 Broadcom Corporation
4 *
5 *  Licensed under the Apache License, Version 2.0 (the "License");
6 *  you may not use this file except in compliance with the License.
7 *  You may obtain a copy of the License at:
8 *
9 *  http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 *
17 ******************************************************************************/
18
19#define LOG_TAG "bt_btif_bta_ag"
20
21#include <cutils/properties.h>
22
23#include "bta/include/bta_ag_api.h"
24#include "hci/include/hci_audio.h"
25#include "osi/include/osi.h"
26
27/*******************************************************************************
28**
29** Function         bta_ag_co_init
30**
31** Description      This callout function is executed by AG when it is
32**                  started by calling BTA_AgEnable().  This function can be
33**                  used by the phone to initialize audio paths or for other
34**                  initialization purposes.
35**
36**
37** Returns          Void.
38**
39*******************************************************************************/
40void bta_ag_co_init(void)
41{
42    BTM_WriteVoiceSettings(AG_VOICE_SETTINGS);
43}
44
45
46/*******************************************************************************
47**
48** Function         bta_ag_co_audio_state
49**
50** Description      This function is called by the AG before the audio connection
51**                  is brought up, after it comes up, and after it goes down.
52**
53** Parameters       handle - handle of the AG instance
54**                  state - Audio state
55**                  codec - if WBS support is compiled in, codec to going to be used is provided
56**                      and when in SCO_STATE_SETUP, BTM_I2SPCMConfig() must be called with
57**                      the correct platform parameters.
58**                      in the other states codec type should not be ignored
59**
60** Returns          void
61**
62*******************************************************************************/
63#if (BTM_WBS_INCLUDED == TRUE )
64void bta_ag_co_audio_state(UINT16 handle, UINT8 app_id, UINT8 state, tBTA_AG_PEER_CODEC codec)
65#else
66void bta_ag_co_audio_state(UINT16 handle, UINT8 app_id, UINT8 state)
67#endif
68{
69    BTIF_TRACE_DEBUG("bta_ag_co_audio_state: handle %d, state %d", handle, state);
70    switch (state)
71    {
72    case SCO_STATE_OFF:
73#if (BTM_WBS_INCLUDED == TRUE )
74        BTIF_TRACE_DEBUG("bta_ag_co_audio_state(handle %d)::Closed (OFF), codec: 0x%x",
75                        handle, codec);
76        set_audio_state(handle, codec, state);
77#else
78        BTIF_TRACE_DEBUG("bta_ag_co_audio_state(handle %d)::Closed (OFF)",
79                        handle);
80#endif
81        break;
82    case SCO_STATE_OFF_TRANSFER:
83        BTIF_TRACE_DEBUG("bta_ag_co_audio_state(handle %d)::Closed (XFERRING)", handle);
84        break;
85    case SCO_STATE_SETUP:
86#if (BTM_WBS_INCLUDED == TRUE )
87        set_audio_state(handle, codec, state);
88#else
89        set_audio_state(handle, BTA_AG_CODEC_CVSD, state);
90#endif
91        break;
92    default:
93        break;
94    }
95#if (BTM_WBS_INCLUDED == TRUE )
96    APPL_TRACE_DEBUG("bta_ag_co_audio_state(handle %d, app_id: %d, state %d, codec: 0x%x)",
97                      handle, app_id, state, codec);
98#else
99    APPL_TRACE_DEBUG("bta_ag_co_audio_state(handle %d, app_id: %d, state %d)", \
100    handle, app_id, state);
101#endif
102}
103
104
105/*******************************************************************************
106**
107** Function         bta_ag_co_data_open
108**
109** Description      This function is executed by AG when a service level connection
110**                  is opened.  The phone can use this function to set
111**                  up data paths or perform any required initialization or
112**                  set up particular to the connected service.
113**
114**
115** Returns          void
116**
117*******************************************************************************/
118void bta_ag_co_data_open(UINT16 handle, tBTA_SERVICE_ID service)
119{
120    BTIF_TRACE_DEBUG("bta_ag_co_data_open handle:%d service:%d", handle, service);
121}
122
123/*******************************************************************************
124**
125** Function         bta_ag_co_data_close
126**
127** Description      This function is called by AG when a service level
128**                  connection is closed
129**
130**
131** Returns          void
132**
133*******************************************************************************/
134void bta_ag_co_data_close(UINT16 handle)
135{
136    BTIF_TRACE_DEBUG("bta_ag_co_data_close handle:%d", handle);
137}
138
139
140/*******************************************************************************
141 **
142 ** Function         bta_ag_co_tx_write
143 **
144 ** Description      This function is called by the AG to send data to the
145 **                  phone when the AG is configured for AT command pass-through.
146 **                  The implementation of this function must copy the data to
147 **                  the phones memory.
148 **
149 ** Returns          void
150 **
151 *******************************************************************************/
152void bta_ag_co_tx_write(UINT16 handle, UNUSED_ATTR UINT8 * p_data, UINT16 len)
153{
154    BTIF_TRACE_DEBUG( "bta_ag_co_tx_write: handle: %d, len: %d", handle, len );
155}
156