1 /******************************************************************************
3 * Copyright (C) 2003-2013 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
20 #include "bt_common.h"
22 #include "avrc_defs.h"
25 /*****************************************************************************
27 *****************************************************************************/
28 #if (AVRC_METADATA_INCLUDED == TRUE)
30 /*******************************************************************************
32 ** Function avrc_pars_vendor_cmd
34 ** Description This function parses the vendor specific commands defined by
37 ** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
38 ** Otherwise, the error code defined by AVRCP 1.4
40 *******************************************************************************/
41 static tAVRC_STS avrc_pars_vendor_cmd(tAVRC_MSG_VENDOR *p_msg, tAVRC_COMMAND *p_result,
42 UINT8 *p_buf, UINT16 buf_len)
44 tAVRC_STS status = AVRC_STS_NO_ERROR;
50 UINT32 u32, u32_2, *p_u32;
51 tAVRC_APP_SETTING *p_app_set;
54 /* Check the vendor data */
55 if (p_msg->vendor_len == 0)
56 return AVRC_STS_NO_ERROR;
57 if (p_msg->p_vendor_data == NULL)
58 return AVRC_STS_INTERNAL_ERR;
60 p = p_msg->p_vendor_data;
62 AVRC_TRACE_DEBUG("avrc_pars_vendor_cmd() pdu:0x%x", p_result->pdu);
63 if (!AVRC_IsValidAvcType (p_result->pdu, p_msg->hdr.ctype))
65 AVRC_TRACE_DEBUG("avrc_pars_vendor_cmd() detects wrong AV/C type!");
66 status = AVRC_STS_BAD_CMD;
69 p++; /* skip the reserved byte */
70 BE_STREAM_TO_UINT16 (len, p);
71 if ((len+4) != (p_msg->vendor_len))
73 status = AVRC_STS_INTERNAL_ERR;
76 if (status != AVRC_STS_NO_ERROR)
79 switch (p_result->pdu)
81 case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */
82 p_result->get_caps.capability_id = *p++;
83 if (!AVRC_IS_VALID_CAP_ID(p_result->get_caps.capability_id))
84 status = AVRC_STS_BAD_PARAM;
86 status = AVRC_STS_INTERNAL_ERR;
89 case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */
90 /* no additional parameters */
92 status = AVRC_STS_INTERNAL_ERR;
95 case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */
96 p_result->list_app_values.attr_id = *p++;
97 if (!AVRC_IS_VALID_ATTRIBUTE(p_result->list_app_values.attr_id))
98 status = AVRC_STS_BAD_PARAM;
100 status = AVRC_STS_INTERNAL_ERR;
103 case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */
104 case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */
105 BE_STREAM_TO_UINT8 (p_result->get_cur_app_val.num_attr, p);
106 if (len != (p_result->get_cur_app_val.num_attr+1))
108 status = AVRC_STS_INTERNAL_ERR;
111 p_u8 = p_result->get_cur_app_val.attrs;
112 for (xx=0, yy=0; xx< p_result->get_cur_app_val.num_attr; xx++)
114 /* only report the valid player app attributes */
115 if (AVRC_IsValidPlayerAttr(*p))
119 p_result->get_cur_app_val.num_attr = yy;
122 status = AVRC_STS_BAD_PARAM;
126 case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */
127 BE_STREAM_TO_UINT8 (p_result->set_app_val.num_val, p);
128 size_needed = sizeof(tAVRC_APP_SETTING);
129 if (p_buf && (len == ((p_result->set_app_val.num_val<<1) + 1)))
131 p_result->set_app_val.p_vals = (tAVRC_APP_SETTING *)p_buf;
132 p_app_set = p_result->set_app_val.p_vals;
133 for (xx=0; ((xx< p_result->set_app_val.num_val) && (buf_len > size_needed)); xx++)
135 p_app_set[xx].attr_id = *p++;
136 p_app_set[xx].attr_val = *p++;
137 if (!avrc_is_valid_player_attrib_value(p_app_set[xx].attr_id, p_app_set[xx].attr_val))
138 status = AVRC_STS_BAD_PARAM;
140 if (xx != p_result->set_app_val.num_val)
142 AVRC_TRACE_ERROR("AVRC_PDU_SET_PLAYER_APP_VALUE not enough room:%d orig num_val:%d",
143 xx, p_result->set_app_val.num_val);
144 p_result->set_app_val.num_val = xx;
149 AVRC_TRACE_ERROR("AVRC_PDU_SET_PLAYER_APP_VALUE NULL decode buffer or bad len");
150 status = AVRC_STS_INTERNAL_ERR;
154 case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:/* 0x16 */
156 status = AVRC_STS_INTERNAL_ERR;
159 BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.attr_id, p);
160 if (!AVRC_IS_VALID_ATTRIBUTE(p_result->get_app_val_txt.attr_id))
161 status = AVRC_STS_BAD_PARAM;
164 BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.num_val, p);
165 if ( (len - 2/* attr_id & num_val */) != p_result->get_app_val_txt.num_val)
166 status = AVRC_STS_INTERNAL_ERR;
169 p_u8 = p_result->get_app_val_txt.vals;
170 for (xx=0; xx< p_result->get_app_val_txt.num_val; xx++)
173 if (!avrc_is_valid_player_attrib_value(p_result->get_app_val_txt.attr_id,
176 status = AVRC_STS_BAD_PARAM;
185 case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */
187 status = AVRC_STS_INTERNAL_ERR;
190 BE_STREAM_TO_UINT8 (p_result->inform_charset.num_id, p);
191 if ( (len - 1/* num_id */) != p_result->inform_charset.num_id * 2)
192 status = AVRC_STS_INTERNAL_ERR;
195 p_u16 = p_result->inform_charset.charsets;
196 if (p_result->inform_charset.num_id > AVRC_MAX_CHARSET_SIZE)
197 p_result->inform_charset.num_id = AVRC_MAX_CHARSET_SIZE;
198 for (xx=0; xx< p_result->inform_charset.num_id; xx++)
200 BE_STREAM_TO_UINT16 (p_u16[xx], p);
206 case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT:/* 0x18 */
208 status = AVRC_STS_INTERNAL_ERR;
211 p_result->inform_battery_status.battery_status = *p++;
212 if (!AVRC_IS_VALID_BATTERY_STATUS(p_result->inform_battery_status.battery_status))
213 status = AVRC_STS_BAD_PARAM;
217 case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */
218 if (len < 9) /* UID/8 and num_attr/1 */
219 status = AVRC_STS_INTERNAL_ERR;
222 BE_STREAM_TO_UINT32 (u32, p);
223 BE_STREAM_TO_UINT32 (u32_2, p);
224 if (u32== 0 && u32_2 == 0)
226 BE_STREAM_TO_UINT8 (p_result->get_elem_attrs.num_attr, p);
227 if ( (len - 9/* UID/8 and num_attr/1 */) != (p_result->get_elem_attrs.num_attr * 4))
228 status = AVRC_STS_INTERNAL_ERR;
231 p_u32 = p_result->get_elem_attrs.attrs;
232 if (p_result->get_elem_attrs.num_attr > AVRC_MAX_ELEM_ATTR_SIZE)
233 p_result->get_elem_attrs.num_attr = AVRC_MAX_ELEM_ATTR_SIZE;
234 for (xx=0; xx< p_result->get_elem_attrs.num_attr; xx++)
236 BE_STREAM_TO_UINT32 (p_u32[xx], p);
241 status = AVRC_STS_NOT_FOUND;
245 case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */
246 /* no additional parameters */
248 status = AVRC_STS_INTERNAL_ERR;
251 case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */
253 status = AVRC_STS_INTERNAL_ERR;
256 BE_STREAM_TO_UINT8 (p_result->reg_notif.event_id, p);
257 BE_STREAM_TO_UINT32 (p_result->reg_notif.param, p);
261 case AVRC_PDU_SET_ABSOLUTE_VOLUME:
264 status = AVRC_STS_INTERNAL_ERR;
268 /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */
269 /* case AVRC_PDU_ABORT_CONTINUATION_RSP: 0x41 */
272 status = AVRC_STS_BAD_CMD;
279 /*******************************************************************************
281 ** Function AVRC_ParsCommand
283 ** Description This function is a superset of AVRC_ParsMetadata to parse the command.
285 ** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
286 ** Otherwise, the error code defined by AVRCP 1.4
288 *******************************************************************************/
289 tAVRC_STS AVRC_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result, UINT8 *p_buf, UINT16 buf_len)
291 tAVRC_STS status = AVRC_STS_INTERNAL_ERR;
294 if (p_msg && p_result)
296 switch (p_msg->hdr.opcode)
298 case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */
299 status = avrc_pars_vendor_cmd(&p_msg->vendor, p_result, p_buf, buf_len);
302 case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */
303 status = avrc_pars_pass_thru(&p_msg->pass, &id);
304 if (status == AVRC_STS_NO_ERROR)
306 p_result->pdu = (UINT8)id;
311 AVRC_TRACE_ERROR("AVRC_ParsCommand() unknown opcode:0x%x", p_msg->hdr.opcode);
314 p_result->cmd.opcode = p_msg->hdr.opcode;
315 p_result->cmd.status = status;
317 AVRC_TRACE_DEBUG("AVRC_ParsCommand() return status:0x%x", status);
321 #endif /* (AVRC_METADATA_INCLUDED == TRUE) */