• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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 
19 #ifndef GAP_API_H
20 #define GAP_API_H
21 
22 #include <cstdint>
23 
24 #include "btm_api.h"
25 #include "l2c_api.h"
26 #include "l2cdefs.h"
27 #include "profiles_api.h"
28 #include "stack/include/bt_hdr.h"
29 #include "types/bt_transport.h"
30 #include "types/raw_address.h"
31 
32 /*****************************************************************************
33  *  Constants
34  ****************************************************************************/
35 /*** GAP Error and Status Codes ***/
36 /* An illegal parameter was detected */
37 #define GAP_ERR_ILL_PARM (GAP_ERR_GRP + 0x09)
38 
39 /* Bad GAP handle */
40 #define GAP_ERR_BAD_HANDLE (GAP_ERR_GRP + 0x0e)
41 /* Connection is in invalid state */
42 #define GAP_ERR_BAD_STATE (GAP_ERR_GRP + 0x10)
43 /* No data available */
44 #define GAP_NO_DATA_AVAIL (GAP_ERR_GRP + 0x11)
45 #define GAP_EVT_CONN_OPENED 0x0100
46 #define GAP_EVT_CONN_CLOSED 0x0101
47 #define GAP_EVT_CONN_DATA_AVAIL 0x0102
48 #define GAP_EVT_CONN_CONGESTED 0x0103
49 #define GAP_EVT_CONN_UNCONGESTED 0x0104
50 #define GAP_EVT_TX_EMPTY 0x0105
51 
52 /*** used in connection variables and functions ***/
53 #define GAP_INVALID_HANDLE 0xFFFF
54 
55 #ifndef GAP_PREFER_CONN_INT_MAX
56 #define GAP_PREFER_CONN_INT_MAX BTM_BLE_CONN_INT_MIN
57 #endif
58 
59 #ifndef GAP_PREFER_CONN_INT_MIN
60 #define GAP_PREFER_CONN_INT_MIN BTM_BLE_CONN_INT_MIN
61 #endif
62 
63 #ifndef GAP_PREFER_CONN_LATENCY
64 #define GAP_PREFER_CONN_LATENCY 0
65 #endif
66 
67 #ifndef GAP_PREFER_CONN_SP_TOUT
68 #define GAP_PREFER_CONN_SP_TOUT 2000
69 #endif
70 
71 struct tGAP_COC_CREDITS {
72   uint16_t credits_received;
73   uint16_t credit_count;
74 };
75 
76 union tGAP_CB_DATA {
77   tGAP_COC_CREDITS coc_credits;
78   uint16_t l2cap_result;
79 };
80 
81 /*****************************************************************************
82  *  Type Definitions
83  ****************************************************************************/
84 /*
85  * Callback function for connection services
86 */
87 typedef void(tGAP_CONN_CALLBACK)(uint16_t gap_handle, uint16_t event,
88                                  tGAP_CB_DATA* data);
89 
90 typedef struct {
91   uint16_t int_min;
92   uint16_t int_max;
93   uint16_t latency;
94   uint16_t sp_tout;
95 } tGAP_BLE_PREF_PARAM;
96 
97 typedef union {
98   tGAP_BLE_PREF_PARAM conn_param;
99   RawAddress reconn_bda;
100   uint16_t icon;
101   uint8_t* p_dev_name;
102   uint8_t addr_resolution;
103 
104 } tGAP_BLE_ATTR_VALUE;
105 
106 typedef void(tGAP_BLE_CMPL_CBACK)(bool status, const RawAddress& addr,
107                                   uint16_t length, char* p_name);
108 
109 /*****************************************************************************
110  *  External Function Declarations
111  ****************************************************************************/
112 
113 /*** Functions for L2CAP connection interface ***/
114 
115 /*******************************************************************************
116  *
117  * Function         GAP_ConnOpen
118  *
119  * Description      This function is called to open a generic L2CAP connection.
120  *
121  * Returns          handle of the connection if successful, else
122  *                  GAP_INVALID_HANDLE
123  *
124  ******************************************************************************/
125 uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
126                       bool is_server, const RawAddress* p_rem_bda, uint16_t psm,
127                       uint16_t le_mps, tL2CAP_CFG_INFO* p_cfg,
128                       tL2CAP_ERTM_INFO* ertm_info, uint16_t security,
129                       tGAP_CONN_CALLBACK* p_cb, tBT_TRANSPORT transport);
130 
131 /*******************************************************************************
132  *
133  * Function         GAP_ConnClose
134  *
135  * Description      This function is called to close a connection.
136  *
137  * Returns          BT_PASS             - closed OK
138  *                  GAP_ERR_BAD_HANDLE  - invalid handle
139  *
140  ******************************************************************************/
141 uint16_t GAP_ConnClose(uint16_t gap_handle);
142 
143 /*******************************************************************************
144  *
145  * Function         GAP_ConnReadData
146  *
147  * Description      GKI buffer unaware application will call this function
148  *                  after receiving GAP_EVT_RXDATA event. A data copy is made
149  *                  into the receive buffer parameter.
150  *
151  * Returns          BT_PASS             - data read
152  *                  GAP_ERR_BAD_HANDLE  - invalid handle
153  *                  GAP_NO_DATA_AVAIL   - no data available
154  *
155  ******************************************************************************/
156 uint16_t GAP_ConnReadData(uint16_t gap_handle, uint8_t* p_data,
157                           uint16_t max_len, uint16_t* p_len);
158 
159 /*******************************************************************************
160  *
161  * Function         GAP_GetRxQueueCnt
162  *
163  * Description      This function return number of bytes on the rx queue.
164  *
165  * Parameters:      handle     - Handle returned in the GAP_ConnOpen
166  *                  p_rx_queue_count - Pointer to return queue count in.
167  *
168  *
169  ******************************************************************************/
170 int GAP_GetRxQueueCnt(uint16_t handle, uint32_t* p_rx_queue_count);
171 
172 /*******************************************************************************
173  *
174  * Function         GAP_ConnWriteData
175  *
176  * Description      GKI buffer unaware application will call this function
177  *                  to send data to the connection. A data copy is made into a
178  *                  GKI buffer.
179  *
180  * Returns          BT_PASS                 - data read
181  *                  GAP_ERR_BAD_HANDLE      - invalid handle
182  *                  GAP_ERR_BAD_STATE       - connection not established
183  *                  GAP_CONGESTION          - system is congested
184  *
185  ******************************************************************************/
186 uint16_t GAP_ConnWriteData(uint16_t gap_handle, BT_HDR* msg);
187 
188 /*******************************************************************************
189  *
190  * Function         GAP_ConnGetRemoteAddr
191  *
192  * Description      This function is called to get the remote BD address
193  *                  of a connection.
194  *
195  * Returns          BT_PASS             - closed OK
196  *                  GAP_ERR_BAD_HANDLE  - invalid handle
197  *
198  ******************************************************************************/
199 const RawAddress* GAP_ConnGetRemoteAddr(uint16_t gap_handle);
200 
201 /*******************************************************************************
202  *
203  * Function         GAP_ConnGetRemMtuSize
204  *
205  * Description      Returns the remote device's MTU size.
206  *
207  * Returns          uint16_t - maximum size buffer that can be transmitted to
208  *                             the peer
209  *
210  ******************************************************************************/
211 uint16_t GAP_ConnGetRemMtuSize(uint16_t gap_handle);
212 
213 /*******************************************************************************
214  *
215  * Function         GAP_ConnGetL2CAPCid
216  *
217  * Description      Returns the L2CAP channel id
218  *
219  * Parameters:      handle      - Handle of the connection
220  *
221  * Returns          uint16_t    - The L2CAP channel id
222  *                  0, if error
223  *
224  ******************************************************************************/
225 uint16_t GAP_ConnGetL2CAPCid(uint16_t gap_handle);
226 
227 /*******************************************************************************
228  *
229  * Function         GAP_Init
230  *
231  * Description      Initializes the control blocks used by GAP.
232  *                  This routine should not be called except once per
233  *                      stack invocation.
234  *
235  * Returns          Nothing
236  *
237  ******************************************************************************/
238 void GAP_Init(void);
239 
240 /*******************************************************************************
241  *
242  * Function         GAP_BleAttrDBUpdate
243  *
244  * Description      update GAP local BLE attribute database.
245  *
246  * Returns          Nothing
247  *
248  ******************************************************************************/
249 void GAP_BleAttrDBUpdate(uint16_t attr_uuid, tGAP_BLE_ATTR_VALUE* p_value);
250 
251 /*******************************************************************************
252  *
253  * Function         GAP_BleReadPeerPrefConnParams
254  *
255  * Description      Start a process to read a connected peripheral's preferred
256  *                  connection parameters
257  *
258  * Returns          true if read started, else false if GAP is busy
259  *
260  ******************************************************************************/
261 bool GAP_BleReadPeerPrefConnParams(const RawAddress& peer_bda);
262 
263 /*******************************************************************************
264  *
265  * Function         GAP_BleReadPeerDevName
266  *
267  * Description      Start a process to read a connected peripheral's device
268  *                  name.
269  *
270  * Returns          true if request accepted
271  *
272  ******************************************************************************/
273 bool GAP_BleReadPeerDevName(const RawAddress& peer_bda,
274                             tGAP_BLE_CMPL_CBACK* p_cback);
275 
276 /*******************************************************************************
277  *
278  * Function         GAP_BleCancelReadPeerDevName
279  *
280  * Description      Cancel reading a peripheral's device name.
281  *
282  * Returns          true if request accepted
283  *
284  ******************************************************************************/
285 bool GAP_BleCancelReadPeerDevName(const RawAddress& peer_bda);
286 
287 #endif /* GAP_API_H */
288