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#include "gki.h"
19#include "bta_api.h"
20#include "bta_sys.h"
21#include "bta_ag_api.h"
22#include "bta_ag_co.h"
23#include "bte_appl.h"
24#include "bt_utils.h"
25
26#define LOG_TAG "BTA_AG_CO: "
27
28#ifndef LINUX_NATIVE
29#include <cutils/properties.h>
30#include <cutils/log.h>
31#else
32#include <stdio.h>
33#define LOGI(format, ...)  fprintf (stdout, LOG_TAG format"\n", ## __VA_ARGS__)
34#define LOGD(format, ...)  fprintf (stdout, LOG_TAG format"\n", ## __VA_ARGS__)
35#define LOGV(format, ...)  fprintf (stdout, LOG_TAG format"\n", ## __VA_ARGS__)
36#define LOGE(format, ...)  fprintf (stderr, LOG_TAG format"\n", ## __VA_ARGS__)
37#endif
38
39
40/************************************************************************************
41**  Externs
42************************************************************************************/
43extern int set_audio_state(UINT16 handle, UINT16 codec, UINT8 state, void *param);
44
45/*******************************************************************************
46**
47** Function         bta_ag_co_init
48**
49** Description      This callout function is executed by AG when it is
50**                  started by calling BTA_AgEnable().  This function can be
51**                  used by the phone to initialize audio paths or for other
52**                  initialization purposes.
53**
54**
55** Returns          Void.
56**
57*******************************************************************************/
58void bta_ag_co_init(void)
59{
60    BTM_WriteVoiceSettings(AG_VOICE_SETTINGS);
61}
62
63
64/*******************************************************************************
65**
66** Function         bta_ag_co_audio_state
67**
68** Description      This function is called by the AG before the audio connection
69**                  is brought up, after it comes up, and after it goes down.
70**
71** Parameters       handle - handle of the AG instance
72**                  state - Audio state
73**                      BTA_AG_CO_AUD_STATE_OFF     - Audio has been turned off
74**                      BTA_AG_CO_AUD_STATE_OFF_XFER - Audio has been turned off (xfer)
75**                      BTA_AG_CO_AUD_STATE_ON      - Audio has been turned on
76**                      BTA_AG_CO_AUD_STATE_SETUP   - Audio is about to be turned on
77**                  codec - if WBS support is compiled in, codec to going to be used is provided
78**                      and when in BTA_AG_CO_AUD_STATE_SETUP, BTM_I2SPCMConfig() must be called with
79**                      the correct platform parameters.
80**                      in the other states codec type should not be ignored
81**
82** Returns          void
83**
84*******************************************************************************/
85#if (BTM_WBS_INCLUDED == TRUE )
86void bta_ag_co_audio_state(UINT16 handle, UINT8 app_id, UINT8 state, tBTA_AG_PEER_CODEC codec)
87#else
88void bta_ag_co_audio_state(UINT16 handle, UINT8 app_id, UINT8 state)
89#endif
90{
91    BTIF_TRACE_DEBUG("bta_ag_co_audio_state: handle %d, state %d", handle, state);
92    switch (state)
93    {
94    case BTA_AG_CO_AUD_STATE_OFF:
95#if (BTM_WBS_INCLUDED == TRUE )
96        BTIF_TRACE_DEBUG("bta_ag_co_audio_state(handle %d)::Closed (OFF), codec: 0x%x",
97                        handle, codec);
98        set_audio_state(handle, codec, state, NULL);
99#else
100        BTIF_TRACE_DEBUG("bta_ag_co_audio_state(handle %d)::Closed (OFF)",
101                        handle);
102#endif
103        break;
104    case BTA_AG_CO_AUD_STATE_OFF_XFER:
105        BTIF_TRACE_DEBUG("bta_ag_co_audio_state(handle %d)::Closed (XFERRING)", handle);
106        break;
107    case BTA_AG_CO_AUD_STATE_SETUP:
108#if (BTM_WBS_INCLUDED == TRUE )
109        set_audio_state(handle, codec, state, NULL);
110#else
111        set_audio_state(handle, BTA_AG_CODEC_CVSD, state, NULL);
112#endif
113        break;
114    default:
115        break;
116    }
117#if (BTM_WBS_INCLUDED == TRUE )
118    APPL_TRACE_DEBUG("bta_ag_co_audio_state(handle %d, app_id: %d, state %d, codec: 0x%x)",
119                      handle, app_id, state, codec);
120#else
121    APPL_TRACE_DEBUG("bta_ag_co_audio_state(handle %d, app_id: %d, state %d)", \
122    handle, app_id, state);
123#endif
124}
125
126
127/*******************************************************************************
128**
129** Function         bta_ag_co_data_open
130**
131** Description      This function is executed by AG when a service level connection
132**                  is opened.  The phone can use this function to set
133**                  up data paths or perform any required initialization or
134**                  set up particular to the connected service.
135**
136**
137** Returns          void
138**
139*******************************************************************************/
140void bta_ag_co_data_open(UINT16 handle, tBTA_SERVICE_ID service)
141{
142    BTIF_TRACE_DEBUG("bta_ag_co_data_open handle:%d service:%d", handle, service);
143}
144
145/*******************************************************************************
146**
147** Function         bta_ag_co_data_close
148**
149** Description      This function is called by AG when a service level
150**                  connection is closed
151**
152**
153** Returns          void
154**
155*******************************************************************************/
156void bta_ag_co_data_close(UINT16 handle)
157{
158    BTIF_TRACE_DEBUG("bta_ag_co_data_close handle:%d", handle);
159}
160
161
162/*******************************************************************************
163 **
164 ** Function         bta_ag_co_tx_write
165 **
166 ** Description      This function is called by the AG to send data to the
167 **                  phone when the AG is configured for AT command pass-through.
168 **                  The implementation of this function must copy the data to
169 **                  the phones memory.
170 **
171 ** Returns          void
172 **
173 *******************************************************************************/
174void bta_ag_co_tx_write(UINT16 handle, UINT8 * p_data, UINT16 len)
175{
176    UNUSED(p_data);
177    BTIF_TRACE_DEBUG( "bta_ag_co_tx_write: handle: %d, len: %d", handle, len );
178}
179
180