avrc_utils.c 7.1 KB

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