bta_pan_ci.cc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /******************************************************************************
  2. *
  3. * Copyright 2004-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. * This is the implementation file for data gateway call-in functions.
  21. *
  22. ******************************************************************************/
  23. #include "bt_target.h"
  24. #include <string.h>
  25. #include "bt_common.h"
  26. #include "bt_utils.h"
  27. #include "bta_api.h"
  28. #include "bta_pan_api.h"
  29. #include "bta_pan_ci.h"
  30. #include "bta_pan_int.h"
  31. #include "osi/include/osi.h"
  32. #include "pan_api.h"
  33. #if (BTA_PAN_INCLUDED == TRUE)
  34. /*******************************************************************************
  35. *
  36. * Function bta_pan_ci_tx_ready
  37. *
  38. * Description This function sends an event to PAN indicating the phone is
  39. * ready for more data and PAN should call
  40. * bta_pan_co_tx_path().
  41. * This function is used when the TX data path is configured
  42. * to use a pull interface.
  43. *
  44. *
  45. * Returns void
  46. *
  47. ******************************************************************************/
  48. void bta_pan_ci_tx_ready(uint16_t handle) {
  49. BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
  50. p_buf->layer_specific = handle;
  51. p_buf->event = BTA_PAN_CI_TX_READY_EVT;
  52. bta_sys_sendmsg(p_buf);
  53. }
  54. /*******************************************************************************
  55. *
  56. * Function bta_pan_ci_rx_ready
  57. *
  58. * Description This function sends an event to PAN indicating the phone
  59. * has data available to send to PAN and PAN should call
  60. * bta_pan_co_rx_path(). This function is used when the RX
  61. * data path is configured to use a pull interface.
  62. *
  63. *
  64. * Returns void
  65. *
  66. ******************************************************************************/
  67. void bta_pan_ci_rx_ready(uint16_t handle) {
  68. BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
  69. p_buf->layer_specific = handle;
  70. p_buf->event = BTA_PAN_CI_RX_READY_EVT;
  71. bta_sys_sendmsg(p_buf);
  72. }
  73. /*******************************************************************************
  74. *
  75. * Function bta_pan_ci_tx_flow
  76. *
  77. * Description This function is called to enable or disable data flow on
  78. * the TX path. The phone should call this function to
  79. * disable data flow when it is congested and cannot handle
  80. * any more data sent by bta_pan_co_tx_write() or
  81. * bta_pan_co_tx_writebuf(). This function is used when the
  82. * TX data path is configured to use a push interface.
  83. *
  84. *
  85. * Returns void
  86. *
  87. ******************************************************************************/
  88. void bta_pan_ci_tx_flow(uint16_t handle, bool enable) {
  89. tBTA_PAN_CI_TX_FLOW* p_buf =
  90. (tBTA_PAN_CI_TX_FLOW*)osi_malloc(sizeof(tBTA_PAN_CI_TX_FLOW));
  91. p_buf->hdr.layer_specific = handle;
  92. p_buf->hdr.event = BTA_PAN_CI_TX_FLOW_EVT;
  93. p_buf->enable = enable;
  94. bta_sys_sendmsg(p_buf);
  95. }
  96. /*******************************************************************************
  97. *
  98. * Function bta_pan_ci_rx_write
  99. *
  100. * Description This function is called to send data to PAN when the RX path
  101. * is configured to use a push interface. The function copies
  102. * data to an event buffer and sends it to PAN.
  103. *
  104. *
  105. * Returns void
  106. *
  107. ******************************************************************************/
  108. void bta_pan_ci_rx_write(uint16_t handle, const RawAddress& dst,
  109. const RawAddress& src, uint16_t protocol,
  110. uint8_t* p_data, uint16_t len, bool ext) {
  111. BT_HDR* p_buf = (BT_HDR*)osi_malloc(PAN_BUF_SIZE);
  112. p_buf->offset = PAN_MINIMUM_OFFSET;
  113. /* copy all other params before the data */
  114. ((tBTA_PAN_DATA_PARAMS*)p_buf)->src = src;
  115. ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst = dst;
  116. ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol = protocol;
  117. ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext = ext;
  118. p_buf->len = len;
  119. /* copy data */
  120. memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, p_data, len);
  121. p_buf->layer_specific = handle;
  122. p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
  123. bta_sys_sendmsg(p_buf);
  124. }
  125. /*******************************************************************************
  126. *
  127. * Function bta_pan_ci_rx_writebuf
  128. *
  129. * Description This function is called to send data to the phone when
  130. * the RX path is configured to use a push interface with
  131. * zero copy. The function sends an event to PAN containing
  132. * the data buffer. The buffer will be freed by BTA; the
  133. * phone must not free the buffer.
  134. *
  135. *
  136. * Returns void
  137. *
  138. ******************************************************************************/
  139. void bta_pan_ci_rx_writebuf(uint16_t handle, const RawAddress& dst,
  140. const RawAddress& src, uint16_t protocol,
  141. BT_HDR* p_buf, bool ext) {
  142. /* copy all other params before the data */
  143. ((tBTA_PAN_DATA_PARAMS*)p_buf)->src = src;
  144. ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst = dst;
  145. ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol = protocol;
  146. ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext = ext;
  147. p_buf->layer_specific = handle;
  148. p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
  149. bta_sys_sendmsg(p_buf);
  150. }
  151. /*******************************************************************************
  152. *
  153. * Function bta_pan_ci_readbuf
  154. *
  155. * Description
  156. *
  157. *
  158. * Returns void
  159. *
  160. ******************************************************************************/
  161. BT_HDR* bta_pan_ci_readbuf(uint16_t handle, RawAddress& src, RawAddress& dst,
  162. uint16_t* p_protocol, bool* p_ext, bool* p_forward) {
  163. tBTA_PAN_SCB* p_scb = bta_pan_scb_by_handle(handle);
  164. BT_HDR* p_buf;
  165. if (p_scb == NULL) return NULL;
  166. p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_scb->data_queue);
  167. if (p_buf != NULL) {
  168. src = ((tBTA_PAN_DATA_PARAMS*)p_buf)->src;
  169. dst = ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst;
  170. *p_protocol = ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol;
  171. *p_ext = ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext;
  172. *p_forward = ((tBTA_PAN_DATA_PARAMS*)p_buf)->forward;
  173. }
  174. return p_buf;
  175. }
  176. /*******************************************************************************
  177. *
  178. * Function bta_pan_ci_set_mfilters
  179. *
  180. * Description This function is called to set multicast filters
  181. *
  182. *
  183. * Returns void
  184. *
  185. ******************************************************************************/
  186. void bta_pan_ci_set_mfilters(uint16_t handle, uint16_t num_mcast_filters,
  187. uint8_t* p_start_array, uint8_t* p_end_array) {
  188. PAN_SetMulticastFilters(handle, num_mcast_filters, p_start_array,
  189. p_end_array);
  190. }
  191. /*******************************************************************************
  192. *
  193. * Function bta_pan_ci_set_mfilters
  194. *
  195. * Description This function is called to set protocol filters
  196. *
  197. *
  198. * Returns void
  199. *
  200. ******************************************************************************/
  201. void bta_pan_ci_set_pfilters(uint16_t handle, uint16_t num_filters,
  202. uint16_t* p_start_array, uint16_t* p_end_array) {
  203. PAN_SetProtocolFilters(handle, num_filters, p_start_array, p_end_array);
  204. }
  205. #else
  206. void bta_pan_ci_tx_ready(UNUSED_ATTR uint16_t handle) {}
  207. void bta_pan_ci_rx_ready(UNUSED_ATTR uint16_t handle) {}
  208. void bta_pan_ci_tx_flow(UNUSED_ATTR uint16_t handle, UNUSED_ATTR bool enable) {}
  209. void bta_pan_ci_rx_writebuf(UNUSED_ATTR uint16_t handle,
  210. UNUSED_ATTR const RawAddress& src,
  211. UNUSED_ATTR const RawAddress& dst,
  212. UNUSED_ATTR uint16_t protocol,
  213. UNUSED_ATTR BT_HDR* p_buf, UNUSED_ATTR bool ext) {}
  214. BT_HDR* bta_pan_ci_readbuf(UNUSED_ATTR uint16_t handle,
  215. UNUSED_ATTR RawAddress& src,
  216. UNUSED_ATTR RawAddress& dst,
  217. UNUSED_ATTR uint16_t* p_protocol,
  218. UNUSED_ATTR bool* p_ext,
  219. UNUSED_ATTR bool* p_forward) {
  220. return NULL;
  221. }
  222. void bta_pan_ci_set_pfilters(UNUSED_ATTR uint16_t handle,
  223. UNUSED_ATTR uint16_t num_filters,
  224. UNUSED_ATTR uint16_t* p_start_array,
  225. UNUSED_ATTR uint16_t* p_end_array) {}
  226. void bta_pan_ci_set_mfilters(UNUSED_ATTR uint16_t handle,
  227. UNUSED_ATTR uint16_t num_mcast_filters,
  228. UNUSED_ATTR uint8_t* p_start_array,
  229. UNUSED_ATTR uint8_t* p_end_array) {}
  230. #endif /* BTA_PAN_API */