bta_pan_api.cc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 of the API for PAN subsystem of BTA,
  21. * Broadcom's Bluetooth application layer for mobile phones.
  22. *
  23. ******************************************************************************/
  24. #include <string.h>
  25. #include "bt_target.h"
  26. #include "bt_common.h"
  27. #include "bt_utils.h"
  28. #include "bta_api.h"
  29. #include "bta_pan_api.h"
  30. #include "bta_pan_int.h"
  31. #include "bta_sys.h"
  32. #include "osi/include/osi.h"
  33. #include "pan_api.h"
  34. #if (BTA_PAN_INCLUDED == TRUE)
  35. static const tBTA_SYS_REG bta_pan_reg = {bta_pan_hdl_event, BTA_PanDisable};
  36. /*******************************************************************************
  37. *
  38. * Function BTA_PanEnable
  39. *
  40. * Description Enable PAN service. This function must be
  41. * called before any other functions in the PAN API are called.
  42. * When the enable operation is complete the callback function
  43. * will be called with a BTA_PAN_ENABLE_EVT.
  44. *
  45. * Returns void
  46. *
  47. ******************************************************************************/
  48. void BTA_PanEnable(tBTA_PAN_CBACK p_cback) {
  49. tBTA_PAN_API_ENABLE* p_buf =
  50. (tBTA_PAN_API_ENABLE*)osi_malloc(sizeof(tBTA_PAN_API_ENABLE));
  51. /* register with BTA system manager */
  52. bta_sys_register(BTA_ID_PAN, &bta_pan_reg);
  53. p_buf->hdr.event = BTA_PAN_API_ENABLE_EVT;
  54. p_buf->p_cback = p_cback;
  55. bta_sys_sendmsg(p_buf);
  56. }
  57. /*******************************************************************************
  58. *
  59. * Function BTA_PanDisable
  60. *
  61. * Description Disables PAN service.
  62. *
  63. *
  64. * Returns void
  65. *
  66. ******************************************************************************/
  67. void BTA_PanDisable(void) {
  68. BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
  69. bta_sys_deregister(BTA_ID_PAN);
  70. p_buf->event = BTA_PAN_API_DISABLE_EVT;
  71. bta_sys_sendmsg(p_buf);
  72. }
  73. /*******************************************************************************
  74. *
  75. * Function BTA_PanSetRole
  76. *
  77. * Description Sets PAN roles. When the enable operation is complete
  78. * the callback function will be called with a
  79. * BTA_PAN_SET_ROLE_EVT.
  80. *
  81. * Returns void
  82. *
  83. ******************************************************************************/
  84. void BTA_PanSetRole(tBTA_PAN_ROLE role, tBTA_PAN_ROLE_INFO* p_user_info,
  85. tBTA_PAN_ROLE_INFO* p_gn_info,
  86. tBTA_PAN_ROLE_INFO* p_nap_info) {
  87. tBTA_PAN_API_SET_ROLE* p_buf =
  88. (tBTA_PAN_API_SET_ROLE*)osi_calloc(sizeof(tBTA_PAN_API_SET_ROLE));
  89. p_buf->hdr.event = BTA_PAN_API_SET_ROLE_EVT;
  90. p_buf->role = role;
  91. if (p_user_info && (role & BTA_PAN_ROLE_PANU)) {
  92. if (p_user_info->p_srv_name)
  93. strlcpy(p_buf->user_name, p_user_info->p_srv_name, BTA_SERVICE_NAME_LEN);
  94. p_buf->user_app_id = p_user_info->app_id;
  95. p_buf->user_sec_mask = p_user_info->sec_mask;
  96. }
  97. if (p_gn_info && (role & BTA_PAN_ROLE_GN)) {
  98. if (p_gn_info->p_srv_name)
  99. strlcpy(p_buf->gn_name, p_gn_info->p_srv_name, BTA_SERVICE_NAME_LEN);
  100. p_buf->gn_app_id = p_gn_info->app_id;
  101. p_buf->gn_sec_mask = p_gn_info->sec_mask;
  102. }
  103. if (p_nap_info && (role & BTA_PAN_ROLE_NAP)) {
  104. if (p_nap_info->p_srv_name)
  105. strlcpy(p_buf->nap_name, p_nap_info->p_srv_name, BTA_SERVICE_NAME_LEN);
  106. p_buf->nap_app_id = p_nap_info->app_id;
  107. p_buf->nap_sec_mask = p_nap_info->sec_mask;
  108. }
  109. bta_sys_sendmsg(p_buf);
  110. }
  111. /*******************************************************************************
  112. *
  113. * Function BTA_PanOpen
  114. *
  115. * Description Opens a connection to a peer device.
  116. * When connection is open callback function is called
  117. * with a BTA_PAN_OPEN_EVT.
  118. *
  119. *
  120. * Returns void
  121. *
  122. ******************************************************************************/
  123. void BTA_PanOpen(const RawAddress& bd_addr, tBTA_PAN_ROLE local_role,
  124. tBTA_PAN_ROLE peer_role) {
  125. tBTA_PAN_API_OPEN* p_buf =
  126. (tBTA_PAN_API_OPEN*)osi_malloc(sizeof(tBTA_PAN_API_OPEN));
  127. p_buf->hdr.event = BTA_PAN_API_OPEN_EVT;
  128. p_buf->local_role = local_role;
  129. p_buf->peer_role = peer_role;
  130. p_buf->bd_addr = bd_addr;
  131. bta_sys_sendmsg(p_buf);
  132. }
  133. /*******************************************************************************
  134. *
  135. * Function BTA_PanClose
  136. *
  137. * Description Close a PAN connection to a peer device.
  138. *
  139. *
  140. * Returns void
  141. *
  142. ******************************************************************************/
  143. void BTA_PanClose(uint16_t handle) {
  144. BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
  145. p_buf->event = BTA_PAN_API_CLOSE_EVT;
  146. p_buf->layer_specific = handle;
  147. bta_sys_sendmsg(p_buf);
  148. }
  149. #else
  150. void BTA_PanEnable(UNUSED_ATTR tBTA_PAN_CBACK p_cback) {}
  151. void BTA_PanDisable(void) {}
  152. void BTA_PanSetRole(UNUSED_ATTR tBTA_PAN_ROLE role,
  153. UNUSED_ATTR tBTA_PAN_ROLE_INFO* p_user_info,
  154. UNUSED_ATTR tBTA_PAN_ROLE_INFO* p_gn_info,
  155. UNUSED_ATTR tBTA_PAN_ROLE_INFO* p_nap_info) {}
  156. void BTA_PanOpen(UNUSED_ATTR const RawAddress& bd_addr,
  157. UNUSED_ATTR tBTA_PAN_ROLE local_role,
  158. UNUSED_ATTR tBTA_PAN_ROLE peer_role) {}
  159. void BTA_PanClose(UNUSED_ATTR uint16_t handle) {}
  160. #endif /* BTA_PAN_INCLUDED */