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