avrc_opt.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2003-2012 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. /******************************************************************************
  19. *
  20. * Interface to AVRCP optional commands
  21. *
  22. ******************************************************************************/
  23. #include <assert.h>
  24. #include "common/bt_target.h"
  25. #include <string.h>
  26. #include "stack/avrc_api.h"
  27. #include "avrc_int.h"
  28. #include "osi/allocator.h"
  29. #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
  30. /******************************************************************************
  31. **
  32. ** Function avrc_vendor_msg
  33. **
  34. ** Description Compose a VENDOR DEPENDENT command according to p_msg
  35. **
  36. ** Input Parameters:
  37. ** p_msg: Pointer to VENDOR DEPENDENT message structure.
  38. **
  39. ** Output Parameters:
  40. ** None.
  41. **
  42. ** Returns pointer to a valid GKI buffer if successful.
  43. ** NULL if p_msg is NULL.
  44. **
  45. ******************************************************************************/
  46. static BT_HDR *avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg)
  47. {
  48. BT_HDR *p_cmd;
  49. UINT8 *p_data;
  50. assert(p_msg != NULL);
  51. #if AVRC_METADATA_INCLUDED == TRUE
  52. assert(AVRC_META_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
  53. if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_META_CMD_BUF_SIZE)) != NULL)
  54. #else
  55. assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
  56. if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL)
  57. #endif
  58. {
  59. p_cmd->offset = AVCT_MSG_OFFSET;
  60. p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
  61. *p_data++ = (p_msg->hdr.ctype & AVRC_CTYPE_MASK);
  62. *p_data++ = (p_msg->hdr.subunit_type << AVRC_SUBTYPE_SHIFT) | p_msg->hdr.subunit_id;
  63. *p_data++ = AVRC_OP_VENDOR;
  64. AVRC_CO_ID_TO_BE_STREAM(p_data, p_msg->company_id);
  65. if (p_msg->vendor_len && p_msg->p_vendor_data) {
  66. memcpy(p_data, p_msg->p_vendor_data, p_msg->vendor_len);
  67. }
  68. p_cmd->len = (UINT16) (p_data + p_msg->vendor_len - (UINT8 *)(p_cmd + 1) - p_cmd->offset);
  69. p_cmd->layer_specific = AVCT_DATA_CTRL;
  70. }
  71. return p_cmd;
  72. }
  73. /******************************************************************************
  74. **
  75. ** Function AVRC_UnitCmd
  76. **
  77. ** Description Send a UNIT INFO command to the peer device. This
  78. ** function can only be called for controller role connections.
  79. ** Any response message from the peer is passed back through
  80. ** the tAVRC_MSG_CBACK callback function.
  81. **
  82. ** Input Parameters:
  83. ** handle: Handle of this connection.
  84. **
  85. ** label: Transaction label.
  86. **
  87. ** Output Parameters:
  88. ** None.
  89. **
  90. ** Returns AVRC_SUCCESS if successful.
  91. ** AVRC_BAD_HANDLE if handle is invalid.
  92. **
  93. ******************************************************************************/
  94. UINT16 AVRC_UnitCmd(UINT8 handle, UINT8 label)
  95. {
  96. BT_HDR *p_cmd;
  97. UINT8 *p_data;
  98. if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL) {
  99. p_cmd->offset = AVCT_MSG_OFFSET;
  100. p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
  101. *p_data++ = AVRC_CMD_STATUS;
  102. /* unit & id ignore */
  103. *p_data++ = (AVRC_SUB_UNIT << AVRC_SUBTYPE_SHIFT) | AVRC_SUBID_IGNORE;
  104. *p_data++ = AVRC_OP_UNIT_INFO;
  105. memset(p_data, AVRC_CMD_OPRND_PAD, AVRC_UNIT_OPRND_BYTES);
  106. p_cmd->len = p_data + AVRC_UNIT_OPRND_BYTES - (UINT8 *)(p_cmd + 1) - p_cmd->offset;
  107. p_cmd->layer_specific = AVCT_DATA_CTRL;
  108. }
  109. return AVCT_MsgReq( handle, label, AVCT_CMD, p_cmd);
  110. }
  111. /******************************************************************************
  112. **
  113. ** Function AVRC_SubCmd
  114. **
  115. ** Description Send a SUBUNIT INFO command to the peer device. This
  116. ** function can only be called for controller role connections.
  117. ** Any response message from the peer is passed back through
  118. ** the tAVRC_MSG_CBACK callback function.
  119. **
  120. ** Input Parameters:
  121. ** handle: Handle of this connection.
  122. **
  123. ** label: Transaction label.
  124. **
  125. ** page: Specifies which part of the subunit type table
  126. ** is requested. For AVRCP it is typically zero.
  127. ** Value range is 0-7.
  128. **
  129. ** Output Parameters:
  130. ** None.
  131. **
  132. ** Returns AVRC_SUCCESS if successful.
  133. ** AVRC_BAD_HANDLE if handle is invalid.
  134. **
  135. ******************************************************************************/
  136. UINT16 AVRC_SubCmd(UINT8 handle, UINT8 label, UINT8 page)
  137. {
  138. BT_HDR *p_cmd;
  139. UINT8 *p_data;
  140. if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL) {
  141. p_cmd->offset = AVCT_MSG_OFFSET;
  142. p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
  143. *p_data++ = AVRC_CMD_STATUS;
  144. /* unit & id ignore */
  145. *p_data++ = (AVRC_SUB_UNIT << AVRC_SUBTYPE_SHIFT) | AVRC_SUBID_IGNORE;
  146. *p_data++ = AVRC_OP_SUB_INFO;
  147. *p_data++ = ((page & AVRC_SUB_PAGE_MASK) << AVRC_SUB_PAGE_SHIFT) | AVRC_SUB_EXT_CODE;
  148. memset(p_data, AVRC_CMD_OPRND_PAD, AVRC_SUB_OPRND_BYTES);
  149. p_cmd->len = p_data + AVRC_SUB_OPRND_BYTES - (UINT8 *)(p_cmd + 1) - p_cmd->offset;
  150. p_cmd->layer_specific = AVCT_DATA_CTRL;
  151. }
  152. return AVCT_MsgReq( handle, label, AVCT_CMD, p_cmd);
  153. }
  154. /******************************************************************************
  155. **
  156. ** Function AVRC_VendorCmd
  157. **
  158. ** Description Send a VENDOR DEPENDENT command to the peer device. This
  159. ** function can only be called for controller role connections.
  160. ** Any response message from the peer is passed back through
  161. ** the tAVRC_MSG_CBACK callback function.
  162. **
  163. ** Input Parameters:
  164. ** handle: Handle of this connection.
  165. **
  166. ** label: Transaction label.
  167. **
  168. ** p_msg: Pointer to VENDOR DEPENDENT message structure.
  169. **
  170. ** Output Parameters:
  171. ** None.
  172. **
  173. ** Returns AVRC_SUCCESS if successful.
  174. ** AVRC_BAD_HANDLE if handle is invalid.
  175. **
  176. ******************************************************************************/
  177. UINT16 AVRC_VendorCmd(UINT8 handle, UINT8 label, tAVRC_MSG_VENDOR *p_msg)
  178. {
  179. BT_HDR *p_buf = avrc_vendor_msg(p_msg);
  180. if (p_buf) {
  181. return AVCT_MsgReq( handle, label, AVCT_CMD, p_buf);
  182. } else {
  183. return AVCT_NO_RESOURCES;
  184. }
  185. }
  186. /******************************************************************************
  187. **
  188. ** Function AVRC_VendorRsp
  189. **
  190. ** Description Send a VENDOR DEPENDENT response to the peer device. This
  191. ** function can only be called for target role connections.
  192. ** This function must be called when a VENDOR DEPENDENT
  193. ** command message is received from the peer through the
  194. ** tAVRC_MSG_CBACK callback function.
  195. **
  196. ** Input Parameters:
  197. ** handle: Handle of this connection.
  198. **
  199. ** label: Transaction label. Must be the same value as
  200. ** passed with the command message in the callback function.
  201. **
  202. ** p_msg: Pointer to VENDOR DEPENDENT message structure.
  203. **
  204. ** Output Parameters:
  205. ** None.
  206. **
  207. ** Returns AVRC_SUCCESS if successful.
  208. ** AVRC_BAD_HANDLE if handle is invalid.
  209. **
  210. ******************************************************************************/
  211. UINT16 AVRC_VendorRsp(UINT8 handle, UINT8 label, tAVRC_MSG_VENDOR *p_msg)
  212. {
  213. BT_HDR *p_buf = avrc_vendor_msg(p_msg);
  214. if (p_buf) {
  215. return AVCT_MsgReq( handle, label, AVCT_RSP, p_buf);
  216. } else {
  217. return AVCT_NO_RESOURCES;
  218. }
  219. }
  220. #endif /* #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE) */