1/******************************************************************************
2 *
3 *  Copyright (C) 2006-2013 Broadcom Corporation
4 *
5 *  Licensed under the Apache License, Version 2.0 (the "License");
6 *  you may not use this file except in compliance with the License.
7 *  You may obtain a copy of the License at:
8 *
9 *  http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 *
17 ******************************************************************************/
18#include <string.h>
19
20#include "gki.h"
21#include "avrc_api.h"
22#include "avrc_defs.h"
23#include "avrc_int.h"
24#include "bt_utils.h"
25
26/*****************************************************************************
27**  Global data
28*****************************************************************************/
29
30#if (AVRC_METADATA_INCLUDED == TRUE)
31
32/*******************************************************************************
33**
34** Function         avrc_pars_vendor_rsp
35**
36** Description      This function parses the vendor specific commands defined by
37**                  Bluetooth SIG
38**
39** Returns          AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
40**                  Otherwise, the error code defined by AVRCP 1.4
41**
42*******************************************************************************/
43static tAVRC_STS avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR *p_msg, tAVRC_RESPONSE *p_result)
44{
45    tAVRC_STS  status = AVRC_STS_NO_ERROR;
46    UINT8   *p = p_msg->p_vendor_data;
47    UINT16  len;
48    UINT8   xx, yy;
49    tAVRC_NOTIF_RSP_PARAM   *p_param;
50    tAVRC_APP_SETTING       *p_app_set;
51    tAVRC_APP_SETTING_TEXT  *p_app_txt;
52    tAVRC_ATTR_ENTRY        *p_entry;
53    UINT32  *p_u32;
54    UINT8   *p_u8;
55    UINT16  size_needed;
56    UINT8 eventid=0;
57
58    BE_STREAM_TO_UINT8 (p_result->pdu, p);
59    p++; /* skip the reserved/packe_type byte */
60    BE_STREAM_TO_UINT16 (len, p);
61    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);
62    if (p_msg->hdr.ctype == AVRC_RSP_REJ)
63    {
64        p_result->rsp.status = *p;
65        return p_result->rsp.status;
66    }
67
68    switch (p_result->pdu)
69    {
70    /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */
71    /* case AVRC_PDU_ABORT_CONTINUATION_RSP:   0x41 */
72
73#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
74    case AVRC_PDU_SET_ABSOLUTE_VOLUME:      /* 0x50 */
75        if (len != 1)
76            status = AVRC_STS_INTERNAL_ERR;
77        else
78        {
79            BE_STREAM_TO_UINT8 (p_result->volume.volume, p);
80        }
81        break;
82#endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */
83
84    case AVRC_PDU_REGISTER_NOTIFICATION:    /* 0x31 */
85#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
86        BE_STREAM_TO_UINT8 (eventid, p);
87        if(AVRC_EVT_VOLUME_CHANGE==eventid
88            && (AVRC_RSP_CHANGED==p_msg->hdr.ctype || AVRC_RSP_INTERIM==p_msg->hdr.ctype
89            || AVRC_RSP_REJ==p_msg->hdr.ctype || AVRC_RSP_NOT_IMPL==p_msg->hdr.ctype))
90        {
91            p_result->reg_notif.status=p_msg->hdr.ctype;
92            p_result->reg_notif.event_id=eventid;
93            BE_STREAM_TO_UINT8 (p_result->reg_notif.param.volume, p);
94        }
95        AVRC_TRACE_DEBUG("avrc_pars_vendor_rsp PDU reg notif response:event %x, volume %x",eventid,
96            p_result->reg_notif.param.volume);
97#endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */
98        break;
99    default:
100        status = AVRC_STS_BAD_CMD;
101        break;
102    }
103
104    return status;
105}
106
107/*******************************************************************************
108**
109** Function         AVRC_ParsResponse
110**
111** Description      This function is a superset of AVRC_ParsMetadata to parse the response.
112**
113** Returns          AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
114**                  Otherwise, the error code defined by AVRCP 1.4
115**
116*******************************************************************************/
117tAVRC_STS AVRC_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, UINT8 *p_buf, UINT16 buf_len)
118{
119    tAVRC_STS  status = AVRC_STS_INTERNAL_ERR;
120    UINT16  id;
121    UNUSED(p_buf);
122    UNUSED(buf_len);
123
124    if (p_msg && p_result)
125    {
126        switch (p_msg->hdr.opcode)
127        {
128        case AVRC_OP_VENDOR:     /*  0x00    Vendor-dependent commands */
129            status = avrc_pars_vendor_rsp(&p_msg->vendor, p_result);
130            break;
131
132        case AVRC_OP_PASS_THRU:  /*  0x7C    panel subunit opcode */
133            status = avrc_pars_pass_thru(&p_msg->pass, &id);
134            if (status == AVRC_STS_NO_ERROR)
135            {
136                p_result->pdu = (UINT8)id;
137            }
138            break;
139
140        default:
141            AVRC_TRACE_ERROR("AVRC_ParsResponse() unknown opcode:0x%x", p_msg->hdr.opcode);
142            break;
143        }
144        p_result->rsp.opcode = p_msg->hdr.opcode;
145        p_result->rsp.status = status;
146    }
147    return status;
148}
149
150
151#endif /* (AVRC_METADATA_INCLUDED == TRUE) */
152