1247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji/******************************************************************************
2247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *
3247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  Copyright (C) 2006-2013 Broadcom Corporation
4247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *
5247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  Licensed under the Apache License, Version 2.0 (the "License");
6247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  you may not use this file except in compliance with the License.
7247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  You may obtain a copy of the License at:
8247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *
9247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  http://www.apache.org/licenses/LICENSE-2.0
10247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *
11247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  Unless required by applicable law or agreed to in writing, software
12247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  distributed under the License is distributed on an "AS IS" BASIS,
13247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  See the License for the specific language governing permissions and
15247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *  limitations under the License.
16247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji *
17247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji ******************************************************************************/
18247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#include <string.h>
19247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
20247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#include "gki.h"
21247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#include "avrc_api.h"
22247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#include "avrc_defs.h"
23247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#include "avrc_int.h"
245cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen#include "bt_utils.h"
25247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
26247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji/*****************************************************************************
27247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**  Global data
28247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji*****************************************************************************/
29247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
30247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#if (AVRC_METADATA_INCLUDED == TRUE)
31247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
32247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji/*******************************************************************************
33247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**
34247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji** Function         avrc_pars_vendor_rsp
35247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**
36247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji** Description      This function parses the vendor specific commands defined by
37247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**                  Bluetooth SIG
38247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**
39247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji** Returns          AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
40247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**                  Otherwise, the error code defined by AVRCP 1.4
41247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**
42247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji*******************************************************************************/
435cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chenstatic tAVRC_STS avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR *p_msg, tAVRC_RESPONSE *p_result)
44247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji{
45247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    tAVRC_STS  status = AVRC_STS_NO_ERROR;
46247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    UINT8   *p = p_msg->p_vendor_data;
47247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    UINT16  len;
48247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    UINT8   xx, yy;
49247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    tAVRC_NOTIF_RSP_PARAM   *p_param;
50247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    tAVRC_APP_SETTING       *p_app_set;
51247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    tAVRC_APP_SETTING_TEXT  *p_app_txt;
52247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    tAVRC_ATTR_ENTRY        *p_entry;
53247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    UINT32  *p_u32;
54247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    UINT8   *p_u8;
55247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    UINT16  size_needed;
56247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    UINT8 eventid=0;
57247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
58247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    BE_STREAM_TO_UINT8 (p_result->pdu, p);
59247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    p++; /* skip the reserved/packe_type byte */
60247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    BE_STREAM_TO_UINT16 (len, p);
61b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    AVRC_TRACE_DEBUG("avrc_pars_vendor_rsp() ctype:0x%x pdu:0x%x, len:%d/0x%x", p_msg->hdr.ctype, p_result->pdu, len, len);
62247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    if (p_msg->hdr.ctype == AVRC_RSP_REJ)
63247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    {
64247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        p_result->rsp.status = *p;
65247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        return p_result->rsp.status;
66247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    }
67247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
68247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    switch (p_result->pdu)
69247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    {
70247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */
71247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    /* case AVRC_PDU_ABORT_CONTINUATION_RSP:   0x41 */
72247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
73247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
74247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    case AVRC_PDU_SET_ABSOLUTE_VOLUME:      /* 0x50 */
75247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        if (len != 1)
76247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            status = AVRC_STS_INTERNAL_ERR;
77247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        else
78247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        {
79247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            BE_STREAM_TO_UINT8 (p_result->volume.volume, p);
80247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        }
81247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        break;
82247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */
83247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
84247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    case AVRC_PDU_REGISTER_NOTIFICATION:    /* 0x31 */
85247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
86247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        BE_STREAM_TO_UINT8 (eventid, p);
87247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        if(AVRC_EVT_VOLUME_CHANGE==eventid
88247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            && (AVRC_RSP_CHANGED==p_msg->hdr.ctype || AVRC_RSP_INTERIM==p_msg->hdr.ctype
89247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            || AVRC_RSP_REJ==p_msg->hdr.ctype || AVRC_RSP_NOT_IMPL==p_msg->hdr.ctype))
90247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        {
91247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            p_result->reg_notif.status=p_msg->hdr.ctype;
92247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            p_result->reg_notif.event_id=eventid;
93247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            BE_STREAM_TO_UINT8 (p_result->reg_notif.param.volume, p);
94247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        }
95b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati        AVRC_TRACE_DEBUG("avrc_pars_vendor_rsp PDU reg notif response:event %x, volume %x",eventid,
96247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            p_result->reg_notif.param.volume);
97247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */
98247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        break;
99247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    default:
100247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        status = AVRC_STS_BAD_CMD;
101247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        break;
102247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    }
103247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
104247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    return status;
105247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji}
106247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
107247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji/*******************************************************************************
108247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**
109247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji** Function         AVRC_ParsResponse
110247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**
111247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji** Description      This function is a superset of AVRC_ParsMetadata to parse the response.
112247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**
113247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji** Returns          AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
114247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**                  Otherwise, the error code defined by AVRCP 1.4
115247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji**
116247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji*******************************************************************************/
117247c68fe6eee3660cbdcf4509195fe735ae25573Satya CallojitAVRC_STS AVRC_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, UINT8 *p_buf, UINT16 buf_len)
118247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji{
119247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    tAVRC_STS  status = AVRC_STS_INTERNAL_ERR;
120247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    UINT16  id;
1215cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(p_buf);
1225cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(buf_len);
123247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
124247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    if (p_msg && p_result)
125247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    {
126247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        switch (p_msg->hdr.opcode)
127247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        {
128247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        case AVRC_OP_VENDOR:     /*  0x00    Vendor-dependent commands */
1295cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen            status = avrc_pars_vendor_rsp(&p_msg->vendor, p_result);
130247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            break;
131247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
132247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        case AVRC_OP_PASS_THRU:  /*  0x7C    panel subunit opcode */
133247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            status = avrc_pars_pass_thru(&p_msg->pass, &id);
134247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            if (status == AVRC_STS_NO_ERROR)
135247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            {
136247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji                p_result->pdu = (UINT8)id;
137247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            }
138247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            break;
139247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
140247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        default:
141b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati            AVRC_TRACE_ERROR("AVRC_ParsResponse() unknown opcode:0x%x", p_msg->hdr.opcode);
142247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji            break;
143247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        }
144247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji        p_result->rsp.opcode = p_msg->hdr.opcode;
1455cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen        p_result->rsp.status = status;
146247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    }
147247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji    return status;
148247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji}
149247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
150247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji
151247c68fe6eee3660cbdcf4509195fe735ae25573Satya Calloji#endif /* (AVRC_METADATA_INCLUDED == TRUE) */
152