bta_pan_int.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 private interface file for the BTA data gateway.
  21. *
  22. ******************************************************************************/
  23. #ifndef BTA_PAN_INT_H
  24. #define BTA_PAN_INT_H
  25. #include "bta_pan_api.h"
  26. #include "bta_sys.h"
  27. #include "osi/include/fixed_queue.h"
  28. /*****************************************************************************
  29. * Constants
  30. ****************************************************************************/
  31. /* PAN events */
  32. enum {
  33. /* these events are handled by the state machine */
  34. BTA_PAN_API_CLOSE_EVT = BTA_SYS_EVT_START(BTA_ID_PAN),
  35. BTA_PAN_CI_TX_READY_EVT,
  36. BTA_PAN_CI_RX_READY_EVT,
  37. BTA_PAN_CI_TX_FLOW_EVT,
  38. BTA_PAN_CI_RX_WRITE_EVT,
  39. BTA_PAN_CI_RX_WRITEBUF_EVT,
  40. BTA_PAN_CONN_OPEN_EVT,
  41. BTA_PAN_CONN_CLOSE_EVT,
  42. BTA_PAN_BNEP_FLOW_ENABLE_EVT,
  43. BTA_PAN_RX_FROM_BNEP_READY_EVT,
  44. /* these events are handled outside of the state machine */
  45. BTA_PAN_API_ENABLE_EVT,
  46. BTA_PAN_API_DISABLE_EVT,
  47. BTA_PAN_API_SET_ROLE_EVT,
  48. BTA_PAN_API_OPEN_EVT
  49. };
  50. /* state machine states */
  51. enum { BTA_PAN_IDLE_ST, BTA_PAN_OPEN_ST, BTA_PAN_CLOSING_ST };
  52. /*****************************************************************************
  53. * Data types
  54. ****************************************************************************/
  55. /* data type for BTA_PAN_API_ENABLE_EVT */
  56. typedef struct {
  57. BT_HDR hdr; /* Event header */
  58. tBTA_PAN_CBACK* p_cback; /* PAN callback function */
  59. } tBTA_PAN_API_ENABLE;
  60. /* data type for BTA_PAN_API_REG_ROLE_EVT */
  61. typedef struct {
  62. BT_HDR hdr; /* Event header */
  63. char user_name[BTA_SERVICE_NAME_LEN + 1]; /* Service name */
  64. char gn_name[BTA_SERVICE_NAME_LEN + 1]; /* Service name */
  65. char nap_name[BTA_SERVICE_NAME_LEN + 1]; /* Service name */
  66. tBTA_PAN_ROLE role;
  67. uint8_t user_app_id;
  68. uint8_t gn_app_id;
  69. uint8_t nap_app_id;
  70. tBTA_SEC user_sec_mask; /* Security mask */
  71. tBTA_SEC gn_sec_mask; /* Security mask */
  72. tBTA_SEC nap_sec_mask; /* Security mask */
  73. } tBTA_PAN_API_SET_ROLE;
  74. /* data type for BTA_PAN_API_OPEN_EVT */
  75. typedef struct {
  76. BT_HDR hdr; /* Event header */
  77. tBTA_PAN_ROLE local_role; /* local role */
  78. tBTA_PAN_ROLE peer_role; /* peer role */
  79. RawAddress bd_addr; /* peer bdaddr */
  80. } tBTA_PAN_API_OPEN;
  81. /* data type for BTA_PAN_CI_TX_FLOW_EVT */
  82. typedef struct {
  83. BT_HDR hdr; /* Event header */
  84. bool enable; /* Flow control setting */
  85. } tBTA_PAN_CI_TX_FLOW;
  86. /* data type for BTA_PAN_CONN_OPEN_EVT */
  87. typedef struct {
  88. BT_HDR hdr; /* Event header */
  89. tPAN_RESULT result;
  90. } tBTA_PAN_CONN;
  91. /* union of all data types */
  92. typedef union {
  93. BT_HDR hdr;
  94. tBTA_PAN_API_ENABLE api_enable;
  95. tBTA_PAN_API_SET_ROLE api_set_role;
  96. tBTA_PAN_API_OPEN api_open;
  97. tBTA_PAN_CI_TX_FLOW ci_tx_flow;
  98. tBTA_PAN_CONN conn;
  99. } tBTA_PAN_DATA;
  100. /* state machine control block */
  101. typedef struct {
  102. RawAddress bd_addr; /* peer bdaddr */
  103. fixed_queue_t*
  104. data_queue; /* Queue of buffers waiting to be passed to application */
  105. uint16_t handle; /* BTA PAN/BNEP handle */
  106. bool in_use; /* scb in use */
  107. tBTA_SEC sec_mask; /* Security mask */
  108. bool pan_flow_enable; /* BNEP flow control state */
  109. bool app_flow_enable; /* Application flow control state */
  110. uint8_t state; /* State machine state */
  111. tBTA_PAN_ROLE local_role; /* local role */
  112. tBTA_PAN_ROLE peer_role; /* peer role */
  113. uint8_t app_id; /* application id for the connection */
  114. } tBTA_PAN_SCB;
  115. /* main control block */
  116. typedef struct {
  117. tBTA_PAN_SCB scb[BTA_PAN_NUM_CONN]; /* state machine control blocks */
  118. tBTA_PAN_CBACK* p_cback; /* PAN callback function */
  119. uint8_t app_id[3]; /* application id for PAN roles */
  120. uint8_t flow_mask; /* Data flow mask */
  121. uint8_t q_level; /* queue level set by application for TX data */
  122. } tBTA_PAN_CB;
  123. /* pan data param */
  124. typedef struct {
  125. BT_HDR hdr;
  126. RawAddress src;
  127. RawAddress dst;
  128. uint16_t protocol;
  129. bool ext;
  130. bool forward;
  131. } tBTA_PAN_DATA_PARAMS;
  132. /*****************************************************************************
  133. * Global data
  134. ****************************************************************************/
  135. /* PAN control block */
  136. extern tBTA_PAN_CB bta_pan_cb;
  137. /*****************************************************************************
  138. * Function prototypes
  139. ****************************************************************************/
  140. extern tBTA_PAN_SCB* bta_pan_scb_alloc(void);
  141. extern void bta_pan_scb_dealloc(tBTA_PAN_SCB* p_scb);
  142. extern uint8_t bta_pan_scb_to_idx(tBTA_PAN_SCB* p_scb);
  143. extern tBTA_PAN_SCB* bta_pan_scb_by_handle(uint16_t handle);
  144. extern bool bta_pan_hdl_event(BT_HDR* p_msg);
  145. /* action functions */
  146. extern void bta_pan_enable(tBTA_PAN_DATA* p_data);
  147. extern void bta_pan_disable(void);
  148. extern void bta_pan_set_role(tBTA_PAN_DATA* p_data);
  149. extern void bta_pan_open(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  150. extern void bta_pan_api_close(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  151. extern void bta_pan_set_shutdown(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  152. extern void bta_pan_rx_path(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  153. extern void bta_pan_tx_path(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  154. extern void bta_pan_tx_flow(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  155. extern void bta_pan_conn_open(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  156. extern void bta_pan_conn_close(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  157. extern void bta_pan_writebuf(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  158. extern void bta_pan_write_buf(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  159. extern void bta_pan_free_buf(tBTA_PAN_SCB* p_scb, tBTA_PAN_DATA* p_data);
  160. #endif /* BTA_PAN_INT_H */