avrc_utils.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 "common/bt_target.h"
  20. #include "stack/avrc_api.h"
  21. #include "avrc_int.h"
  22. #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
  23. #if (AVRC_METADATA_INCLUDED == TRUE)
  24. /**************************************************************************
  25. **
  26. ** Function AVRC_IsValidAvcType
  27. **
  28. ** Description Check if correct AVC type is specified
  29. **
  30. ** Returns returns TRUE if it is valid
  31. **
  32. **
  33. *******************************************************************************/
  34. BOOLEAN AVRC_IsValidAvcType(UINT8 pdu_id, UINT8 avc_type)
  35. {
  36. BOOLEAN result = FALSE;
  37. if (avc_type < AVRC_RSP_NOT_IMPL) { /* command msg */
  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) {
  48. result = TRUE;
  49. }
  50. break;
  51. case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */
  52. case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */
  53. case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: /* 0x18 */
  54. case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */
  55. case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */
  56. case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */
  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. }
  116. return result;
  117. }
  118. /*******************************************************************************
  119. **
  120. ** Function AVRC_IsValidPlayerAttr
  121. **
  122. ** Description Check if the given attrib value is a valid one
  123. **
  124. ** Returns returns TRUE if it is valid
  125. **
  126. *******************************************************************************/
  127. BOOLEAN AVRC_IsValidPlayerAttr(UINT8 attr)
  128. {
  129. BOOLEAN result = FALSE;
  130. if ( (attr >= AVRC_PLAYER_SETTING_EQUALIZER && attr <= AVRC_PLAYER_SETTING_SCAN) ||
  131. (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) ) {
  132. result = TRUE;
  133. }
  134. return result;
  135. }
  136. /*******************************************************************************
  137. **
  138. ** Function avrc_pars_pass_thru
  139. **
  140. ** Description This function parses the pass thru commands defined by
  141. ** Bluetooth SIG
  142. **
  143. ** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
  144. ** Otherwise, the error code defined by AVRCP 1.4
  145. **
  146. *******************************************************************************/
  147. tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, UINT16 *p_vendor_unique_id)
  148. {
  149. UINT8 *p_data;
  150. UINT32 co_id;
  151. UINT16 id;
  152. tAVRC_STS status = AVRC_STS_BAD_CMD;
  153. if (p_msg->op_id == AVRC_ID_VENDOR && p_msg->pass_len == AVRC_PASS_THRU_GROUP_LEN) {
  154. p_data = p_msg->p_pass_data;
  155. AVRC_BE_STREAM_TO_CO_ID (co_id, p_data);
  156. if (co_id == AVRC_CO_METADATA) {
  157. BE_STREAM_TO_UINT16 (id, p_data);
  158. if (AVRC_IS_VALID_GROUP(id)) {
  159. *p_vendor_unique_id = id;
  160. status = AVRC_STS_NO_ERROR;
  161. }
  162. }
  163. }
  164. return status;
  165. }
  166. /*******************************************************************************
  167. **
  168. ** Function avrc_opcode_from_pdu
  169. **
  170. ** Description This function returns the opcode of the given pdu
  171. **
  172. ** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE
  173. **
  174. *******************************************************************************/
  175. UINT8 avrc_opcode_from_pdu(UINT8 pdu)
  176. {
  177. UINT8 opcode = 0;
  178. switch (pdu) {
  179. case AVRC_PDU_NEXT_GROUP:
  180. case AVRC_PDU_PREV_GROUP: /* pass thru */
  181. opcode = AVRC_OP_PASS_THRU;
  182. break;
  183. default: /* vendor */
  184. opcode = AVRC_OP_VENDOR;
  185. break;
  186. }
  187. return opcode;
  188. }
  189. /*******************************************************************************
  190. **
  191. ** Function avrc_is_valid_opcode
  192. **
  193. ** Description This function returns the opcode of the given pdu
  194. **
  195. ** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE
  196. **
  197. *******************************************************************************/
  198. BOOLEAN avrc_is_valid_opcode(UINT8 opcode)
  199. {
  200. BOOLEAN is_valid = FALSE;
  201. switch (opcode) {
  202. case AVRC_OP_BROWSE:
  203. case AVRC_OP_PASS_THRU:
  204. case AVRC_OP_VENDOR:
  205. is_valid = TRUE;
  206. break;
  207. }
  208. return is_valid;
  209. }
  210. #endif /* (AVRC_METADATA_INCLUDED == TRUE) */
  211. #endif /* #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE) */