bnep_api.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /******************************************************************************
  2. *
  3. * Copyright 2001-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 interface file contains the interface to the Bluetooth Network
  21. * Encapsilation Protocol (BNEP).
  22. *
  23. ******************************************************************************/
  24. #ifndef BNEP_API_H
  25. #define BNEP_API_H
  26. #include "l2c_api.h"
  27. /*****************************************************************************
  28. * Constants
  29. ****************************************************************************/
  30. /* Define the minimum offset needed in a GKI buffer for
  31. * sending BNEP packets. Note, we are currently not sending
  32. * extension headers, but may in the future, so allow
  33. * space for them
  34. */
  35. #define BNEP_MINIMUM_OFFSET (15 + L2CAP_MIN_OFFSET)
  36. #define BNEP_INVALID_HANDLE 0xFFFF
  37. /*****************************************************************************
  38. * Type Definitions
  39. ****************************************************************************/
  40. /* Define the result codes from BNEP
  41. */
  42. enum {
  43. BNEP_SUCCESS, /* Success */
  44. BNEP_CONN_DISCONNECTED, /* Connection terminated */
  45. BNEP_NO_RESOURCES, /* No resources */
  46. BNEP_MTU_EXCEDED, /* Attempt to write long data */
  47. BNEP_INVALID_OFFSET, /* Insufficient offset in GKI buffer */
  48. BNEP_CONN_FAILED, /* Connection failed */
  49. BNEP_CONN_FAILED_CFG, /* Connection failed cos of config */
  50. BNEP_CONN_FAILED_SRC_UUID, /* Connection failed wrong source UUID */
  51. BNEP_CONN_FAILED_DST_UUID, /* Connection failed wrong destination UUID */
  52. BNEP_CONN_FAILED_UUID_SIZE, /* Connection failed wrong size UUID */
  53. BNEP_Q_SIZE_EXCEEDED, /* Too many buffers to dest */
  54. BNEP_TOO_MANY_FILTERS, /* Too many local filters specified */
  55. BNEP_SET_FILTER_FAIL, /* Set Filter failed */
  56. BNEP_WRONG_HANDLE, /* Wrong handle for the connection */
  57. BNEP_WRONG_STATE, /* Connection is in wrong state */
  58. BNEP_SECURITY_FAIL, /* Failed because of security */
  59. BNEP_IGNORE_CMD, /* To ignore the rcvd command */
  60. BNEP_TX_FLOW_ON, /* tx data flow enabled */
  61. BNEP_TX_FLOW_OFF /* tx data flow disabled */
  62. };
  63. typedef uint8_t tBNEP_RESULT;
  64. /***************************
  65. * Callback Functions
  66. ***************************/
  67. /* Connection state change callback prototype. Parameters are
  68. * Connection handle
  69. * BD Address of remote
  70. * Connection state change result
  71. * BNEP_SUCCESS indicates connection is success
  72. * All values are used to indicate the reason for failure
  73. * Flag to indicate if it is just a role change
  74. */
  75. typedef void(tBNEP_CONN_STATE_CB)(uint16_t handle, const RawAddress& rem_bda,
  76. tBNEP_RESULT result, bool is_role_change);
  77. /* Connection indication callback prototype. Parameters are
  78. * BD Address of remote, remote UUID and local UUID
  79. * and flag to indicate role change and handle to the connection
  80. * When BNEP calls this function profile should
  81. * use BNEP_ConnectResp call to accept or reject the request
  82. */
  83. typedef void(tBNEP_CONNECT_IND_CB)(uint16_t handle, const RawAddress& bd_addr,
  84. const bluetooth::Uuid& remote_uuid,
  85. const bluetooth::Uuid& local_uuid,
  86. bool is_role_change);
  87. /* Data buffer received indication callback prototype. Parameters are
  88. * Handle to the connection
  89. * Source BD/Ethernet Address
  90. * Dest BD/Ethernet address
  91. * Protocol
  92. * Pointer to the buffer
  93. * Flag to indicate whether extension headers to be forwarded are
  94. * present
  95. */
  96. typedef void(tBNEP_DATA_BUF_CB)(uint16_t handle, const RawAddress& src,
  97. const RawAddress& dst, uint16_t protocol,
  98. BT_HDR* p_buf, bool fw_ext_present);
  99. /* Data received indication callback prototype. Parameters are
  100. * Handle to the connection
  101. * Source BD/Ethernet Address
  102. * Dest BD/Ethernet address
  103. * Protocol
  104. * Pointer to the beginning of the data
  105. * Length of data
  106. * Flag to indicate whether extension headers to be forwarded are
  107. * present
  108. */
  109. typedef void(tBNEP_DATA_IND_CB)(uint16_t handle, const RawAddress& src,
  110. const RawAddress& dst, uint16_t protocol,
  111. uint8_t* p_data, uint16_t len,
  112. bool fw_ext_present);
  113. /* Flow control callback for TX data. Parameters are
  114. * Handle to the connection
  115. * Event flow status
  116. */
  117. typedef void(tBNEP_TX_DATA_FLOW_CB)(uint16_t handle, tBNEP_RESULT event);
  118. /* Filters received indication callback prototype. Parameters are
  119. * Handle to the connection
  120. * true if the cb is called for indication
  121. * Ignore this if it is indication, otherwise it is the result
  122. * for the filter set operation performed by the local
  123. * device
  124. * Number of protocol filters present
  125. * Pointer to the filters start. Filters are present in pairs
  126. * of start of the range and end of the range.
  127. * They will be present in big endian order. First
  128. * two bytes will be starting of the first range and
  129. * next two bytes will be ending of the range.
  130. */
  131. typedef void(tBNEP_FILTER_IND_CB)(uint16_t handle, bool indication,
  132. tBNEP_RESULT result, uint16_t num_filters,
  133. uint8_t* p_filters);
  134. /* Multicast Filters received indication callback prototype. Parameters are
  135. * Handle to the connection
  136. * true if the cb is called for indication
  137. * Ignore this if it is indication, otherwise it is the result
  138. * for the filter set operation performed by the local
  139. * device
  140. * Number of multicast filters present
  141. * Pointer to the filters start. Filters are present in pairs
  142. * of start of the range and end of the range.
  143. * First six bytes will be starting of the first range and
  144. * next six bytes will be ending of the range.
  145. */
  146. typedef void(tBNEP_MFILTER_IND_CB)(uint16_t handle, bool indication,
  147. tBNEP_RESULT result, uint16_t num_mfilters,
  148. uint8_t* p_mfilters);
  149. /* This is the structure used by profile to register with BNEP */
  150. typedef struct {
  151. tBNEP_CONNECT_IND_CB* p_conn_ind_cb; /* To indicate the conn request */
  152. tBNEP_CONN_STATE_CB* p_conn_state_cb; /* To indicate conn state change */
  153. tBNEP_DATA_IND_CB* p_data_ind_cb; /* To pass the data received */
  154. tBNEP_DATA_BUF_CB* p_data_buf_cb; /* To pass the data buffer received */
  155. tBNEP_TX_DATA_FLOW_CB* p_tx_data_flow_cb; /* data flow callback */
  156. tBNEP_FILTER_IND_CB*
  157. p_filter_ind_cb; /* To indicate that peer set protocol filters */
  158. tBNEP_MFILTER_IND_CB*
  159. p_mfilter_ind_cb; /* To indicate that peer set mcast filters */
  160. } tBNEP_REGISTER;
  161. /* This is the structure used by profile to get the status of BNEP */
  162. typedef struct {
  163. #define BNEP_STATUS_FAILE 0
  164. #define BNEP_STATUS_CONNECTED 1
  165. uint8_t con_status;
  166. uint16_t l2cap_cid;
  167. RawAddress rem_bda;
  168. uint16_t rem_mtu_size;
  169. uint16_t xmit_q_depth;
  170. uint16_t sent_num_filters;
  171. uint16_t sent_mcast_filters;
  172. uint16_t rcvd_num_filters;
  173. uint16_t rcvd_mcast_filters;
  174. bluetooth::Uuid src_uuid;
  175. bluetooth::Uuid dst_uuid;
  176. } tBNEP_STATUS;
  177. /*****************************************************************************
  178. * External Function Declarations
  179. ****************************************************************************/
  180. /*******************************************************************************
  181. *
  182. * Function BNEP_Register
  183. *
  184. * Description This function is called by the upper layer to register
  185. * its callbacks with BNEP
  186. *
  187. * Parameters: p_reg_info - contains all callback function pointers
  188. *
  189. *
  190. * Returns BNEP_SUCCESS if registered successfully
  191. * BNEP_FAILURE if connection state callback is missing
  192. *
  193. ******************************************************************************/
  194. extern tBNEP_RESULT BNEP_Register(tBNEP_REGISTER* p_reg_info);
  195. /*******************************************************************************
  196. *
  197. * Function BNEP_Deregister
  198. *
  199. * Description This function is called by the upper layer to de-register
  200. * its callbacks.
  201. *
  202. * Parameters: void
  203. *
  204. *
  205. * Returns void
  206. *
  207. ******************************************************************************/
  208. extern void BNEP_Deregister(void);
  209. /*******************************************************************************
  210. *
  211. * Function BNEP_Connect
  212. *
  213. * Description This function creates a BNEP connection to a remote
  214. * device.
  215. *
  216. * Parameters: p_rem_addr - BD_ADDR of the peer
  217. * src_uuid - source uuid for the connection
  218. * dst_uuid - destination uuid for the connection
  219. * p_handle - pointer to return the handle for the connection
  220. *
  221. * Returns BNEP_SUCCESS if connection started
  222. * BNEP_NO_RESOURCES if no resources
  223. *
  224. ******************************************************************************/
  225. extern tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda,
  226. const bluetooth::Uuid& src_uuid,
  227. const bluetooth::Uuid& dst_uuid,
  228. uint16_t* p_handle);
  229. /*******************************************************************************
  230. *
  231. * Function BNEP_ConnectResp
  232. *
  233. * Description This function is called in responce to connection indication
  234. *
  235. *
  236. * Parameters: handle - handle given in the connection indication
  237. * resp - responce for the connection indication
  238. *
  239. * Returns BNEP_SUCCESS if connection started
  240. * BNEP_WRONG_HANDLE if the connection is not found
  241. * BNEP_WRONG_STATE if the responce is not expected
  242. *
  243. ******************************************************************************/
  244. extern tBNEP_RESULT BNEP_ConnectResp(uint16_t handle, tBNEP_RESULT resp);
  245. /*******************************************************************************
  246. *
  247. * Function BNEP_Disconnect
  248. *
  249. * Description This function is called to close the specified connection.
  250. *
  251. * Parameters: handle - handle of the connection
  252. *
  253. * Returns BNEP_SUCCESS if connection is disconnected
  254. * BNEP_WRONG_HANDLE if no connection is not found
  255. *
  256. ******************************************************************************/
  257. extern tBNEP_RESULT BNEP_Disconnect(uint16_t handle);
  258. /*******************************************************************************
  259. *
  260. * Function BNEP_WriteBuf
  261. *
  262. * Description This function sends data in a GKI buffer on BNEP connection
  263. *
  264. * Parameters: handle - handle of the connection to write
  265. * p_dest_addr - BD_ADDR/Ethernet addr of the destination
  266. * p_buf - pointer to address of buffer with data
  267. * protocol - protocol type of the packet
  268. * p_src_addr - (optional) BD_ADDR/ethernet address of the
  269. * source (should be NULL if it is the local BD
  270. * Addr)
  271. * fw_ext_present - forwarded extensions present
  272. *
  273. * Returns: BNEP_WRONG_HANDLE - if passed handle is not valid
  274. * BNEP_MTU_EXCEDED - If the data length is greater
  275. * than MTU
  276. * BNEP_IGNORE_CMD - If the packet is filtered out
  277. * BNEP_Q_SIZE_EXCEEDED - If the Tx Q is full
  278. * BNEP_SUCCESS - If written successfully
  279. *
  280. ******************************************************************************/
  281. extern tBNEP_RESULT BNEP_WriteBuf(uint16_t handle,
  282. const RawAddress& p_dest_addr, BT_HDR* p_buf,
  283. uint16_t protocol,
  284. const RawAddress* p_src_addr,
  285. bool fw_ext_present);
  286. /*******************************************************************************
  287. *
  288. * Function BNEP_Write
  289. *
  290. * Description This function sends data over a BNEP connection
  291. *
  292. * Parameters: handle - handle of the connection to write
  293. * p_dest_addr - BD_ADDR/Ethernet addr of the destination
  294. * p_data - pointer to data start
  295. * protocol - protocol type of the packet
  296. * p_src_addr - (optional) BD_ADDR/ethernet address of the
  297. * source (should be NULL if it is the local BD
  298. * Addr)
  299. * fw_ext_present - forwarded extensions present
  300. *
  301. * Returns: BNEP_WRONG_HANDLE - if passed handle is not valid
  302. * BNEP_MTU_EXCEDED - If the data length is greater than
  303. * the MTU
  304. * BNEP_IGNORE_CMD - If the packet is filtered out
  305. * BNEP_Q_SIZE_EXCEEDED - If the Tx Q is full
  306. * BNEP_NO_RESOURCES - If not able to allocate a buffer
  307. * BNEP_SUCCESS - If written successfully
  308. *
  309. ******************************************************************************/
  310. extern tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& p_dest_addr,
  311. uint8_t* p_data, uint16_t len, uint16_t protocol,
  312. const RawAddress* p_src_addr,
  313. bool fw_ext_present);
  314. /*******************************************************************************
  315. *
  316. * Function BNEP_SetProtocolFilters
  317. *
  318. * Description This function sets the protocol filters on peer device
  319. *
  320. * Parameters: handle - Handle for the connection
  321. * num_filters - total number of filter ranges
  322. * p_start_array - Array of beginings of all protocol ranges
  323. * p_end_array - Array of ends of all protocol ranges
  324. *
  325. * Returns BNEP_WRONG_HANDLE - if the connection handle is
  326. * not valid
  327. * BNEP_SET_FILTER_FAIL - if the connection is in the
  328. * wrong state
  329. * BNEP_TOO_MANY_FILTERS - if too many filters
  330. * BNEP_SUCCESS - if request sent successfully
  331. *
  332. ******************************************************************************/
  333. extern tBNEP_RESULT BNEP_SetProtocolFilters(uint16_t handle,
  334. uint16_t num_filters,
  335. uint16_t* p_start_array,
  336. uint16_t* p_end_array);
  337. /*******************************************************************************
  338. *
  339. * Function BNEP_SetMulticastFilters
  340. *
  341. * Description This function sets the filters for multicast addresses for
  342. * BNEP.
  343. *
  344. * Parameters: handle - Handle for the connection
  345. * num_filters - total number of filter ranges
  346. * p_start_array - Pointer to sequence of beginings of all
  347. * multicast address ranges
  348. * p_end_array - Pointer to sequence of ends of all
  349. * multicast address ranges
  350. *
  351. * Returns BNEP_WRONG_HANDLE - if the connection handle is
  352. * not valid
  353. * BNEP_SET_FILTER_FAIL - if the connection is in the
  354. * wrong state
  355. * BNEP_TOO_MANY_FILTERS - if too many filters
  356. * BNEP_SUCCESS - if request sent successfully
  357. *
  358. ******************************************************************************/
  359. extern tBNEP_RESULT BNEP_SetMulticastFilters(uint16_t handle,
  360. uint16_t num_filters,
  361. uint8_t* p_start_array,
  362. uint8_t* p_end_array);
  363. /*******************************************************************************
  364. *
  365. * Function BNEP_SetTraceLevel
  366. *
  367. * Description This function sets the trace level for BNEP. If called with
  368. * a value of 0xFF, it simply reads the current trace level.
  369. *
  370. * Returns the new (current) trace level
  371. *
  372. ******************************************************************************/
  373. extern uint8_t BNEP_SetTraceLevel(uint8_t new_level);
  374. /*******************************************************************************
  375. *
  376. * Function BNEP_Init
  377. *
  378. * Description This function initializes the BNEP unit. It should be called
  379. * before accessing any other APIs to initialize the control
  380. * block
  381. *
  382. * Returns void
  383. *
  384. ******************************************************************************/
  385. extern void BNEP_Init(void);
  386. /*******************************************************************************
  387. *
  388. * Function BNEP_GetStatus
  389. *
  390. * Description This function gets the status information for BNEP
  391. * connection
  392. *
  393. * Returns BNEP_SUCCESS - if the status is available
  394. * BNEP_NO_RESOURCES - if no structure is passed for
  395. * output
  396. * BNEP_WRONG_HANDLE - if the handle is invalid
  397. * BNEP_WRONG_STATE - if not in connected state
  398. *
  399. ******************************************************************************/
  400. extern tBNEP_RESULT BNEP_GetStatus(uint16_t handle, tBNEP_STATUS* p_status);
  401. #endif