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 "bt_common.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 *******************************************************************************/ 37 BOOLEAN 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 case AVRC_PDU_SET_ADDRESSED_PLAYER: 63 case AVRC_PDU_PLAY_ITEM: 64 case AVRC_PDU_SET_ABSOLUTE_VOLUME: 65 if (avc_type == AVRC_CMD_CTRL) 66 result=TRUE; 67 break; 68 69 case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ 70 if (avc_type == AVRC_CMD_NOTIF) 71 result=TRUE; 72 break; 73 } 74 } 75 else /* response msg */ 76 { 77 if (avc_type >= AVRC_RSP_NOT_IMPL && 78 avc_type <= AVRC_RSP_INTERIM ) 79 result=TRUE; 80 } 81 82 return result; 83 } 84 85 /******************************************************************************* 86 ** 87 ** Function avrc_is_valid_player_attrib_value 88 ** 89 ** Description Check if the given attrib value is valid for its attribute 90 ** 91 ** Returns returns TRUE if it is valid 92 ** 93 *******************************************************************************/ 94 BOOLEAN avrc_is_valid_player_attrib_value(UINT8 attrib, UINT8 value) 95 { 96 BOOLEAN result=FALSE; 97 98 switch(attrib) 99 { 100 case AVRC_PLAYER_SETTING_EQUALIZER: 101 if ((value > 0) && 102 (value <= AVRC_PLAYER_VAL_ON)) 103 result=TRUE; 104 break; 105 106 case AVRC_PLAYER_SETTING_REPEAT: 107 if ((value > 0) && 108 (value <= AVRC_PLAYER_VAL_GROUP_REPEAT)) 109 result=TRUE; 110 break; 111 112 case AVRC_PLAYER_SETTING_SHUFFLE: 113 case AVRC_PLAYER_SETTING_SCAN: 114 if ((value > 0) && 115 (value <= AVRC_PLAYER_VAL_GROUP_SHUFFLE)) 116 result=TRUE; 117 break; 118 } 119 120 if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) 121 result = TRUE; 122 123 if (!result) 124 AVRC_TRACE_ERROR( 125 "avrc_is_valid_player_attrib_value() found not matching attrib(x%x)-value(x%x) pair!", 126 attrib, value); 127 128 return result; 129 } 130 131 /******************************************************************************* 132 ** 133 ** Function AVRC_IsValidPlayerAttr 134 ** 135 ** Description Check if the given attrib value is a valid one 136 ** 137 ** Returns returns TRUE if it is valid 138 ** 139 *******************************************************************************/ 140 BOOLEAN AVRC_IsValidPlayerAttr(UINT8 attr) 141 { 142 BOOLEAN result=FALSE; 143 144 if ( (attr >= AVRC_PLAYER_SETTING_EQUALIZER && attr <= AVRC_PLAYER_SETTING_SCAN) || 145 (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) ) 146 { 147 result = TRUE; 148 } 149 150 return result; 151 } 152 153 154 155 /******************************************************************************* 156 ** 157 ** Function avrc_pars_pass_thru 158 ** 159 ** Description This function parses the pass thru commands defined by 160 ** Bluetooth SIG 161 ** 162 ** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. 163 ** Otherwise, the error code defined by AVRCP 1.4 164 ** 165 *******************************************************************************/ 166 tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, UINT16 *p_vendor_unique_id) 167 { 168 UINT8 *p_data; 169 UINT32 co_id; 170 UINT16 id; 171 tAVRC_STS status = AVRC_STS_BAD_CMD; 172 173 if (p_msg->op_id == AVRC_ID_VENDOR && p_msg->pass_len == AVRC_PASS_THRU_GROUP_LEN) 174 { 175 p_data = p_msg->p_pass_data; 176 AVRC_BE_STREAM_TO_CO_ID (co_id, p_data); 177 if (co_id == AVRC_CO_METADATA) 178 { 179 BE_STREAM_TO_UINT16 (id, p_data); 180 if (AVRC_IS_VALID_GROUP(id)) 181 { 182 *p_vendor_unique_id = id; 183 status = AVRC_STS_NO_ERROR; 184 } 185 } 186 } 187 return status; 188 } 189 190 /******************************************************************************* 191 ** 192 ** Function avrc_opcode_from_pdu 193 ** 194 ** Description This function returns the opcode of the given pdu 195 ** 196 ** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE 197 ** 198 *******************************************************************************/ 199 UINT8 avrc_opcode_from_pdu(UINT8 pdu) 200 { 201 UINT8 opcode = 0; 202 203 switch (pdu) 204 { 205 case AVRC_PDU_NEXT_GROUP: 206 case AVRC_PDU_PREV_GROUP: /* pass thru */ 207 opcode = AVRC_OP_PASS_THRU; 208 break; 209 210 default: /* vendor */ 211 opcode = AVRC_OP_VENDOR; 212 break; 213 } 214 215 return opcode; 216 } 217 218 /******************************************************************************* 219 ** 220 ** Function avrc_is_valid_opcode 221 ** 222 ** Description This function returns the opcode of the given pdu 223 ** 224 ** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE 225 ** 226 *******************************************************************************/ 227 BOOLEAN avrc_is_valid_opcode(UINT8 opcode) 228 { 229 BOOLEAN is_valid = FALSE; 230 switch (opcode) 231 { 232 case AVRC_OP_BROWSE: 233 case AVRC_OP_PASS_THRU: 234 case AVRC_OP_VENDOR: 235 is_valid = TRUE; 236 break; 237 } 238 return is_valid; 239 } 240 241 #endif /* (AVRC_METADATA_INCLUDED == TRUE) */ 242 243