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