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 *******************************************************************************/
avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR * p_msg,tAVRC_RESPONSE * p_result)43 static 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;
47 UINT16 len;
48 UINT8 eventid=0;
49
50 /* Check the vendor data */
51 if (p_msg->vendor_len == 0)
52 return AVRC_STS_NO_ERROR;
53 if (p_msg->p_vendor_data == NULL)
54 return AVRC_STS_INTERNAL_ERR;
55
56 p = p_msg->p_vendor_data;
57 BE_STREAM_TO_UINT8 (p_result->pdu, p);
58 p++; /* skip the reserved/packe_type byte */
59 BE_STREAM_TO_UINT16 (len, p);
60 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);
61 if (p_msg->hdr.ctype == AVRC_RSP_REJ)
62 {
63 p_result->rsp.status = *p;
64 return p_result->rsp.status;
65 }
66
67 switch (p_result->pdu)
68 {
69 /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */
70 /* case AVRC_PDU_ABORT_CONTINUATION_RSP: 0x41 */
71
72 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
73 case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */
74 if (len != 1)
75 status = AVRC_STS_INTERNAL_ERR;
76 else
77 {
78 BE_STREAM_TO_UINT8 (p_result->volume.volume, p);
79 }
80 break;
81 #endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */
82
83 case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */
84 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
85 BE_STREAM_TO_UINT8 (eventid, p);
86 if(AVRC_EVT_VOLUME_CHANGE==eventid
87 && (AVRC_RSP_CHANGED==p_msg->hdr.ctype || AVRC_RSP_INTERIM==p_msg->hdr.ctype
88 || AVRC_RSP_REJ==p_msg->hdr.ctype || AVRC_RSP_NOT_IMPL==p_msg->hdr.ctype))
89 {
90 p_result->reg_notif.status=p_msg->hdr.ctype;
91 p_result->reg_notif.event_id=eventid;
92 BE_STREAM_TO_UINT8 (p_result->reg_notif.param.volume, p);
93 }
94 AVRC_TRACE_DEBUG("avrc_pars_vendor_rsp PDU reg notif response:event %x, volume %x",eventid,
95 p_result->reg_notif.param.volume);
96 #endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */
97 break;
98 default:
99 status = AVRC_STS_BAD_CMD;
100 break;
101 }
102
103 return status;
104 }
105
106 /*******************************************************************************
107 **
108 ** Function AVRC_ParsResponse
109 **
110 ** Description This function is a superset of AVRC_ParsMetadata to parse the response.
111 **
112 ** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
113 ** Otherwise, the error code defined by AVRCP 1.4
114 **
115 *******************************************************************************/
AVRC_ParsResponse(tAVRC_MSG * p_msg,tAVRC_RESPONSE * p_result,UINT8 * p_buf,UINT16 buf_len)116 tAVRC_STS AVRC_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, UINT8 *p_buf, UINT16 buf_len)
117 {
118 tAVRC_STS status = AVRC_STS_INTERNAL_ERR;
119 UINT16 id;
120 UNUSED(p_buf);
121 UNUSED(buf_len);
122
123 if (p_msg && p_result)
124 {
125 switch (p_msg->hdr.opcode)
126 {
127 case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */
128 status = avrc_pars_vendor_rsp(&p_msg->vendor, p_result);
129 break;
130
131 case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */
132 status = avrc_pars_pass_thru(&p_msg->pass, &id);
133 if (status == AVRC_STS_NO_ERROR)
134 {
135 p_result->pdu = (UINT8)id;
136 }
137 break;
138
139 default:
140 AVRC_TRACE_ERROR("AVRC_ParsResponse() unknown opcode:0x%x", p_msg->hdr.opcode);
141 break;
142 }
143 p_result->rsp.opcode = p_msg->hdr.opcode;
144 p_result->rsp.status = status;
145 }
146 return status;
147 }
148
149
150 #endif /* (AVRC_METADATA_INCLUDED == TRUE) */
151