avrc_utils.c 7.1 KB

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