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