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