1/******************************************************************************
2 *
3 *  Copyright (C) 2003-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_int.h"
23
24
25#if (AVRC_METADATA_INCLUDED == TRUE)
26
27/**************************************************************************
28**
29** Function         AVRC_IsValidAvcType
30**
31** Description      Check if correct AVC type is specified
32**
33** Returns          returns TRUE if it is valid
34**
35**
36*******************************************************************************/
37BOOLEAN AVRC_IsValidAvcType(UINT8 pdu_id, UINT8 avc_type)
38{
39    BOOLEAN result=FALSE;
40
41    if (avc_type < AVRC_RSP_NOT_IMPL) /* command msg */
42    {
43        switch (pdu_id)
44        {
45        case AVRC_PDU_GET_CAPABILITIES:            /* 0x10 */
46        case AVRC_PDU_LIST_PLAYER_APP_ATTR:        /* 0x11 */
47        case AVRC_PDU_LIST_PLAYER_APP_VALUES:      /* 0x12 */
48        case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:    /* 0x13 */
49        case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:    /* 0x15 */
50        case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:   /* 0x16 */
51        case AVRC_PDU_GET_ELEMENT_ATTR:            /* 0x20 */
52        case AVRC_PDU_GET_PLAY_STATUS:             /* 0x30 */
53             if (avc_type == AVRC_CMD_STATUS)
54                result=TRUE;
55             break;
56
57        case AVRC_PDU_SET_PLAYER_APP_VALUE:        /* 0x14 */
58        case AVRC_PDU_INFORM_DISPLAY_CHARSET:      /* 0x17 */
59        case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT:   /* 0x18 */
60        case AVRC_PDU_REQUEST_CONTINUATION_RSP:    /* 0x40 */
61        case AVRC_PDU_ABORT_CONTINUATION_RSP:      /* 0x41 */
62             if (avc_type == AVRC_CMD_CTRL)
63                result=TRUE;
64             break;
65
66        case AVRC_PDU_REGISTER_NOTIFICATION:       /* 0x31 */
67             if (avc_type == AVRC_CMD_NOTIF)
68                result=TRUE;
69             break;
70        }
71    }
72    else  /* response msg */
73    {
74        if (avc_type >= AVRC_RSP_NOT_IMPL  &&
75           avc_type <= AVRC_RSP_INTERIM    )
76           result=TRUE;
77    }
78
79    return result;
80}
81
82/*******************************************************************************
83**
84** Function         avrc_is_valid_player_attrib_value
85**
86** Description      Check if the given attrib value is valid for its attribute
87**
88** Returns          returns TRUE if it is valid
89**
90*******************************************************************************/
91BOOLEAN avrc_is_valid_player_attrib_value(UINT8 attrib, UINT8 value)
92{
93    BOOLEAN result=FALSE;
94
95    switch(attrib)
96    {
97    case AVRC_PLAYER_SETTING_EQUALIZER:
98         if ((value > 0)  &&
99            (value <= AVRC_PLAYER_VAL_ON))
100            result=TRUE;
101         break;
102
103    case AVRC_PLAYER_SETTING_REPEAT:
104         if ((value > 0)  &&
105            (value <= AVRC_PLAYER_VAL_GROUP_REPEAT))
106            result=TRUE;
107         break;
108
109    case AVRC_PLAYER_SETTING_SHUFFLE:
110    case AVRC_PLAYER_SETTING_SCAN:
111         if ((value > 0)  &&
112            (value <= AVRC_PLAYER_VAL_GROUP_SHUFFLE))
113            result=TRUE;
114         break;
115    }
116
117    if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT)
118       result = TRUE;
119
120    if (!result)
121        AVRC_TRACE_ERROR(
122            "avrc_is_valid_player_attrib_value() found not matching attrib(x%x)-value(x%x) pair!",
123            attrib, value);
124
125    return result;
126}
127
128/*******************************************************************************
129**
130** Function         AVRC_IsValidPlayerAttr
131**
132** Description      Check if the given attrib value is a valid one
133**
134** Returns          returns TRUE if it is valid
135**
136*******************************************************************************/
137BOOLEAN AVRC_IsValidPlayerAttr(UINT8 attr)
138{
139    BOOLEAN result=FALSE;
140
141    if ( (attr >= AVRC_PLAYER_SETTING_EQUALIZER && attr <= AVRC_PLAYER_SETTING_SCAN) ||
142         (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) )
143    {
144       result = TRUE;
145    }
146
147    return result;
148}
149
150
151
152/*******************************************************************************
153**
154** Function         avrc_pars_pass_thru
155**
156** Description      This function parses the pass thru commands defined by
157**                  Bluetooth SIG
158**
159** Returns          AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
160**                  Otherwise, the error code defined by AVRCP 1.4
161**
162*******************************************************************************/
163tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, UINT16 *p_vendor_unique_id)
164{
165    UINT8      *p_data;
166    UINT32      co_id;
167    UINT16      id;
168    tAVRC_STS  status = AVRC_STS_BAD_CMD;
169
170    if (p_msg->op_id == AVRC_ID_VENDOR && p_msg->pass_len == AVRC_PASS_THRU_GROUP_LEN)
171    {
172        p_data = p_msg->p_pass_data;
173        AVRC_BE_STREAM_TO_CO_ID (co_id, p_data);
174        if (co_id == AVRC_CO_METADATA)
175        {
176            BE_STREAM_TO_UINT16 (id, p_data);
177            if (AVRC_IS_VALID_GROUP(id))
178            {
179                *p_vendor_unique_id = id;
180                status = AVRC_STS_NO_ERROR;
181            }
182        }
183    }
184    return status;
185}
186
187/*******************************************************************************
188**
189** Function         avrc_opcode_from_pdu
190**
191** Description      This function returns the opcode of the given pdu
192**
193** Returns          AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE
194**
195*******************************************************************************/
196UINT8 avrc_opcode_from_pdu(UINT8 pdu)
197{
198    UINT8 opcode = 0;
199
200    switch (pdu)
201    {
202    case AVRC_PDU_NEXT_GROUP:
203    case AVRC_PDU_PREV_GROUP: /* pass thru */
204        opcode  = AVRC_OP_PASS_THRU;
205        break;
206
207    default: /* vendor */
208        opcode  = AVRC_OP_VENDOR;
209        break;
210    }
211
212    return opcode;
213}
214
215/*******************************************************************************
216**
217** Function         avrc_is_valid_opcode
218**
219** Description      This function returns the opcode of the given pdu
220**
221** Returns          AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE
222**
223*******************************************************************************/
224BOOLEAN avrc_is_valid_opcode(UINT8 opcode)
225{
226    BOOLEAN is_valid = FALSE;
227    switch (opcode)
228    {
229    case AVRC_OP_BROWSE:
230    case AVRC_OP_PASS_THRU:
231    case AVRC_OP_VENDOR:
232        is_valid = TRUE;
233        break;
234    }
235    return is_valid;
236}
237
238#endif /* (AVRC_METADATA_INCLUDED == TRUE) */
239
240