blob: 07e0c2ce915172e96088f79afcaee3a8eda4b5ec [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
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
20/*****************************************************************************
21 *
22 * Filename: btif_rc.c
23 *
24 * Description: Bluetooth AVRC implementation
25 *
26 *****************************************************************************/
27#include <hardware/bluetooth.h>
28#include <fcntl.h>
Ian Coolidgec7503db2015-01-24 02:01:26 -080029#include <string.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080030#include "bta_api.h"
31#include "bta_av_api.h"
32#include "avrc_defs.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080033#include "gki.h"
34
Chris Mantonf8027002015-03-12 09:22:48 -070035#define LOG_TAG "bt_btif_avrc"
The Android Open Source Project5738f832012-12-12 16:00:35 -080036#include "btif_common.h"
Ravi Nagarajan9adddf42013-03-06 05:29:48 -080037#include "btif_util.h"
38#include "btif_av.h"
39#include "hardware/bt_rc.h"
40#include "uinput.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080041
42/*****************************************************************************
43** Constants & Macros
44******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080045
46/* cod value for Headsets */
47#define COD_AV_HEADSETS 0x0404
Ravi Nagarajan9adddf42013-03-06 05:29:48 -080048/* for AVRC 1.4 need to change this */
49#define MAX_RC_NOTIFICATIONS AVRC_EVT_APP_SETTING_CHANGE
The Android Open Source Project5738f832012-12-12 16:00:35 -080050
Ravi Nagarajan9adddf42013-03-06 05:29:48 -080051#define IDX_GET_PLAY_STATUS_RSP 0
52#define IDX_LIST_APP_ATTR_RSP 1
53#define IDX_LIST_APP_VALUE_RSP 2
54#define IDX_GET_CURR_APP_VAL_RSP 3
55#define IDX_SET_APP_VAL_RSP 4
56#define IDX_GET_APP_ATTR_TXT_RSP 5
57#define IDX_GET_APP_VAL_TXT_RSP 6
58#define IDX_GET_ELEMENT_ATTR_RSP 7
Satya Calloji247c68f2013-08-01 02:14:43 -070059#define MAX_VOLUME 128
60#define MAX_LABEL 16
61#define MAX_TRANSACTIONS_PER_SESSION 16
Ravi Nagarajan9adddf42013-03-06 05:29:48 -080062#define MAX_CMD_QUEUE_LEN 8
63
64#define CHECK_RC_CONNECTED \
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -070065 BTIF_TRACE_DEBUG("## %s ##", __FUNCTION__); \
Ravi Nagarajan9adddf42013-03-06 05:29:48 -080066 if(btif_rc_cb.rc_connected == FALSE) \
67 { \
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -070068 BTIF_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \
Ravi Nagarajan9adddf42013-03-06 05:29:48 -080069 return BT_STATUS_NOT_READY; \
70 }
71
72#define FILL_PDU_QUEUE(index, ctype, label, pending) \
73{ \
74 btif_rc_cb.rc_pdu_info[index].ctype = ctype; \
75 btif_rc_cb.rc_pdu_info[index].label = label; \
76 btif_rc_cb.rc_pdu_info[index].is_rsp_pending = pending; \
77}
78
79#define SEND_METAMSG_RSP(index, avrc_rsp) \
80{ \
81 if(btif_rc_cb.rc_pdu_info[index].is_rsp_pending == FALSE) \
82 { \
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -070083 BTIF_TRACE_WARNING("%s Not sending response as no PDU was registered", __FUNCTION__); \
Ravi Nagarajan9adddf42013-03-06 05:29:48 -080084 return BT_STATUS_UNHANDLED; \
85 } \
86 send_metamsg_rsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_pdu_info[index].label, \
87 btif_rc_cb.rc_pdu_info[index].ctype, avrc_rsp); \
88 btif_rc_cb.rc_pdu_info[index].ctype = 0; \
89 btif_rc_cb.rc_pdu_info[index].label = 0; \
90 btif_rc_cb.rc_pdu_info[index].is_rsp_pending = FALSE; \
91}
The Android Open Source Project5738f832012-12-12 16:00:35 -080092
93/*****************************************************************************
94** Local type definitions
95******************************************************************************/
96typedef struct {
Ravi Nagarajan9adddf42013-03-06 05:29:48 -080097 UINT8 bNotify;
98 UINT8 label;
99} btif_rc_reg_notifications_t;
100
101typedef struct
102{
103 UINT8 label;
104 UINT8 ctype;
105 BOOLEAN is_rsp_pending;
106} btif_rc_cmd_ctxt_t;
107
108/* TODO : Merge btif_rc_reg_notifications_t and btif_rc_cmd_ctxt_t to a single struct */
109typedef struct {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800110 BOOLEAN rc_connected;
111 UINT8 rc_handle;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800112 tBTA_AV_FEAT rc_features;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800113 BD_ADDR rc_addr;
114 UINT16 rc_pending_play;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800115 btif_rc_cmd_ctxt_t rc_pdu_info[MAX_CMD_QUEUE_LEN];
116 btif_rc_reg_notifications_t rc_notif[MAX_RC_NOTIFICATIONS];
Satya Calloji247c68f2013-08-01 02:14:43 -0700117 unsigned int rc_volume;
118 uint8_t rc_vol_label;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800119} btif_rc_cb_t;
120
Satya Calloji247c68f2013-08-01 02:14:43 -0700121typedef struct {
122 BOOLEAN in_use;
123 UINT8 lbl;
124 UINT8 handle;
125} rc_transaction_t;
126
127typedef struct
128{
129 pthread_mutex_t lbllock;
130 rc_transaction_t transaction[MAX_TRANSACTIONS_PER_SESSION];
131} rc_device_t;
132
133
134rc_device_t device;
135
The Android Open Source Project5738f832012-12-12 16:00:35 -0800136#define MAX_UINPUT_PATHS 3
137static const char* uinput_dev_path[] =
138 {"/dev/uinput", "/dev/input/uinput", "/dev/misc/uinput" };
139static int uinput_fd = -1;
140
141static int send_event (int fd, uint16_t type, uint16_t code, int32_t value);
142static void send_key (int fd, uint16_t key, int pressed);
143static int uinput_driver_check();
144static int uinput_create(char *name);
145static int init_uinput (void);
146static void close_uinput (void);
Matthew Xiea7ae4a12013-10-24 01:09:52 -0700147static BOOLEAN dev_blacklisted_for_absolute_volume(BD_ADDR peer_dev);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800148
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800149static const struct {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800150 const char *name;
151 uint8_t avrcp;
152 uint16_t mapped_id;
153 uint8_t release_quirk;
154} key_map[] = {
155 { "PLAY", AVRC_ID_PLAY, KEY_PLAYCD, 1 },
156 { "STOP", AVRC_ID_STOP, KEY_STOPCD, 0 },
157 { "PAUSE", AVRC_ID_PAUSE, KEY_PAUSECD, 1 },
158 { "FORWARD", AVRC_ID_FORWARD, KEY_NEXTSONG, 0 },
159 { "BACKWARD", AVRC_ID_BACKWARD, KEY_PREVIOUSSONG, 0 },
160 { "REWIND", AVRC_ID_REWIND, KEY_REWIND, 0 },
John Du98497a52013-06-24 19:18:56 -0700161 { "FAST FORWARD", AVRC_ID_FAST_FOR, KEY_FAST_FORWARD, 0 },
The Android Open Source Project5738f832012-12-12 16:00:35 -0800162 { NULL, 0, 0, 0 }
163};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800164
Matthew Xie7850a932013-11-05 17:19:39 -0800165/* the rc_black_addr_prefix and rc_white_addr_prefix are used to correct
166 * IOP issues of absolute volume feature
167 * We encoutered A2DP headsets/carkits advertising absolute volume but buggy.
168 * We would like to blacklist those devices.
169 * But we donot have a full list of the bad devices. So as a temp fix, we
170 * are blacklisting all the devices except the devices we have well tested,
171 * the ones in the whitelist.
172 *
173 * For now, only the rc_white_addr_prefix is used in the code while
174 * rc_black_addr_prefix is kept here for future long term solution.
175 */
Matthew Xie7850a932013-11-05 17:19:39 -0800176static const UINT8 rc_white_addr_prefix[][3] = {
177 {0x94, 0xCE, 0x2C}, // Sony SBH50
Thomas.TT_Linc9fbcde2014-04-07 16:13:06 +0800178 {0x30, 0x17, 0xC8} // Sony wm600
179};
180
181static const char* rc_white_name[] = {
182 "SBH50",
183 "MW600"
Matthew Xie7850a932013-11-05 17:19:39 -0800184};
185
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800186static void send_reject_response (UINT8 rc_handle, UINT8 label,
187 UINT8 pdu, UINT8 status);
188static UINT8 opcode_from_pdu(UINT8 pdu);
189static void send_metamsg_rsp (UINT8 rc_handle, UINT8 label,
190 tBTA_AV_CODE code, tAVRC_RESPONSE *pmetamsg_resp);
Satya Calloji247c68f2013-08-01 02:14:43 -0700191static void register_volumechange(UINT8 label);
192static void lbl_init();
193static void lbl_destroy();
194static void init_all_transactions();
195static bt_status_t get_transaction(rc_transaction_t **ptransaction);
196static void release_transaction(UINT8 label);
197static rc_transaction_t* get_transaction_by_lbl(UINT8 label);
198static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800199static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND* p_param, UINT8 ctype, UINT8 label);
Satya Calloji247c68f2013-08-01 02:14:43 -0700200static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800201
202/*****************************************************************************
203** Static variables
204******************************************************************************/
205static btif_rc_cb_t btif_rc_cb;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800206static btrc_callbacks_t *bt_rc_callbacks = NULL;
Mike Lockwood4ad470e2014-06-02 16:21:49 -0700207static btrc_ctrl_callbacks_t *bt_rc_ctrl_callbacks = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800208
209/*****************************************************************************
210** Static functions
211******************************************************************************/
212
213/*****************************************************************************
214** Externs
215******************************************************************************/
216extern BOOLEAN btif_hf_call_terminated_recently();
217extern BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800218
The Android Open Source Project5738f832012-12-12 16:00:35 -0800219
220/*****************************************************************************
221** Functions
222******************************************************************************/
223
The Android Open Source Project5738f832012-12-12 16:00:35 -0800224/*****************************************************************************
225** Local uinput helper functions
226******************************************************************************/
227int send_event (int fd, uint16_t type, uint16_t code, int32_t value)
228{
229 struct uinput_event event;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700230 BTIF_TRACE_DEBUG("%s type:%u code:%u value:%d", __FUNCTION__,
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800231 type, code, value);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800232 memset(&event, 0, sizeof(event));
233 event.type = type;
234 event.code = code;
235 event.value = value;
236
237 return write(fd, &event, sizeof(event));
238}
239
240void send_key (int fd, uint16_t key, int pressed)
241{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700242 BTIF_TRACE_DEBUG("%s fd:%d key:%u pressed:%d", __FUNCTION__,
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800243 fd, key, pressed);
244
245 if (fd < 0)
246 {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800247 return;
248 }
249
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700250 BTIF_TRACE_DEBUG("AVRCP: Send key %d (%d) fd=%d", key, pressed, fd);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800251 send_event(fd, EV_KEY, key, pressed);
252 send_event(fd, EV_SYN, SYN_REPORT, 0);
253}
254
255/************** uinput related functions **************/
256int uinput_driver_check()
257{
258 uint32_t i;
259 for (i=0; i < MAX_UINPUT_PATHS; i++)
260 {
261 if (access(uinput_dev_path[i], O_RDWR) == 0) {
262 return 0;
263 }
264 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700265 BTIF_TRACE_ERROR("%s ERROR: uinput device is not in the system", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800266 return -1;
267}
268
269int uinput_create(char *name)
270{
271 struct uinput_dev dev;
Bernhard Rosenkränzer104e3f22014-11-12 21:53:08 +0100272 int fd, x = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800273
274 for(x=0; x < MAX_UINPUT_PATHS; x++)
275 {
276 fd = open(uinput_dev_path[x], O_RDWR);
277 if (fd < 0)
278 continue;
279 break;
280 }
281 if (x == MAX_UINPUT_PATHS) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700282 BTIF_TRACE_ERROR("%s ERROR: uinput device open failed", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800283 return -1;
284 }
285 memset(&dev, 0, sizeof(dev));
286 if (name)
VenkatRaghavan VijayaRaghavan4540f592015-02-05 04:40:47 -0800287 strncpy(dev.name, name, UINPUT_MAX_NAME_SIZE-1);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800288
289 dev.id.bustype = BUS_BLUETOOTH;
290 dev.id.vendor = 0x0000;
291 dev.id.product = 0x0000;
292 dev.id.version = 0x0000;
293
294 if (write(fd, &dev, sizeof(dev)) < 0) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700295 BTIF_TRACE_ERROR("%s Unable to write device information", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800296 close(fd);
297 return -1;
298 }
299
300 ioctl(fd, UI_SET_EVBIT, EV_KEY);
301 ioctl(fd, UI_SET_EVBIT, EV_REL);
302 ioctl(fd, UI_SET_EVBIT, EV_SYN);
303
304 for (x = 0; key_map[x].name != NULL; x++)
305 ioctl(fd, UI_SET_KEYBIT, key_map[x].mapped_id);
306
307 for(x = 0; x < KEY_MAX; x++)
308 ioctl(fd, UI_SET_KEYBIT, x);
309
310 if (ioctl(fd, UI_DEV_CREATE, NULL) < 0) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700311 BTIF_TRACE_ERROR("%s Unable to create uinput device", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800312 close(fd);
313 return -1;
314 }
315 return fd;
316}
317
318int init_uinput (void)
319{
320 char *name = "AVRCP";
321
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700322 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800323 uinput_fd = uinput_create(name);
324 if (uinput_fd < 0) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700325 BTIF_TRACE_ERROR("%s AVRCP: Failed to initialize uinput for %s (%d)",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800326 __FUNCTION__, name, uinput_fd);
327 } else {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700328 BTIF_TRACE_DEBUG("%s AVRCP: Initialized uinput for %s (fd=%d)",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800329 __FUNCTION__, name, uinput_fd);
330 }
331 return uinput_fd;
332}
333
334void close_uinput (void)
335{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700336 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800337 if (uinput_fd > 0) {
338 ioctl(uinput_fd, UI_DEV_DESTROY);
339
340 close(uinput_fd);
341 uinput_fd = -1;
342 }
343}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800344
Satya Calloji247c68f2013-08-01 02:14:43 -0700345void handle_rc_features()
346{
347 btrc_remote_features_t rc_features = BTRC_FEAT_NONE;
348 bt_bdaddr_t rc_addr;
349 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800350
Matthew Xiea7ae4a12013-10-24 01:09:52 -0700351 if (dev_blacklisted_for_absolute_volume(btif_rc_cb.rc_addr))
352 {
353 btif_rc_cb.rc_features &= ~BTA_AV_FEAT_ADV_CTRL;
354 }
355
Satya Calloji247c68f2013-08-01 02:14:43 -0700356 if (btif_rc_cb.rc_features & BTA_AV_FEAT_BROWSE)
357 {
358 rc_features |= BTRC_FEAT_BROWSE;
359 }
360 if ( (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL) &&
361 (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG))
362 {
363 rc_features |= BTRC_FEAT_ABSOLUTE_VOLUME;
364 }
365 if (btif_rc_cb.rc_features & BTA_AV_FEAT_METADATA)
366 {
367 rc_features |= BTRC_FEAT_METADATA;
368 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700369 BTIF_TRACE_DEBUG("%s: rc_features=0x%x", __FUNCTION__, rc_features);
Satya Calloji247c68f2013-08-01 02:14:43 -0700370 HAL_CBACK(bt_rc_callbacks, remote_features_cb, &rc_addr, rc_features)
371
372#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700373 BTIF_TRACE_DEBUG("Checking for feature flags in btif_rc_handler with label %d",
Satya Calloji247c68f2013-08-01 02:14:43 -0700374 btif_rc_cb.rc_vol_label);
375 // Register for volume change on connect
376 if(btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL &&
377 btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
378 {
379 rc_transaction_t *p_transaction=NULL;
380 bt_status_t status = BT_STATUS_NOT_READY;
381 if(MAX_LABEL==btif_rc_cb.rc_vol_label)
382 {
383 status=get_transaction(&p_transaction);
384 }
385 else
386 {
387 p_transaction=get_transaction_by_lbl(btif_rc_cb.rc_vol_label);
388 if(NULL!=p_transaction)
389 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700390 BTIF_TRACE_DEBUG("register_volumechange already in progress for label %d",
Satya Calloji247c68f2013-08-01 02:14:43 -0700391 btif_rc_cb.rc_vol_label);
392 return;
393 }
394 else
395 status=get_transaction(&p_transaction);
396 }
397
398 if(BT_STATUS_SUCCESS == status && NULL!=p_transaction)
399 {
400 btif_rc_cb.rc_vol_label=p_transaction->lbl;
401 register_volumechange(btif_rc_cb.rc_vol_label);
402 }
403 }
404#endif
405}
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800406
The Android Open Source Project5738f832012-12-12 16:00:35 -0800407
408/***************************************************************************
409 * Function handle_rc_connect
410 *
John Du98497a52013-06-24 19:18:56 -0700411 * - Argument: tBTA_AV_RC_OPEN RC open data structure
The Android Open Source Project5738f832012-12-12 16:00:35 -0800412 *
413 * - Description: RC connection event handler
414 *
415 ***************************************************************************/
416void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open)
417{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700418 BTIF_TRACE_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_open->rc_handle);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800419 bt_status_t result = BT_STATUS_SUCCESS;
Mike Lockwood93912472014-06-26 11:08:24 -0700420#if (AVRC_CTLR_INCLUDED == TRUE)
421 bt_bdaddr_t rc_addr;
422#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800423
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800424 if(p_rc_open->status == BTA_AV_SUCCESS)
425 {
426 memcpy(btif_rc_cb.rc_addr, p_rc_open->peer_addr, sizeof(BD_ADDR));
427 btif_rc_cb.rc_features = p_rc_open->peer_features;
Satya Calloji247c68f2013-08-01 02:14:43 -0700428 btif_rc_cb.rc_vol_label=MAX_LABEL;
429 btif_rc_cb.rc_volume=MAX_VOLUME;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800430
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800431 btif_rc_cb.rc_connected = TRUE;
432 btif_rc_cb.rc_handle = p_rc_open->rc_handle;
433
Satya Calloji247c68f2013-08-01 02:14:43 -0700434 /* on locally initiated connection we will get remote features as part of connect */
435 if (btif_rc_cb.rc_features != 0)
436 handle_rc_features();
437
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800438 result = uinput_driver_check();
439 if(result == BT_STATUS_SUCCESS)
440 {
441 init_uinput();
442 }
Mike Lockwood4ad470e2014-06-02 16:21:49 -0700443#if (AVRC_CTLR_INCLUDED == TRUE)
444 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
445 /* report connection state if device is AVRCP target */
446 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG) {
447 HAL_CBACK(bt_rc_ctrl_callbacks, connection_state_cb, TRUE, &rc_addr);
448 }
449#endif
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800450 }
451 else
452 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700453 BTIF_TRACE_ERROR("%s Connect failed with error code: %d",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800454 __FUNCTION__, p_rc_open->status);
455 btif_rc_cb.rc_connected = FALSE;
456 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800457}
458
459/***************************************************************************
460 * Function handle_rc_disconnect
461 *
John Du98497a52013-06-24 19:18:56 -0700462 * - Argument: tBTA_AV_RC_CLOSE RC close data structure
The Android Open Source Project5738f832012-12-12 16:00:35 -0800463 *
464 * - Description: RC disconnection event handler
465 *
466 ***************************************************************************/
467void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close)
468{
Mike Lockwood4ad470e2014-06-02 16:21:49 -0700469#if (AVRC_CTLR_INCLUDED == TRUE)
470 bt_bdaddr_t rc_addr;
471 tBTA_AV_FEAT features;
472#endif
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700473 BTIF_TRACE_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_close->rc_handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800474
475 btif_rc_cb.rc_handle = 0;
476 btif_rc_cb.rc_connected = FALSE;
477 memset(btif_rc_cb.rc_addr, 0, sizeof(BD_ADDR));
Nitin Srivastava68c53de2014-02-13 19:31:40 +0530478 memset(btif_rc_cb.rc_notif, 0, sizeof(btif_rc_cb.rc_notif));
Mike Lockwood4ad470e2014-06-02 16:21:49 -0700479#if (AVRC_CTLR_INCLUDED == TRUE)
480 features = btif_rc_cb.rc_features;
481#endif
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800482 btif_rc_cb.rc_features = 0;
Satya Calloji247c68f2013-08-01 02:14:43 -0700483 btif_rc_cb.rc_vol_label=MAX_LABEL;
484 btif_rc_cb.rc_volume=MAX_VOLUME;
485 init_all_transactions();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800486 close_uinput();
Mike Lockwood4ad470e2014-06-02 16:21:49 -0700487#if (AVRC_CTLR_INCLUDED == TRUE)
488 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
489#endif
490 memset(btif_rc_cb.rc_addr, 0, sizeof(BD_ADDR));
491#if (AVRC_CTLR_INCLUDED == TRUE)
492 /* report connection state if device is AVRCP target */
493 if (features & BTA_AV_FEAT_RCTG) {
494 HAL_CBACK(bt_rc_ctrl_callbacks, connection_state_cb, FALSE, &rc_addr);
495 }
496#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800497}
498
499/***************************************************************************
500 * Function handle_rc_passthrough_cmd
501 *
502 * - Argument: tBTA_AV_RC rc_id remote control command ID
503 * tBTA_AV_STATE key_state status of key press
504 *
505 * - Description: Remote control command handler
506 *
507 ***************************************************************************/
508void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd)
509{
510 const char *status;
511 int pressed, i;
512
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700513 BTIF_TRACE_DEBUG("%s: p_remote_cmd->rc_id=%d", __FUNCTION__, p_remote_cmd->rc_id);
John Du98497a52013-06-24 19:18:56 -0700514
The Android Open Source Project5738f832012-12-12 16:00:35 -0800515 /* If AVRC is open and peer sends PLAY but there is no AVDT, then we queue-up this PLAY */
516 if (p_remote_cmd)
517 {
518 /* queue AVRC PLAY if GAVDTP Open notification to app is pending (2 second timer) */
519 if ((p_remote_cmd->rc_id == BTA_AV_RC_PLAY) && (!btif_av_is_connected()))
520 {
521 if (p_remote_cmd->key_state == AVRC_STATE_PRESS)
522 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700523 APPL_TRACE_WARNING("%s: AVDT not open, queuing the PLAY command", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800524 btif_rc_cb.rc_pending_play = TRUE;
525 }
526 return;
527 }
528
529 if ((p_remote_cmd->rc_id == BTA_AV_RC_PAUSE) && (btif_rc_cb.rc_pending_play))
530 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700531 APPL_TRACE_WARNING("%s: Clear the pending PLAY on PAUSE received", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800532 btif_rc_cb.rc_pending_play = FALSE;
533 return;
534 }
535 }
536 if (p_remote_cmd->key_state == AVRC_STATE_RELEASE) {
537 status = "released";
538 pressed = 0;
539 } else {
540 status = "pressed";
541 pressed = 1;
542 }
543
544 /* If this is Play/Pause command (press or release) before processing, check the following
545 * a voice call has ended recently
546 * the remote device is not of type headset
547 * If the above conditions meet, drop the Play/Pause command
548 * This fix is to interop with certain carkits which sends an automatic PLAY or PAUSE
549 * commands right after call ends
550 */
551 if((p_remote_cmd->rc_id == BTA_AV_RC_PLAY || p_remote_cmd->rc_id == BTA_AV_RC_PAUSE)&&
552 (btif_hf_call_terminated_recently() == TRUE) &&
553 (check_cod( (const bt_bdaddr_t*)&(btif_rc_cb.rc_addr), COD_AV_HEADSETS) != TRUE))
554 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700555 BTIF_TRACE_DEBUG("%s:Dropping the play/Pause command received right after call end cmd:%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800556 __FUNCTION__,p_remote_cmd->rc_id);
557 return;
558 }
559
John Du98497a52013-06-24 19:18:56 -0700560 if (p_remote_cmd->rc_id == BTA_AV_RC_FAST_FOR || p_remote_cmd->rc_id == BTA_AV_RC_REWIND) {
561 HAL_CBACK(bt_rc_callbacks, passthrough_cmd_cb, p_remote_cmd->rc_id, pressed);
562 return;
563 }
564
The Android Open Source Project5738f832012-12-12 16:00:35 -0800565 for (i = 0; key_map[i].name != NULL; i++) {
566 if (p_remote_cmd->rc_id == key_map[i].avrcp) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700567 BTIF_TRACE_DEBUG("%s: %s %s", __FUNCTION__, key_map[i].name, status);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800568
569 /* MusicPlayer uses a long_press_timeout of 1 second for PLAYPAUSE button
570 * and maps that to autoshuffle. So if for some reason release for PLAY/PAUSE
571 * comes 1 second after the press, the MediaPlayer UI goes into a bad state.
572 * The reason for the delay could be sniff mode exit or some AVDTP procedure etc.
573 * The fix is to generate a release right after the press and drown the 'actual'
574 * release.
575 */
576 if ((key_map[i].release_quirk == 1) && (pressed == 0))
577 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700578 BTIF_TRACE_DEBUG("%s: AVRC %s Release Faked earlier, drowned now",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800579 __FUNCTION__, key_map[i].name);
580 return;
581 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800582 send_key(uinput_fd, key_map[i].mapped_id, pressed);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800583 if ((key_map[i].release_quirk == 1) && (pressed == 1))
584 {
585 GKI_delay(30); // 30ms
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700586 BTIF_TRACE_DEBUG("%s: AVRC %s Release quirk enabled, send release now",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800587 __FUNCTION__, key_map[i].name);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800588 send_key(uinput_fd, key_map[i].mapped_id, 0);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800589 }
590 break;
591 }
592 }
593
594 if (key_map[i].name == NULL)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700595 BTIF_TRACE_ERROR("%s AVRCP: unknown button 0x%02X %s", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800596 p_remote_cmd->rc_id, status);
597}
598
Mike Lockwood4ad470e2014-06-02 16:21:49 -0700599/***************************************************************************
600 * Function handle_rc_passthrough_rsp
601 *
602 * - Argument: tBTA_AV_REMOTE_RSP passthrough command response
603 *
604 * - Description: Remote control passthrough response handler
605 *
606 ***************************************************************************/
607void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp)
608{
609#if (AVRC_CTLR_INCLUDED == TRUE)
610 const char *status;
611 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
612 {
613 int key_state;
614 if (p_remote_rsp->key_state == AVRC_STATE_RELEASE)
615 {
616 status = "released";
617 key_state = 1;
618 }
619 else
620 {
621 status = "pressed";
622 key_state = 0;
623 }
624
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700625 BTIF_TRACE_DEBUG("%s: rc_id=%d status=%s", __FUNCTION__, p_remote_rsp->rc_id, status);
Mike Lockwood4ad470e2014-06-02 16:21:49 -0700626
627 release_transaction(p_remote_rsp->label);
628 HAL_CBACK(bt_rc_ctrl_callbacks, passthrough_rsp_cb, p_remote_rsp->rc_id, key_state);
629 }
630 else
631 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700632 BTIF_TRACE_ERROR("%s DUT does not support AVRCP controller role", __FUNCTION__);
Mike Lockwood4ad470e2014-06-02 16:21:49 -0700633 }
634#else
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700635 BTIF_TRACE_ERROR("%s AVRCP controller role is not enabled", __FUNCTION__);
Mike Lockwood4ad470e2014-06-02 16:21:49 -0700636#endif
637}
638
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800639void handle_uid_changed_notification(tBTA_AV_META_MSG *pmeta_msg, tAVRC_COMMAND *pavrc_command)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800640{
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800641 tAVRC_RESPONSE avrc_rsp = {0};
642 avrc_rsp.rsp.pdu = pavrc_command->pdu;
643 avrc_rsp.rsp.status = AVRC_STS_NO_ERROR;
644 avrc_rsp.rsp.opcode = pavrc_command->cmd.opcode;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800645
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800646 avrc_rsp.reg_notif.event_id = pavrc_command->reg_notif.event_id;
647 avrc_rsp.reg_notif.param.uid_counter = 0;
648
649 send_metamsg_rsp(pmeta_msg->rc_handle, pmeta_msg->label, AVRC_RSP_INTERIM, &avrc_rsp);
650 send_metamsg_rsp(pmeta_msg->rc_handle, pmeta_msg->label, AVRC_RSP_CHANGED, &avrc_rsp);
651
652}
653
654
655/***************************************************************************
656 * Function handle_rc_metamsg_cmd
657 *
658 * - Argument: tBTA_AV_VENDOR Structure containing the received
659 * metamsg command
660 *
661 * - Description: Remote control metamsg command handler (AVRCP 1.3)
662 *
663 ***************************************************************************/
664void handle_rc_metamsg_cmd (tBTA_AV_META_MSG *pmeta_msg)
665{
666 /* Parse the metamsg command and pass it on to BTL-IFS */
667 UINT8 scratch_buf[512] = {0};
668 tAVRC_COMMAND avrc_command = {0};
669 tAVRC_STS status;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800670
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700671 BTIF_TRACE_EVENT("+ %s", __FUNCTION__);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800672
673 if (pmeta_msg->p_msg->hdr.opcode != AVRC_OP_VENDOR)
674 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700675 BTIF_TRACE_WARNING("Invalid opcode: %x", pmeta_msg->p_msg->hdr.opcode);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800676 return;
677 }
678 if (pmeta_msg->len < 3)
679 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700680 BTIF_TRACE_WARNING("Invalid length.Opcode: 0x%x, len: 0x%x", pmeta_msg->p_msg->hdr.opcode,
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800681 pmeta_msg->len);
682 return;
683 }
684
685 if (pmeta_msg->code >= AVRC_RSP_NOT_IMPL)
686 {
Satya Calloji247c68f2013-08-01 02:14:43 -0700687#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
688{
689 rc_transaction_t *transaction=NULL;
690 transaction=get_transaction_by_lbl(pmeta_msg->label);
691 if(NULL!=transaction)
692 {
693 handle_rc_metamsg_rsp(pmeta_msg);
694 }
695 else
696 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700697 BTIF_TRACE_DEBUG("%s:Discard vendor dependent rsp. code: %d label:%d.",
Satya Calloji247c68f2013-08-01 02:14:43 -0700698 __FUNCTION__, pmeta_msg->code, pmeta_msg->label);
699 }
700 return;
701}
702#else
703{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700704 BTIF_TRACE_DEBUG("%s:Received vendor dependent rsp. code: %d len: %d. Not processing it.",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800705 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
706 return;
Satya Calloji247c68f2013-08-01 02:14:43 -0700707}
708#endif
709 }
710
711 status=AVRC_ParsCommand(pmeta_msg->p_msg, &avrc_command, scratch_buf, sizeof(scratch_buf));
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700712 BTIF_TRACE_DEBUG("Received vendor command.code,PDU and label: %d, %d,%d",pmeta_msg->code,
Satya Calloji247c68f2013-08-01 02:14:43 -0700713 avrc_command.cmd.pdu, pmeta_msg->label);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800714
715 if (status != AVRC_STS_NO_ERROR)
716 {
717 /* return error */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700718 BTIF_TRACE_WARNING("%s: Error in parsing received metamsg command. status: 0x%02x",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800719 __FUNCTION__, status);
720 send_reject_response(pmeta_msg->rc_handle, pmeta_msg->label, avrc_command.pdu, status);
721 }
722 else
723 {
724 /* if RegisterNotification, add it to our registered queue */
725
726 if (avrc_command.cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION)
727 {
728 UINT8 event_id = avrc_command.reg_notif.event_id;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700729 BTIF_TRACE_EVENT("%s:New register notification received.event_id:%s,label:0x%x,code:%x",
Satya Calloji247c68f2013-08-01 02:14:43 -0700730 __FUNCTION__,dump_rc_notification_event_id(event_id), pmeta_msg->label,pmeta_msg->code);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800731 btif_rc_cb.rc_notif[event_id-1].bNotify = TRUE;
732 btif_rc_cb.rc_notif[event_id-1].label = pmeta_msg->label;
733
734 if(event_id == AVRC_EVT_UIDS_CHANGE)
735 {
736 handle_uid_changed_notification(pmeta_msg, &avrc_command);
737 return;
738 }
739
740 }
741
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700742 BTIF_TRACE_EVENT("%s: Passing received metamsg command to app. pdu: %s",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800743 __FUNCTION__, dump_rc_pdu(avrc_command.cmd.pdu));
744
745 /* Since handle_rc_metamsg_cmd() itself is called from
746 *btif context, no context switching is required. Invoke
747 * btif_rc_upstreams_evt directly from here. */
748 btif_rc_upstreams_evt((uint16_t)avrc_command.cmd.pdu, &avrc_command, pmeta_msg->code,
Satya Calloji247c68f2013-08-01 02:14:43 -0700749 pmeta_msg->label);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800750 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800751}
752
753/***************************************************************************
754 **
755 ** Function btif_rc_handler
756 **
757 ** Description RC event handler
758 **
759 ***************************************************************************/
760void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data)
761{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700762 BTIF_TRACE_DEBUG ("%s event:%s", __FUNCTION__, dump_rc_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800763 switch (event)
764 {
765 case BTA_AV_RC_OPEN_EVT:
766 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700767 BTIF_TRACE_DEBUG("Peer_features:%x", p_data->rc_open.peer_features);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800768 handle_rc_connect( &(p_data->rc_open) );
769 }break;
770
771 case BTA_AV_RC_CLOSE_EVT:
772 {
773 handle_rc_disconnect( &(p_data->rc_close) );
774 }break;
775
776 case BTA_AV_REMOTE_CMD_EVT:
777 {
Matthew Xieafa6e1a2014-06-28 11:35:29 -0700778 BTIF_TRACE_DEBUG("rc_id:0x%x key_state:%d", p_data->remote_cmd.rc_id,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800779 p_data->remote_cmd.key_state);
780 handle_rc_passthrough_cmd( (&p_data->remote_cmd) );
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800781 }
782 break;
Mike Lockwood93912472014-06-26 11:08:24 -0700783#if (AVRC_CTLR_INCLUDED == TRUE)
784 case BTA_AV_REMOTE_RSP_EVT:
785 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700786 BTIF_TRACE_DEBUG("RSP: rc_id:0x%x key_state:%d", p_data->remote_rsp.rc_id,
Mike Lockwood93912472014-06-26 11:08:24 -0700787 p_data->remote_rsp.key_state);
788 handle_rc_passthrough_rsp( (&p_data->remote_rsp) );
789 }
790 break;
791#endif
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800792 case BTA_AV_RC_FEAT_EVT:
793 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700794 BTIF_TRACE_DEBUG("Peer_features:%x", p_data->rc_feat.peer_features);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800795 btif_rc_cb.rc_features = p_data->rc_feat.peer_features;
Satya Calloji247c68f2013-08-01 02:14:43 -0700796 handle_rc_features();
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800797 }
798 break;
799 case BTA_AV_META_MSG_EVT:
800 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700801 BTIF_TRACE_DEBUG("BTA_AV_META_MSG_EVT code:%d label:%d", p_data->meta_msg.code,
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800802 p_data->meta_msg.label);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700803 BTIF_TRACE_DEBUG(" company_id:0x%x len:%d handle:%d", p_data->meta_msg.company_id,
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800804 p_data->meta_msg.len, p_data->meta_msg.rc_handle);
805 /* handle the metamsg command */
806 handle_rc_metamsg_cmd(&(p_data->meta_msg));
807 }
808 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800809 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700810 BTIF_TRACE_DEBUG("Unhandled RC event : 0x%x", event);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800811 }
812}
813
814/***************************************************************************
815 **
816 ** Function btif_rc_get_connected_peer
817 **
818 ** Description Fetches the connected headset's BD_ADDR if any
819 **
820 ***************************************************************************/
821BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr)
822{
823 if (btif_rc_cb.rc_connected == TRUE) {
824 bdcpy(peer_addr, btif_rc_cb.rc_addr);
825 return TRUE;
826 }
827 return FALSE;
828}
829
830/***************************************************************************
831 **
832 ** Function btif_rc_check_handle_pending_play
833 **
834 ** Description Clears the queued PLAY command. if bSend is TRUE, forwards to app
835 **
836 ***************************************************************************/
837
838/* clear the queued PLAY command. if bSend is TRUE, forward to app */
839void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp)
840{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800841 UNUSED(peer_addr);
842
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700843 BTIF_TRACE_DEBUG("%s: bSendToApp=%d", __FUNCTION__, bSendToApp);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800844 if (btif_rc_cb.rc_pending_play)
845 {
846 if (bSendToApp)
847 {
848 tBTA_AV_REMOTE_CMD remote_cmd;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700849 APPL_TRACE_DEBUG("%s: Sending queued PLAYED event to app", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800850
851 memset (&remote_cmd, 0, sizeof(tBTA_AV_REMOTE_CMD));
852 remote_cmd.rc_handle = btif_rc_cb.rc_handle;
853 remote_cmd.rc_id = AVRC_ID_PLAY;
854 remote_cmd.hdr.ctype = AVRC_CMD_CTRL;
855 remote_cmd.hdr.opcode = AVRC_OP_PASS_THRU;
856
857 /* delay sending to app, else there is a timing issue in the framework,
858 ** which causes the audio to be on th device's speaker. Delay between
859 ** OPEN & RC_PLAYs
860 */
861 GKI_delay (200);
862 /* send to app - both PRESSED & RELEASED */
863 remote_cmd.key_state = AVRC_STATE_PRESS;
864 handle_rc_passthrough_cmd( &remote_cmd );
865
866 GKI_delay (100);
867
868 remote_cmd.key_state = AVRC_STATE_RELEASE;
869 handle_rc_passthrough_cmd( &remote_cmd );
870 }
871 btif_rc_cb.rc_pending_play = FALSE;
872 }
873}
874
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800875/* Generic reject response */
876static void send_reject_response (UINT8 rc_handle, UINT8 label, UINT8 pdu, UINT8 status)
877{
878 UINT8 ctype = AVRC_RSP_REJ;
879 tAVRC_RESPONSE avrc_rsp;
880 BT_HDR *p_msg = NULL;
881 memset (&avrc_rsp, 0, sizeof(tAVRC_RESPONSE));
882
883 avrc_rsp.rsp.opcode = opcode_from_pdu(pdu);
884 avrc_rsp.rsp.pdu = pdu;
885 avrc_rsp.rsp.status = status;
886
887 if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(rc_handle, &avrc_rsp, &p_msg)) )
888 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700889 BTIF_TRACE_DEBUG("%s:Sending error notification to handle:%d. pdu:%s,status:0x%02x",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800890 __FUNCTION__, rc_handle, dump_rc_pdu(pdu), status);
891 BTA_AvMetaRsp(rc_handle, label, ctype, p_msg);
892 }
893}
894
895/***************************************************************************
896 * Function send_metamsg_rsp
897 *
898 * - Argument:
899 * rc_handle RC handle corresponding to the connected RC
900 * label Label of the RC response
901 * code Response type
902 * pmetamsg_resp Vendor response
903 *
904 * - Description: Remote control metamsg response handler (AVRCP 1.3)
905 *
906 ***************************************************************************/
907static void send_metamsg_rsp (UINT8 rc_handle, UINT8 label, tBTA_AV_CODE code,
908 tAVRC_RESPONSE *pmetamsg_resp)
909{
910 UINT8 ctype;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800911
912 if (!pmetamsg_resp)
913 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700914 BTIF_TRACE_WARNING("%s: Invalid response received from application", __FUNCTION__);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800915 return;
916 }
917
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700918 BTIF_TRACE_EVENT("+%s: rc_handle: %d, label: %d, code: 0x%02x, pdu: %s", __FUNCTION__,
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800919 rc_handle, label, code, dump_rc_pdu(pmetamsg_resp->rsp.pdu));
920
921 if (pmetamsg_resp->rsp.status != AVRC_STS_NO_ERROR)
922 {
923 ctype = AVRC_RSP_REJ;
924 }
925 else
926 {
927 if ( code < AVRC_RSP_NOT_IMPL)
928 {
929 if (code == AVRC_CMD_NOTIF)
930 {
931 ctype = AVRC_RSP_INTERIM;
932 }
933 else if (code == AVRC_CMD_STATUS)
934 {
935 ctype = AVRC_RSP_IMPL_STBL;
936 }
937 else
938 {
939 ctype = AVRC_RSP_ACCEPT;
940 }
941 }
942 else
943 {
944 ctype = code;
945 }
946 }
947 /* if response is for register_notification, make sure the rc has
948 actually registered for this */
949 if((pmetamsg_resp->rsp.pdu == AVRC_PDU_REGISTER_NOTIFICATION) && (code == AVRC_RSP_CHANGED))
950 {
951 BOOLEAN bSent = FALSE;
952 UINT8 event_id = pmetamsg_resp->reg_notif.event_id;
953 BOOLEAN bNotify = (btif_rc_cb.rc_connected) && (btif_rc_cb.rc_notif[event_id-1].bNotify);
954
955 /* de-register this notification for a CHANGED response */
956 btif_rc_cb.rc_notif[event_id-1].bNotify = FALSE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700957 BTIF_TRACE_DEBUG("%s rc_handle: %d. event_id: 0x%02d bNotify:%u", __FUNCTION__,
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800958 btif_rc_cb.rc_handle, event_id, bNotify);
959 if (bNotify)
960 {
961 BT_HDR *p_msg = NULL;
962 tAVRC_STS status;
963
964 if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(btif_rc_cb.rc_handle,
965 pmetamsg_resp, &p_msg)) )
966 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700967 BTIF_TRACE_DEBUG("%s Sending notification to rc_handle: %d. event_id: 0x%02d",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800968 __FUNCTION__, btif_rc_cb.rc_handle, event_id);
969 bSent = TRUE;
970 BTA_AvMetaRsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label,
971 ctype, p_msg);
972 }
973 else
974 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700975 BTIF_TRACE_WARNING("%s failed to build metamsg response. status: 0x%02x",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800976 __FUNCTION__, status);
977 }
978
979 }
980
981 if (!bSent)
982 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700983 BTIF_TRACE_DEBUG("%s: Notification not sent, as there are no RC connections or the \
Ravi Nagarajan9adddf42013-03-06 05:29:48 -0800984 CT has not subscribed for event_id: %s", __FUNCTION__, dump_rc_notification_event_id(event_id));
985 }
986 }
987 else
988 {
989 /* All other commands go here */
990
991 BT_HDR *p_msg = NULL;
992 tAVRC_STS status;
993
994 status = AVRC_BldResponse(rc_handle, pmetamsg_resp, &p_msg);
995
996 if (status == AVRC_STS_NO_ERROR)
997 {
998 BTA_AvMetaRsp(rc_handle, label, ctype, p_msg);
999 }
1000 else
1001 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001002 BTIF_TRACE_ERROR("%s: failed to build metamsg response. status: 0x%02x",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001003 __FUNCTION__, status);
1004 }
1005 }
1006}
1007
1008static UINT8 opcode_from_pdu(UINT8 pdu)
1009{
1010 UINT8 opcode = 0;
1011
1012 switch (pdu)
1013 {
1014 case AVRC_PDU_NEXT_GROUP:
1015 case AVRC_PDU_PREV_GROUP: /* pass thru */
1016 opcode = AVRC_OP_PASS_THRU;
1017 break;
1018
1019 default: /* vendor */
1020 opcode = AVRC_OP_VENDOR;
1021 break;
1022 }
1023
1024 return opcode;
1025}
1026
1027/*******************************************************************************
1028**
1029** Function btif_rc_upstreams_evt
1030**
1031** Description Executes AVRC UPSTREAMS events in btif context.
1032**
1033** Returns void
1034**
1035*******************************************************************************/
1036static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND *pavrc_cmd, UINT8 ctype, UINT8 label)
1037{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001038 BTIF_TRACE_EVENT("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001039 dump_rc_pdu(pavrc_cmd->pdu), btif_rc_cb.rc_handle, ctype, label);
1040
1041 switch (event)
1042 {
1043 case AVRC_PDU_GET_PLAY_STATUS:
1044 {
1045 FILL_PDU_QUEUE(IDX_GET_PLAY_STATUS_RSP, ctype, label, TRUE)
1046 HAL_CBACK(bt_rc_callbacks, get_play_status_cb);
1047 }
1048 break;
1049 case AVRC_PDU_LIST_PLAYER_APP_ATTR:
1050 case AVRC_PDU_LIST_PLAYER_APP_VALUES:
1051 case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:
1052 case AVRC_PDU_SET_PLAYER_APP_VALUE:
1053 case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:
1054 case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
1055 {
1056 /* TODO: Add support for Application Settings */
Zhihai Xu081d6e52013-03-29 17:27:01 -07001057 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_CMD);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001058 }
1059 break;
1060 case AVRC_PDU_GET_ELEMENT_ATTR:
1061 {
1062 btrc_media_attr_t element_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
1063 UINT8 num_attr;
Ravi Nagarajan841e5b52013-03-22 04:16:57 -07001064 memset(&element_attrs, 0, sizeof(element_attrs));
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001065 if (pavrc_cmd->get_elem_attrs.num_attr == 0)
1066 {
1067 /* CT requests for all attributes */
1068 int attr_cnt;
Ravi Nagarajan841e5b52013-03-22 04:16:57 -07001069 num_attr = BTRC_MAX_ELEM_ATTR_SIZE;
1070 for (attr_cnt = 0; attr_cnt < BTRC_MAX_ELEM_ATTR_SIZE; attr_cnt++)
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001071 {
Ravi Nagarajan841e5b52013-03-22 04:16:57 -07001072 element_attrs[attr_cnt] = attr_cnt + 1;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001073 }
1074 }
1075 else if (pavrc_cmd->get_elem_attrs.num_attr == 0xFF)
1076 {
Ravi Nagarajan841e5b52013-03-22 04:16:57 -07001077 /* 0xff indicates, no attributes requested - reject */
1078 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu,
1079 AVRC_STS_BAD_PARAM);
1080 return;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001081 }
1082 else
1083 {
Mallikarjuna GB0d65d4c2013-11-10 13:30:25 +05301084 int attr_cnt, filled_attr_count;
1085
1086 num_attr = 0;
1087 /* Attribute IDs from 1 to AVRC_MAX_NUM_MEDIA_ATTR_ID are only valid,
1088 * hence HAL definition limits the attributes to AVRC_MAX_NUM_MEDIA_ATTR_ID.
1089 * Fill only valid entries.
1090 */
1091 for (attr_cnt = 0; (attr_cnt < pavrc_cmd->get_elem_attrs.num_attr) &&
1092 (num_attr < AVRC_MAX_NUM_MEDIA_ATTR_ID); attr_cnt++)
1093 {
1094 if ((pavrc_cmd->get_elem_attrs.attrs[attr_cnt] > 0) &&
1095 (pavrc_cmd->get_elem_attrs.attrs[attr_cnt] <= AVRC_MAX_NUM_MEDIA_ATTR_ID))
1096 {
1097 /* Skip the duplicate entries : PTS sends duplicate entries for Fragment cases
1098 */
1099 for (filled_attr_count = 0; filled_attr_count < num_attr; filled_attr_count++)
1100 {
1101 if (element_attrs[filled_attr_count] == pavrc_cmd->get_elem_attrs.attrs[attr_cnt])
1102 break;
1103 }
1104 if (filled_attr_count == num_attr)
1105 {
1106 element_attrs[num_attr] = pavrc_cmd->get_elem_attrs.attrs[attr_cnt];
1107 num_attr++;
1108 }
1109 }
1110 }
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001111 }
1112 FILL_PDU_QUEUE(IDX_GET_ELEMENT_ATTR_RSP, ctype, label, TRUE);
1113 HAL_CBACK(bt_rc_callbacks, get_element_attr_cb, num_attr, element_attrs);
1114 }
1115 break;
1116 case AVRC_PDU_REGISTER_NOTIFICATION:
1117 {
1118 if(pavrc_cmd->reg_notif.event_id == BTRC_EVT_PLAY_POS_CHANGED &&
1119 pavrc_cmd->reg_notif.param == 0)
1120 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001121 BTIF_TRACE_WARNING("%s Device registering position changed with illegal param 0.",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001122 __FUNCTION__);
1123 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_PARAM);
1124 /* de-register this notification for a rejected response */
1125 btif_rc_cb.rc_notif[BTRC_EVT_PLAY_POS_CHANGED - 1].bNotify = FALSE;
1126 return;
1127 }
1128 HAL_CBACK(bt_rc_callbacks, register_notification_cb, pavrc_cmd->reg_notif.event_id,
1129 pavrc_cmd->reg_notif.param);
1130 }
1131 break;
1132 case AVRC_PDU_INFORM_DISPLAY_CHARSET:
1133 {
1134 tAVRC_RESPONSE avrc_rsp;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001135 BTIF_TRACE_EVENT("%s() AVRC_PDU_INFORM_DISPLAY_CHARSET", __FUNCTION__);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001136 if(btif_rc_cb.rc_connected == TRUE)
1137 {
1138 memset(&(avrc_rsp.inform_charset), 0, sizeof(tAVRC_RSP));
1139 avrc_rsp.inform_charset.opcode=opcode_from_pdu(AVRC_PDU_INFORM_DISPLAY_CHARSET);
1140 avrc_rsp.inform_charset.pdu=AVRC_PDU_INFORM_DISPLAY_CHARSET;
1141 avrc_rsp.inform_charset.status=AVRC_STS_NO_ERROR;
1142 send_metamsg_rsp(btif_rc_cb.rc_handle, label, ctype, &avrc_rsp);
1143 }
1144 }
1145 break;
1146 default:
1147 {
1148 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu,
1149 (pavrc_cmd->pdu == AVRC_PDU_SEARCH)?AVRC_STS_SEARCH_NOT_SUP:AVRC_STS_BAD_CMD);
1150 return;
1151 }
1152 break;
1153 }
1154
1155}
1156
Satya Calloji247c68f2013-08-01 02:14:43 -07001157
1158/*******************************************************************************
1159**
1160** Function btif_rc_upstreams_rsp_evt
1161**
1162** Description Executes AVRC UPSTREAMS response events in btif context.
1163**
1164** Returns void
1165**
1166*******************************************************************************/
1167static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label)
1168{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001169 BTIF_TRACE_EVENT("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
Satya Calloji247c68f2013-08-01 02:14:43 -07001170 dump_rc_pdu(pavrc_resp->pdu), btif_rc_cb.rc_handle, ctype, label);
1171
1172#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
1173 switch (event)
1174 {
1175 case AVRC_PDU_REGISTER_NOTIFICATION:
1176 {
1177 if(AVRC_RSP_CHANGED==ctype)
1178 btif_rc_cb.rc_volume=pavrc_resp->reg_notif.param.volume;
1179 HAL_CBACK(bt_rc_callbacks, volume_change_cb, pavrc_resp->reg_notif.param.volume,ctype)
1180 }
1181 break;
1182
1183 case AVRC_PDU_SET_ABSOLUTE_VOLUME:
1184 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001185 BTIF_TRACE_DEBUG("Set absolute volume change event received: volume %d,ctype %d",
Satya Calloji247c68f2013-08-01 02:14:43 -07001186 pavrc_resp->volume.volume,ctype);
1187 if(AVRC_RSP_ACCEPT==ctype)
1188 btif_rc_cb.rc_volume=pavrc_resp->volume.volume;
1189 HAL_CBACK(bt_rc_callbacks,volume_change_cb,pavrc_resp->volume.volume,ctype)
1190 }
1191 break;
1192
1193 default:
1194 return;
1195 }
1196#endif
1197}
1198
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001199/************************************************************************************
1200** AVRCP API Functions
1201************************************************************************************/
1202
1203/*******************************************************************************
1204**
1205** Function init
1206**
1207** Description Initializes the AVRC interface
1208**
1209** Returns bt_status_t
1210**
1211*******************************************************************************/
1212static bt_status_t init(btrc_callbacks_t* callbacks )
1213{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001214 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001215 bt_status_t result = BT_STATUS_SUCCESS;
1216
1217 if (bt_rc_callbacks)
1218 return BT_STATUS_DONE;
1219
1220 bt_rc_callbacks = callbacks;
1221 memset (&btif_rc_cb, 0, sizeof(btif_rc_cb));
Satya Calloji247c68f2013-08-01 02:14:43 -07001222 btif_rc_cb.rc_vol_label=MAX_LABEL;
1223 btif_rc_cb.rc_volume=MAX_VOLUME;
1224 lbl_init();
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001225
1226 return result;
1227}
1228
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001229/*******************************************************************************
1230**
1231** Function init_ctrl
1232**
1233** Description Initializes the AVRC interface
1234**
1235** Returns bt_status_t
1236**
1237*******************************************************************************/
1238static bt_status_t init_ctrl(btrc_ctrl_callbacks_t* callbacks )
1239{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001240 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001241 bt_status_t result = BT_STATUS_SUCCESS;
1242
1243 if (bt_rc_ctrl_callbacks)
1244 return BT_STATUS_DONE;
1245
1246 bt_rc_ctrl_callbacks = callbacks;
1247 memset (&btif_rc_cb, 0, sizeof(btif_rc_cb));
1248 btif_rc_cb.rc_vol_label=MAX_LABEL;
1249 btif_rc_cb.rc_volume=MAX_VOLUME;
1250 lbl_init();
1251
1252 return result;
1253}
1254
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001255/***************************************************************************
1256**
1257** Function get_play_status_rsp
1258**
1259** Description Returns the current play status.
1260** This method is called in response to
1261** GetPlayStatus request.
1262**
1263** Returns bt_status_t
1264**
1265***************************************************************************/
1266static bt_status_t get_play_status_rsp(btrc_play_status_t play_status, uint32_t song_len,
1267 uint32_t song_pos)
1268{
1269 tAVRC_RESPONSE avrc_rsp;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001270 CHECK_RC_CONNECTED
1271 memset(&(avrc_rsp.get_play_status), 0, sizeof(tAVRC_GET_PLAY_STATUS_RSP));
1272 avrc_rsp.get_play_status.song_len = song_len;
1273 avrc_rsp.get_play_status.song_pos = song_pos;
1274 avrc_rsp.get_play_status.play_status = play_status;
1275
1276 avrc_rsp.get_play_status.pdu = AVRC_PDU_GET_PLAY_STATUS;
1277 avrc_rsp.get_play_status.opcode = opcode_from_pdu(AVRC_PDU_GET_PLAY_STATUS);
Ravi Nagarajanb88fc6c2013-04-02 07:11:14 -07001278 avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001279 /* Send the response */
1280 SEND_METAMSG_RSP(IDX_GET_PLAY_STATUS_RSP, &avrc_rsp);
1281 return BT_STATUS_SUCCESS;
1282}
1283
1284/***************************************************************************
1285**
1286** Function get_element_attr_rsp
1287**
1288** Description Returns the current songs' element attributes
1289** in text.
1290**
1291** Returns bt_status_t
1292**
1293***************************************************************************/
1294static bt_status_t get_element_attr_rsp(uint8_t num_attr, btrc_element_attr_val_t *p_attrs)
1295{
1296 tAVRC_RESPONSE avrc_rsp;
1297 UINT32 i;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001298 tAVRC_ATTR_ENTRY element_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
1299 CHECK_RC_CONNECTED
1300 memset(element_attrs, 0, sizeof(tAVRC_ATTR_ENTRY) * num_attr);
1301
1302 if (num_attr == 0)
1303 {
1304 avrc_rsp.get_play_status.status = AVRC_STS_BAD_PARAM;
1305 }
1306 else
1307 {
1308 for (i=0; i<num_attr; i++) {
1309 element_attrs[i].attr_id = p_attrs[i].attr_id;
1310 element_attrs[i].name.charset_id = AVRC_CHARSET_ID_UTF8;
1311 element_attrs[i].name.str_len = (UINT16)strlen((char *)p_attrs[i].text);
1312 element_attrs[i].name.p_str = p_attrs[i].text;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001313 BTIF_TRACE_DEBUG("%s attr_id:0x%x, charset_id:0x%x, str_len:%d, str:%s",
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001314 __FUNCTION__, (unsigned int)element_attrs[i].attr_id,
1315 element_attrs[i].name.charset_id, element_attrs[i].name.str_len,
1316 element_attrs[i].name.p_str);
1317 }
1318 avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
1319 }
1320 avrc_rsp.get_elem_attrs.num_attr = num_attr;
1321 avrc_rsp.get_elem_attrs.p_attrs = element_attrs;
1322 avrc_rsp.get_elem_attrs.pdu = AVRC_PDU_GET_ELEMENT_ATTR;
1323 avrc_rsp.get_elem_attrs.opcode = opcode_from_pdu(AVRC_PDU_GET_ELEMENT_ATTR);
1324 /* Send the response */
1325 SEND_METAMSG_RSP(IDX_GET_ELEMENT_ATTR_RSP, &avrc_rsp);
1326 return BT_STATUS_SUCCESS;
1327}
1328
1329/***************************************************************************
1330**
1331** Function register_notification_rsp
1332**
1333** Description Response to the register notification request.
1334** in text.
1335**
1336** Returns bt_status_t
1337**
1338***************************************************************************/
1339static bt_status_t register_notification_rsp(btrc_event_id_t event_id,
1340 btrc_notification_type_t type, btrc_register_notification_t *p_param)
1341{
1342 tAVRC_RESPONSE avrc_rsp;
1343 CHECK_RC_CONNECTED
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001344 BTIF_TRACE_EVENT("## %s ## event_id:%s", __FUNCTION__, dump_rc_notification_event_id(event_id));
Nitin Srivastava68c53de2014-02-13 19:31:40 +05301345 if (btif_rc_cb.rc_notif[event_id-1].bNotify == FALSE)
1346 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001347 BTIF_TRACE_ERROR("Avrcp Event id not registered: event_id = %x", event_id);
Nitin Srivastava68c53de2014-02-13 19:31:40 +05301348 return BT_STATUS_NOT_READY;
1349 }
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001350 memset(&(avrc_rsp.reg_notif), 0, sizeof(tAVRC_REG_NOTIF_RSP));
1351 avrc_rsp.reg_notif.event_id = event_id;
1352
1353 switch(event_id)
1354 {
1355 case BTRC_EVT_PLAY_STATUS_CHANGED:
1356 avrc_rsp.reg_notif.param.play_status = p_param->play_status;
1357 break;
1358 case BTRC_EVT_TRACK_CHANGE:
1359 memcpy(&(avrc_rsp.reg_notif.param.track), &(p_param->track), sizeof(btrc_uid_t));
1360 break;
Ravi Nagarajanb88fc6c2013-04-02 07:11:14 -07001361 case BTRC_EVT_PLAY_POS_CHANGED:
1362 avrc_rsp.reg_notif.param.play_pos = p_param->song_pos;
1363 break;
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001364 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001365 BTIF_TRACE_WARNING("%s : Unhandled event ID : 0x%x", __FUNCTION__, event_id);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001366 return BT_STATUS_UNHANDLED;
1367 }
1368
1369 avrc_rsp.reg_notif.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
1370 avrc_rsp.reg_notif.opcode = opcode_from_pdu(AVRC_PDU_REGISTER_NOTIFICATION);
1371 avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
1372
1373 /* Send the response. */
1374 send_metamsg_rsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label,
1375 ((type == BTRC_NOTIFICATION_TYPE_INTERIM)?AVRC_CMD_NOTIF:AVRC_RSP_CHANGED), &avrc_rsp);
1376 return BT_STATUS_SUCCESS;
1377}
1378
1379/***************************************************************************
1380**
Satya Calloji247c68f2013-08-01 02:14:43 -07001381** Function set_volume
1382**
1383** Description Send current volume setting to remote side.
1384** Support limited to SetAbsoluteVolume
1385** This can be enhanced to support Relative Volume (AVRCP 1.0).
1386** With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN
1387** as opposed to absolute volume level
1388** volume: Should be in the range 0-127. bit7 is reseved and cannot be set
1389**
1390** Returns bt_status_t
1391**
1392***************************************************************************/
1393static bt_status_t set_volume(uint8_t volume)
1394{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001395 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Satya Calloji247c68f2013-08-01 02:14:43 -07001396 CHECK_RC_CONNECTED
1397 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
1398 rc_transaction_t *p_transaction=NULL;
1399
1400 if(btif_rc_cb.rc_volume==volume)
1401 {
1402 status=BT_STATUS_DONE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001403 BTIF_TRACE_ERROR("%s: volume value already set earlier: 0x%02x",__FUNCTION__, volume);
Satya Calloji247c68f2013-08-01 02:14:43 -07001404 return status;
1405 }
1406
1407 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG) &&
1408 (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL))
1409 {
1410 tAVRC_COMMAND avrc_cmd = {0};
1411 BT_HDR *p_msg = NULL;
1412
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001413 BTIF_TRACE_DEBUG("%s: Peer supports absolute volume. newVolume=%d", __FUNCTION__, volume);
Satya Calloji247c68f2013-08-01 02:14:43 -07001414 avrc_cmd.volume.opcode = AVRC_OP_VENDOR;
1415 avrc_cmd.volume.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME;
1416 avrc_cmd.volume.status = AVRC_STS_NO_ERROR;
1417 avrc_cmd.volume.volume = volume;
1418
1419 if (AVRC_BldCommand(&avrc_cmd, &p_msg) == AVRC_STS_NO_ERROR)
1420 {
1421 bt_status_t tran_status=get_transaction(&p_transaction);
1422 if(BT_STATUS_SUCCESS == tran_status && NULL!=p_transaction)
1423 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001424 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
Satya Calloji247c68f2013-08-01 02:14:43 -07001425 __FUNCTION__,p_transaction->lbl);
1426 BTA_AvMetaCmd(btif_rc_cb.rc_handle,p_transaction->lbl, AVRC_CMD_CTRL, p_msg);
1427 status = BT_STATUS_SUCCESS;
1428 }
1429 else
1430 {
1431 if(NULL!=p_msg)
1432 GKI_freebuf(p_msg);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001433 BTIF_TRACE_ERROR("%s: failed to obtain transaction details. status: 0x%02x",
Satya Calloji247c68f2013-08-01 02:14:43 -07001434 __FUNCTION__, tran_status);
1435 status = BT_STATUS_FAIL;
1436 }
1437 }
1438 else
1439 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001440 BTIF_TRACE_ERROR("%s: failed to build absolute volume command. status: 0x%02x",
Satya Calloji247c68f2013-08-01 02:14:43 -07001441 __FUNCTION__, status);
1442 status = BT_STATUS_FAIL;
1443 }
1444 }
1445 else
1446 status=BT_STATUS_NOT_READY;
1447 return status;
1448}
1449
1450
1451/***************************************************************************
1452**
1453** Function register_volumechange
1454**
1455** Description Register for volume change notification from remote side.
1456**
1457** Returns void
1458**
1459***************************************************************************/
1460
1461static void register_volumechange (UINT8 lbl)
1462{
1463 tAVRC_COMMAND avrc_cmd = {0};
1464 BT_HDR *p_msg = NULL;
1465 tAVRC_STS BldResp=AVRC_STS_BAD_CMD;
Satya Calloji247c68f2013-08-01 02:14:43 -07001466 rc_transaction_t *p_transaction=NULL;
1467
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001468 BTIF_TRACE_DEBUG("%s called with label:%d",__FUNCTION__,lbl);
Satya Calloji247c68f2013-08-01 02:14:43 -07001469
1470 avrc_cmd.cmd.opcode=0x00;
1471 avrc_cmd.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
1472 avrc_cmd.reg_notif.event_id = AVRC_EVT_VOLUME_CHANGE;
1473 avrc_cmd.reg_notif.status = AVRC_STS_NO_ERROR;
1474
1475 BldResp=AVRC_BldCommand(&avrc_cmd, &p_msg);
1476 if(AVRC_STS_NO_ERROR==BldResp && p_msg)
1477 {
1478 p_transaction=get_transaction_by_lbl(lbl);
1479 if(NULL!=p_transaction)
1480 {
1481 BTA_AvMetaCmd(btif_rc_cb.rc_handle,p_transaction->lbl, AVRC_CMD_NOTIF, p_msg);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001482 BTIF_TRACE_DEBUG("%s:BTA_AvMetaCmd called",__FUNCTION__);
Satya Calloji247c68f2013-08-01 02:14:43 -07001483 }
1484 else
1485 {
1486 if(NULL!=p_msg)
1487 GKI_freebuf(p_msg);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001488 BTIF_TRACE_ERROR("%s transaction not obtained with label: %d",__FUNCTION__,lbl);
Satya Calloji247c68f2013-08-01 02:14:43 -07001489 }
1490 }
1491 else
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001492 BTIF_TRACE_ERROR("%s failed to build command:%d",__FUNCTION__,BldResp);
Satya Calloji247c68f2013-08-01 02:14:43 -07001493}
1494
1495
1496/***************************************************************************
1497**
1498** Function handle_rc_metamsg_rsp
1499**
1500** Description Handle RC metamessage response
1501**
1502** Returns void
1503**
1504***************************************************************************/
1505static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg)
1506{
1507 tAVRC_RESPONSE avrc_response = {0};
1508 UINT8 scratch_buf[512] = {0};
1509 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
1510
1511 if(AVRC_OP_VENDOR==pmeta_msg->p_msg->hdr.opcode &&(AVRC_RSP_CHANGED==pmeta_msg->code
1512 || AVRC_RSP_INTERIM==pmeta_msg->code || AVRC_RSP_ACCEPT==pmeta_msg->code
1513 || AVRC_RSP_REJ==pmeta_msg->code || AVRC_RSP_NOT_IMPL==pmeta_msg->code))
1514 {
1515 status=AVRC_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf, sizeof(scratch_buf));
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001516 BTIF_TRACE_DEBUG("%s: code %d,event ID %d,PDU %x,parsing status %d, label:%d",
Satya Calloji247c68f2013-08-01 02:14:43 -07001517 __FUNCTION__,pmeta_msg->code,avrc_response.reg_notif.event_id,avrc_response.reg_notif.pdu,
1518 status, pmeta_msg->label);
1519
1520 if (status != AVRC_STS_NO_ERROR)
1521 {
1522 if(AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
1523 && AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
1524 && btif_rc_cb.rc_vol_label==pmeta_msg->label)
1525 {
1526 btif_rc_cb.rc_vol_label=MAX_LABEL;
1527 release_transaction(btif_rc_cb.rc_vol_label);
1528 }
1529 else if(AVRC_PDU_SET_ABSOLUTE_VOLUME==avrc_response.rsp.pdu)
1530 {
1531 release_transaction(pmeta_msg->label);
1532 }
1533 return;
1534 }
1535 else if(AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
1536 && AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
1537 && btif_rc_cb.rc_vol_label!=pmeta_msg->label)
1538 {
1539 // Just discard the message, if the device sends back with an incorrect label
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001540 BTIF_TRACE_DEBUG("%s:Discarding register notfn in rsp.code: %d and label %d",
Satya Calloji247c68f2013-08-01 02:14:43 -07001541 __FUNCTION__, pmeta_msg->code, pmeta_msg->label);
1542 return;
1543 }
1544 }
1545 else
1546 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001547 BTIF_TRACE_DEBUG("%s:Received vendor dependent in adv ctrl rsp. code: %d len: %d. Not processing it.",
Satya Calloji247c68f2013-08-01 02:14:43 -07001548 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
1549 return;
1550 }
1551
1552 if(AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
1553 && AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
1554 && AVRC_RSP_CHANGED==pmeta_msg->code)
1555 {
1556 /* re-register for volume change notification */
1557 // Do not re-register for rejected case, as it might get into endless loop
1558 register_volumechange(btif_rc_cb.rc_vol_label);
1559 }
1560 else if(AVRC_PDU_SET_ABSOLUTE_VOLUME==avrc_response.rsp.pdu)
1561 {
1562 /* free up the label here */
1563 release_transaction(pmeta_msg->label);
1564 }
1565
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001566 BTIF_TRACE_EVENT("%s: Passing received metamsg response to app. pdu: %s",
Satya Calloji247c68f2013-08-01 02:14:43 -07001567 __FUNCTION__, dump_rc_pdu(avrc_response.pdu));
1568 btif_rc_upstreams_rsp_evt((uint16_t)avrc_response.rsp.pdu, &avrc_response, pmeta_msg->code,
1569 pmeta_msg->label);
1570}
1571
1572
1573/***************************************************************************
1574**
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001575** Function cleanup
1576**
1577** Description Closes the AVRC interface
1578**
1579** Returns void
1580**
1581***************************************************************************/
1582static void cleanup()
1583{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001584 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001585 close_uinput();
1586 if (bt_rc_callbacks)
1587 {
1588 bt_rc_callbacks = NULL;
1589 }
1590 memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
Satya Calloji247c68f2013-08-01 02:14:43 -07001591 lbl_destroy();
Anubhav Guptadaddea92014-09-08 16:00:22 +05301592 BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001593}
1594
Anubhav Guptadaddea92014-09-08 16:00:22 +05301595/***************************************************************************
1596**
1597** Function cleanup_ctrl
1598**
1599** Description Closes the AVRC Controller interface
1600**
1601** Returns void
1602**
1603***************************************************************************/
1604static void cleanup_ctrl()
1605{
1606 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
1607
1608 if (bt_rc_ctrl_callbacks)
1609 {
1610 bt_rc_ctrl_callbacks = NULL;
1611 }
1612 memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
1613 lbl_destroy();
1614 BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
1615}
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001616
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001617static bt_status_t send_passthrough_cmd(bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state)
1618{
1619 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
1620#if (AVRC_CTLR_INCLUDED == TRUE)
1621 CHECK_RC_CONNECTED
1622 rc_transaction_t *p_transaction=NULL;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001623 BTIF_TRACE_DEBUG("%s: key-code: %d, key-state: %d", __FUNCTION__,
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001624 key_code, key_state);
1625 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
1626 {
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001627 bt_status_t tran_status = get_transaction(&p_transaction);
1628 if(BT_STATUS_SUCCESS == tran_status && NULL != p_transaction)
1629 {
1630 BTA_AvRemoteCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
1631 (tBTA_AV_RC)key_code, (tBTA_AV_STATE)key_state);
1632 status = BT_STATUS_SUCCESS;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001633 BTIF_TRACE_DEBUG("%s: succesfully sent passthrough command to BTA", __FUNCTION__);
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001634 }
1635 else
1636 {
1637 status = BT_STATUS_FAIL;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001638 BTIF_TRACE_DEBUG("%s: error in fetching transaction", __FUNCTION__);
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001639 }
1640 }
1641 else
1642 {
1643 status = BT_STATUS_FAIL;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001644 BTIF_TRACE_DEBUG("%s: feature not supported", __FUNCTION__);
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001645 }
1646#else
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001647 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001648#endif
1649 return status;
1650}
1651
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001652static const btrc_interface_t bt_rc_interface = {
1653 sizeof(bt_rc_interface),
1654 init,
1655 get_play_status_rsp,
1656 NULL, /* list_player_app_attr_rsp */
1657 NULL, /* list_player_app_value_rsp */
1658 NULL, /* get_player_app_value_rsp */
1659 NULL, /* get_player_app_attr_text_rsp */
1660 NULL, /* get_player_app_value_text_rsp */
1661 get_element_attr_rsp,
1662 NULL, /* set_player_app_value_rsp */
1663 register_notification_rsp,
Satya Calloji247c68f2013-08-01 02:14:43 -07001664 set_volume,
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001665 cleanup,
1666};
1667
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001668static const btrc_ctrl_interface_t bt_rc_ctrl_interface = {
1669 sizeof(bt_rc_ctrl_interface),
1670 init_ctrl,
1671 send_passthrough_cmd,
Anubhav Guptadaddea92014-09-08 16:00:22 +05301672 cleanup_ctrl,
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001673};
1674
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001675/*******************************************************************************
1676**
1677** Function btif_rc_get_interface
1678**
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001679** Description Get the AVRCP Target callback interface
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001680**
1681** Returns btav_interface_t
1682**
1683*******************************************************************************/
1684const btrc_interface_t *btif_rc_get_interface(void)
1685{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001686 BTIF_TRACE_EVENT("%s", __FUNCTION__);
Ravi Nagarajan9adddf42013-03-06 05:29:48 -08001687 return &bt_rc_interface;
Satya Calloji247c68f2013-08-01 02:14:43 -07001688}
1689
1690/*******************************************************************************
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001691**
1692** Function btif_rc_ctrl_get_interface
1693**
1694** Description Get the AVRCP Controller callback interface
1695**
1696** Returns btav_interface_t
1697**
1698*******************************************************************************/
1699const btrc_ctrl_interface_t *btif_rc_ctrl_get_interface(void)
1700{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001701 BTIF_TRACE_EVENT("%s", __FUNCTION__);
Mike Lockwood4ad470e2014-06-02 16:21:49 -07001702 return &bt_rc_ctrl_interface;
1703}
1704
1705/*******************************************************************************
Satya Calloji247c68f2013-08-01 02:14:43 -07001706** Function initialize_transaction
1707**
1708** Description Initializes fields of the transaction structure
1709**
1710** Returns void
1711*******************************************************************************/
1712static void initialize_transaction(int lbl)
1713{
1714 pthread_mutex_lock(&device.lbllock);
1715 if(lbl < MAX_TRANSACTIONS_PER_SESSION)
1716 {
1717 device.transaction[lbl].lbl = lbl;
1718 device.transaction[lbl].in_use=FALSE;
1719 device.transaction[lbl].handle=0;
1720 }
1721 pthread_mutex_unlock(&device.lbllock);
1722}
1723
1724/*******************************************************************************
1725** Function lbl_init
1726**
1727** Description Initializes label structures and mutexes.
1728**
1729** Returns void
1730*******************************************************************************/
1731void lbl_init()
1732{
1733 memset(&device,0,sizeof(rc_device_t));
1734 pthread_mutexattr_t attr;
1735 pthread_mutexattr_init(&attr);
1736 pthread_mutex_init(&(device.lbllock), &attr);
1737 pthread_mutexattr_destroy(&attr);
1738 init_all_transactions();
1739}
1740
1741/*******************************************************************************
1742**
1743** Function init_all_transactions
1744**
1745** Description Initializes all transactions
1746**
1747** Returns void
1748*******************************************************************************/
1749void init_all_transactions()
1750{
1751 UINT8 txn_indx=0;
1752 for(txn_indx=0; txn_indx < MAX_TRANSACTIONS_PER_SESSION; txn_indx++)
1753 {
1754 initialize_transaction(txn_indx);
1755 }
1756}
1757
1758/*******************************************************************************
1759**
1760** Function get_transaction_by_lbl
1761**
1762** Description Will return a transaction based on the label. If not inuse
1763** will return an error.
1764**
1765** Returns bt_status_t
1766*******************************************************************************/
1767rc_transaction_t *get_transaction_by_lbl(UINT8 lbl)
1768{
1769 rc_transaction_t *transaction = NULL;
1770 pthread_mutex_lock(&device.lbllock);
1771
1772 /* Determine if this is a valid label */
1773 if (lbl < MAX_TRANSACTIONS_PER_SESSION)
1774 {
1775 if (FALSE==device.transaction[lbl].in_use)
1776 {
1777 transaction = NULL;
1778 }
1779 else
1780 {
1781 transaction = &(device.transaction[lbl]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001782 BTIF_TRACE_DEBUG("%s: Got transaction.label: %d",__FUNCTION__,lbl);
Satya Calloji247c68f2013-08-01 02:14:43 -07001783 }
1784 }
1785
1786 pthread_mutex_unlock(&device.lbllock);
1787 return transaction;
1788}
1789
1790/*******************************************************************************
1791**
1792** Function get_transaction
1793**
1794** Description Obtains the transaction details.
1795**
1796** Returns bt_status_t
1797*******************************************************************************/
1798
1799bt_status_t get_transaction(rc_transaction_t **ptransaction)
1800{
1801 bt_status_t result = BT_STATUS_NOMEM;
1802 UINT8 i=0;
1803 pthread_mutex_lock(&device.lbllock);
1804
1805 // Check for unused transactions
1806 for (i=0; i<MAX_TRANSACTIONS_PER_SESSION; i++)
1807 {
1808 if (FALSE==device.transaction[i].in_use)
1809 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001810 BTIF_TRACE_DEBUG("%s:Got transaction.label: %d",__FUNCTION__,device.transaction[i].lbl);
Satya Calloji247c68f2013-08-01 02:14:43 -07001811 device.transaction[i].in_use = TRUE;
1812 *ptransaction = &(device.transaction[i]);
1813 result = BT_STATUS_SUCCESS;
1814 break;
1815 }
1816 }
1817
1818 pthread_mutex_unlock(&device.lbllock);
1819 return result;
1820}
1821
1822
1823/*******************************************************************************
1824**
1825** Function release_transaction
1826**
1827** Description Will release a transaction for reuse
1828**
1829** Returns bt_status_t
1830*******************************************************************************/
1831void release_transaction(UINT8 lbl)
1832{
1833 rc_transaction_t *transaction = get_transaction_by_lbl(lbl);
1834
1835 /* If the transaction is in use... */
1836 if (transaction != NULL)
1837 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001838 BTIF_TRACE_DEBUG("%s: lbl: %d", __FUNCTION__, lbl);
Satya Calloji247c68f2013-08-01 02:14:43 -07001839 initialize_transaction(lbl);
1840 }
1841}
1842
1843/*******************************************************************************
1844**
1845** Function lbl_destroy
1846**
1847** Description Cleanup of the mutex
1848**
1849** Returns void
1850*******************************************************************************/
1851void lbl_destroy()
1852{
1853 pthread_mutex_destroy(&(device.lbllock));
1854}
Matthew Xiea7ae4a12013-10-24 01:09:52 -07001855
1856/*******************************************************************************
1857** Function dev_blacklisted_for_absolute_volume
1858**
1859** Description Blacklist Devices that donot handle absolute volume well
Matthew Xie7850a932013-11-05 17:19:39 -08001860** We are blacklisting all the devices that are not in whitelist
Matthew Xiea7ae4a12013-10-24 01:09:52 -07001861**
1862** Returns True if the device is in the list
1863*******************************************************************************/
1864static BOOLEAN dev_blacklisted_for_absolute_volume(BD_ADDR peer_dev)
1865{
1866 int i;
Thomas.TT_Linc9fbcde2014-04-07 16:13:06 +08001867 char *dev_name_str = NULL;
Matthew Xie7850a932013-11-05 17:19:39 -08001868 int whitelist_size = sizeof(rc_white_addr_prefix)/sizeof(rc_white_addr_prefix[0]);
Thomas.TT_Linc9fbcde2014-04-07 16:13:06 +08001869
Matthew Xie7850a932013-11-05 17:19:39 -08001870 for (i = 0; i < whitelist_size; i++) {
1871 if (rc_white_addr_prefix[i][0] == peer_dev[0] &&
1872 rc_white_addr_prefix[i][1] == peer_dev[1] &&
1873 rc_white_addr_prefix[i][2] == peer_dev[2]) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001874 BTIF_TRACE_DEBUG("whitelist absolute volume for %02x:%02x:%02x",
Thomas.TT_Linc9fbcde2014-04-07 16:13:06 +08001875 peer_dev[0], peer_dev[1], peer_dev[2]);
Matthew Xie7850a932013-11-05 17:19:39 -08001876 return FALSE;
Matthew Xiea7ae4a12013-10-24 01:09:52 -07001877 }
1878 }
Thomas.TT_Linc9fbcde2014-04-07 16:13:06 +08001879
1880 dev_name_str = BTM_SecReadDevName(peer_dev);
1881 whitelist_size = sizeof(rc_white_name)/sizeof(char*);
1882 if (dev_name_str != NULL) {
1883 for (i = 0; i < whitelist_size; i++) {
1884 if (strcmp(dev_name_str, rc_white_name[i]) == 0) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001885 BTIF_TRACE_DEBUG("whitelist absolute volume for %s", dev_name_str);
Thomas.TT_Linc9fbcde2014-04-07 16:13:06 +08001886 return FALSE;
1887 }
1888 }
1889 }
1890
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001891 BTIF_TRACE_WARNING("blacklist absolute volume for %02x:%02x:%02x, name = %s",
Thomas.TT_Linc9fbcde2014-04-07 16:13:06 +08001892 peer_dev[0], peer_dev[1], peer_dev[2], dev_name_str);
Matthew Xie7850a932013-11-05 17:19:39 -08001893 return TRUE;
Matthew Xiea7ae4a12013-10-24 01:09:52 -07001894}