gap_api.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2009-2013 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. #ifndef GAP_API_H
  19. #define GAP_API_H
  20. #include "sdpdefs.h"
  21. #include "profiles_api.h"
  22. #include "btm_api.h"
  23. #include "l2c_api.h"
  24. /*****************************************************************************
  25. ** Constants
  26. *****************************************************************************/
  27. /*** GAP Error and Status Codes ***/
  28. #define GAP_UNSUPPORTED (GAP_ERR_GRP + 0x01) /* Unsupported call */
  29. #define GAP_EOINQDB (GAP_ERR_GRP + 0x02) /* End of inquiry database marker */
  30. #define GAP_ERR_BUSY (GAP_ERR_GRP + 0x03) /* The requested function was busy */
  31. #define GAP_ERR_NO_CTRL_BLK (GAP_ERR_GRP + 0x04) /* No control blocks available */
  32. #define GAP_ERR_STARTING_CMD (GAP_ERR_GRP + 0x05) /* Error occurred while initiating the command */
  33. #define GAP_NO_BDADDR_REC (GAP_ERR_GRP + 0x06) /* No Inquiry DB record for BD_ADDR */
  34. #define GAP_ERR_ILL_MODE (GAP_ERR_GRP + 0x07) /* An illegal mode parameter was detected */
  35. #define GAP_ERR_ILL_INQ_TIME (GAP_ERR_GRP + 0x08) /* An illegal time parameter was detected */
  36. #define GAP_ERR_ILL_PARM (GAP_ERR_GRP + 0x09) /* An illegal parameter was detected */
  37. #define GAP_ERR_REM_NAME (GAP_ERR_GRP + 0x0a) /* Error starting the remote device name request */
  38. #define GAP_CMD_INITIATED (GAP_ERR_GRP + 0x0b) /* The GAP command was started (result pending) */
  39. #define GAP_DEVICE_NOT_UP (GAP_ERR_GRP + 0x0c) /* The device was not up; the request was not executed */
  40. #define GAP_BAD_BD_ADDR (GAP_ERR_GRP + 0x0d) /* The bd addr passed in was not found or invalid */
  41. #define GAP_ERR_BAD_HANDLE (GAP_ERR_GRP + 0x0e) /* Bad GAP handle */
  42. #define GAP_ERR_BUF_OFFSET (GAP_ERR_GRP + 0x0f) /* Buffer offset invalid */
  43. #define GAP_ERR_BAD_STATE (GAP_ERR_GRP + 0x10) /* Connection is in invalid state */
  44. #define GAP_NO_DATA_AVAIL (GAP_ERR_GRP + 0x11) /* No data available */
  45. #define GAP_ERR_CONGESTED (GAP_ERR_GRP + 0x12) /* BT stack is congested */
  46. #define GAP_ERR_SECURITY (GAP_ERR_GRP + 0x13) /* Security failed */
  47. #define GAP_ERR_PROCESSING (GAP_ERR_GRP + 0x14) /* General error processing BTM request */
  48. #define GAP_ERR_TIMEOUT (GAP_ERR_GRP + 0x15) /* Timeout occurred while processing cmd */
  49. #define GAP_EVT_CONN_OPENED 0x0100
  50. #define GAP_EVT_CONN_CLOSED 0x0101
  51. #define GAP_EVT_CONN_DATA_AVAIL 0x0102
  52. #define GAP_EVT_CONN_CONGESTED 0x0103
  53. #define GAP_EVT_CONN_UNCONGESTED 0x0104
  54. /* Values for 'chan_mode_mask' field */
  55. /* GAP_ConnOpen() - optional channels to negotiate */
  56. #define GAP_FCR_CHAN_OPT_BASIC L2CAP_FCR_CHAN_OPT_BASIC
  57. #define GAP_FCR_CHAN_OPT_ERTM L2CAP_FCR_CHAN_OPT_ERTM
  58. #define GAP_FCR_CHAN_OPT_STREAM L2CAP_FCR_CHAN_OPT_STREAM
  59. /*** used in connection variables and functions ***/
  60. #define GAP_INVALID_HANDLE 0xFFFF
  61. /* This is used to change the criteria for AMP */
  62. #define GAP_PROTOCOL_ID (UUID_PROTOCOL_UDP)
  63. #ifndef GAP_PREFER_CONN_INT_MAX
  64. #define GAP_PREFER_CONN_INT_MAX BTM_BLE_CONN_INT_MIN
  65. #endif
  66. #ifndef GAP_PREFER_CONN_INT_MIN
  67. #define GAP_PREFER_CONN_INT_MIN BTM_BLE_CONN_INT_MIN
  68. #endif
  69. #ifndef GAP_PREFER_CONN_LATENCY
  70. #define GAP_PREFER_CONN_LATENCY 0
  71. #endif
  72. #ifndef GAP_PREFER_CONN_SP_TOUT
  73. #define GAP_PREFER_CONN_SP_TOUT 2000
  74. #endif
  75. /*****************************************************************************
  76. ** Type Definitions
  77. *****************************************************************************/
  78. /*
  79. ** Callback function for connection services
  80. */
  81. typedef void (tGAP_CONN_CALLBACK) (UINT16 gap_handle, UINT16 event);
  82. /*
  83. ** Define the callback function prototypes. Parameters are specific
  84. ** to each event and are described below
  85. */
  86. typedef void (tGAP_CALLBACK) (UINT16 event, void *p_data);
  87. /* Definition of the GAP_FindAddrByName results structure */
  88. typedef struct {
  89. UINT16 status;
  90. BD_ADDR bd_addr;
  91. tBTM_BD_NAME devname;
  92. } tGAP_FINDADDR_RESULTS;
  93. typedef struct {
  94. UINT16 int_min;
  95. UINT16 int_max;
  96. UINT16 latency;
  97. UINT16 sp_tout;
  98. } tGAP_BLE_PREF_PARAM;
  99. typedef union {
  100. tGAP_BLE_PREF_PARAM conn_param;
  101. BD_ADDR reconn_bda;
  102. UINT16 icon;
  103. UINT8 *p_dev_name;
  104. UINT8 addr_resolution;
  105. } tGAP_BLE_ATTR_VALUE;
  106. typedef void (tGAP_BLE_CMPL_CBACK)(BOOLEAN status, BD_ADDR addr, UINT16 length, char *p_name);
  107. /*****************************************************************************
  108. ** External Function Declarations
  109. *****************************************************************************/
  110. /*** Functions for L2CAP connection interface ***/
  111. /*******************************************************************************
  112. **
  113. ** Function GAP_ConnOpen
  114. **
  115. ** Description This function is called to open a generic L2CAP connection.
  116. **
  117. ** Returns handle of the connection if successful, else GAP_INVALID_HANDLE
  118. **
  119. *******************************************************************************/
  120. extern UINT16 GAP_ConnOpen (char *p_serv_name, UINT8 service_id, BOOLEAN is_server,
  121. BD_ADDR p_rem_bda, UINT16 psm, tL2CAP_CFG_INFO *p_cfg,
  122. tL2CAP_ERTM_INFO *ertm_info,
  123. UINT16 security, UINT8 chan_mode_mask, tGAP_CONN_CALLBACK *p_cb);
  124. /*******************************************************************************
  125. **
  126. ** Function GAP_ConnClose
  127. **
  128. ** Description This function is called to close a connection.
  129. **
  130. ** Returns BT_PASS - closed OK
  131. ** GAP_ERR_BAD_HANDLE - invalid handle
  132. **
  133. *******************************************************************************/
  134. extern UINT16 GAP_ConnClose (UINT16 gap_handle);
  135. /*******************************************************************************
  136. **
  137. ** Function GAP_ConnReadData
  138. **
  139. ** Description GKI buffer unaware application will call this function
  140. ** after receiving GAP_EVT_RXDATA event. A data copy is made
  141. ** into the receive buffer parameter.
  142. **
  143. ** Returns BT_PASS - data read
  144. ** GAP_ERR_BAD_HANDLE - invalid handle
  145. ** GAP_NO_DATA_AVAIL - no data available
  146. **
  147. *******************************************************************************/
  148. extern UINT16 GAP_ConnReadData (UINT16 gap_handle, UINT8 *p_data,
  149. UINT16 max_len, UINT16 *p_len);
  150. /*******************************************************************************
  151. **
  152. ** Function GAP_GetRxQueueCnt
  153. **
  154. ** Description This function return number of bytes on the rx queue.
  155. **
  156. ** Parameters: handle - Handle returned in the GAP_ConnOpen
  157. ** p_rx_queue_count - Pointer to return queue count in.
  158. **
  159. **
  160. *******************************************************************************/
  161. extern int GAP_GetRxQueueCnt (UINT16 handle, UINT32 *p_rx_queue_count);
  162. /*******************************************************************************
  163. **
  164. ** Function GAP_ConnBTRead
  165. **
  166. ** Description GKI buffer aware applications will call this function after
  167. ** receiving an GAP_EVT_RXDATA event to process the incoming
  168. ** data buffer.
  169. **
  170. ** Returns BT_PASS - data read
  171. ** GAP_ERR_BAD_HANDLE - invalid handle
  172. ** GAP_NO_DATA_AVAIL - no data available
  173. **
  174. *******************************************************************************/
  175. extern UINT16 GAP_ConnBTRead (UINT16 gap_handle, BT_HDR **pp_buf);
  176. /*******************************************************************************
  177. **
  178. ** Function GAP_ConnBTWrite
  179. **
  180. ** Description GKI buffer aware applications can call this function to write data
  181. ** by passing a pointer to the GKI buffer of data.
  182. **
  183. ** Returns BT_PASS - data read
  184. ** GAP_ERR_BAD_HANDLE - invalid handle
  185. ** GAP_ERR_BAD_STATE - connection not established
  186. ** GAP_INVALID_BUF_OFFSET - buffer offset is invalid
  187. *******************************************************************************/
  188. extern UINT16 GAP_ConnBTWrite (UINT16 gap_handle, BT_HDR *p_buf);
  189. /*******************************************************************************
  190. **
  191. ** Function GAP_ConnWriteData
  192. **
  193. ** Description GKI buffer unaware application will call this function
  194. ** to send data to the connection. A data copy is made into a GKI
  195. ** buffer.
  196. **
  197. ** Returns BT_PASS - data read
  198. ** GAP_ERR_BAD_HANDLE - invalid handle
  199. ** GAP_ERR_BAD_STATE - connection not established
  200. ** GAP_CONGESTION - system is congested
  201. **
  202. *******************************************************************************/
  203. extern UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data,
  204. UINT16 max_len, UINT16 *p_len);
  205. /*******************************************************************************
  206. **
  207. ** Function GAP_ConnReconfig
  208. **
  209. ** Description Applications can call this function to reconfigure the connection.
  210. **
  211. ** Returns BT_PASS - config process started
  212. ** GAP_ERR_BAD_HANDLE - invalid handle
  213. **
  214. *******************************************************************************/
  215. extern UINT16 GAP_ConnReconfig (UINT16 gap_handle, tL2CAP_CFG_INFO *p_cfg);
  216. /*******************************************************************************
  217. **
  218. ** Function GAP_ConnSetIdleTimeout
  219. **
  220. ** Description Higher layers call this function to set the idle timeout for
  221. ** a connection, or for all future connections. The "idle timeout"
  222. ** is the amount of time that a connection can remain up with
  223. ** no L2CAP channels on it. A timeout of zero means that the
  224. ** connection will be torn down immediately when the last channel
  225. ** is removed. A timeout of 0xFFFF means no timeout. Values are
  226. ** in seconds.
  227. **
  228. ** Returns BT_PASS - config process started
  229. ** GAP_ERR_BAD_HANDLE - invalid handle
  230. **
  231. *******************************************************************************/
  232. extern UINT16 GAP_ConnSetIdleTimeout (UINT16 gap_handle, UINT16 timeout);
  233. /*******************************************************************************
  234. **
  235. ** Function GAP_ConnGetRemoteAddr
  236. **
  237. ** Description This function is called to get the remote BD address
  238. ** of a connection.
  239. **
  240. ** Returns BT_PASS - closed OK
  241. ** GAP_ERR_BAD_HANDLE - invalid handle
  242. **
  243. *******************************************************************************/
  244. extern UINT8 *GAP_ConnGetRemoteAddr (UINT16 gap_handle);
  245. /*******************************************************************************
  246. **
  247. ** Function GAP_ConnGetRemMtuSize
  248. **
  249. ** Description Returns the remote device's MTU size.
  250. **
  251. ** Returns UINT16 - maximum size buffer that can be transmitted to the peer
  252. **
  253. *******************************************************************************/
  254. extern UINT16 GAP_ConnGetRemMtuSize (UINT16 gap_handle);
  255. /*******************************************************************************
  256. **
  257. ** Function GAP_ConnGetL2CAPCid
  258. **
  259. ** Description Returns the L2CAP channel id
  260. **
  261. ** Parameters: handle - Handle of the connection
  262. **
  263. ** Returns UINT16 - The L2CAP channel id
  264. ** 0, if error
  265. **
  266. *******************************************************************************/
  267. extern UINT16 GAP_ConnGetL2CAPCid (UINT16 gap_handle);
  268. /*******************************************************************************
  269. **
  270. ** Function GAP_SetTraceLevel
  271. **
  272. ** Description This function sets the trace level for GAP. If called with
  273. ** a value of 0xFF, it simply returns the current trace level.
  274. **
  275. ** Returns The new or current trace level
  276. **
  277. *******************************************************************************/
  278. extern UINT8 GAP_SetTraceLevel (UINT8 new_level);
  279. /*******************************************************************************
  280. **
  281. ** Function GAP_Init
  282. **
  283. ** Description Initializes the control blocks used by GAP.
  284. ** This routine should not be called except once per
  285. ** stack invocation.
  286. **
  287. ** Returns Nothing
  288. **
  289. *******************************************************************************/
  290. extern void GAP_Init(void);
  291. #if (BLE_INCLUDED == TRUE)
  292. /*******************************************************************************
  293. **
  294. ** Function GAP_BleAttrDBUpdate
  295. **
  296. ** Description update GAP local BLE attribute database.
  297. **
  298. ** Returns Nothing
  299. **
  300. *******************************************************************************/
  301. extern void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value);
  302. /*******************************************************************************
  303. **
  304. ** Function GAP_BleReadPeerPrefConnParams
  305. **
  306. ** Description Start a process to read a connected peripheral's preferred
  307. ** connection parameters
  308. **
  309. ** Returns TRUE if read started, else FALSE if GAP is busy
  310. **
  311. *******************************************************************************/
  312. extern BOOLEAN GAP_BleReadPeerPrefConnParams (BD_ADDR peer_bda);
  313. /*******************************************************************************
  314. **
  315. ** Function GAP_BleReadPeerDevName
  316. **
  317. ** Description Start a process to read a connected peripheral's device name.
  318. **
  319. ** Returns TRUE if request accepted
  320. **
  321. *******************************************************************************/
  322. extern BOOLEAN GAP_BleReadPeerDevName (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK *p_cback);
  323. /*******************************************************************************
  324. **
  325. ** Function GAP_BleReadPeerAddressResolutionCap
  326. **
  327. ** Description Start a process to read peer address resolution capability
  328. **
  329. ** Returns TRUE if request accepted
  330. **
  331. *******************************************************************************/
  332. extern BOOLEAN GAP_BleReadPeerAddressResolutionCap (BD_ADDR peer_bda,
  333. tGAP_BLE_CMPL_CBACK *p_cback);
  334. /*******************************************************************************
  335. **
  336. ** Function GAP_BleCancelReadPeerDevName
  337. **
  338. ** Description Cancel reading a peripheral's device name.
  339. **
  340. ** Returns TRUE if request accepted
  341. **
  342. *******************************************************************************/
  343. extern BOOLEAN GAP_BleCancelReadPeerDevName (BD_ADDR peer_bda);
  344. #endif
  345. #endif /* GAP_API_H */