1 /****************************************************************************** 2 * 3 * Copyright 1999-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 #pragma once 20 21 #include <base/functional/callback_forward.h> 22 23 #include <cstdint> 24 25 #include "stack/include/sdp_callback.h" 26 #include "stack/include/sdp_device_id.h" 27 #include "stack/sdp/sdp_discovery_db.h" 28 #include "types/bluetooth/uuid.h" 29 #include "types/raw_address.h" 30 31 /******************************************************************************* 32 * 33 * Function SDP_InitDiscoveryDb 34 * 35 * Description This function is called to initialize a discovery database. 36 * 37 * Returns true if successful, false if one or more parameters are bad 38 * 39 ******************************************************************************/ 40 bool SDP_InitDiscoveryDb(tSDP_DISCOVERY_DB* p_db, uint32_t len, 41 uint16_t num_uuid, const bluetooth::Uuid* p_uuid_list, 42 uint16_t num_attr, const uint16_t* p_attr_list); 43 44 /******************************************************************************* 45 * 46 * Function SDP_CancelServiceSearch 47 * 48 * Description This function cancels an active query to an SDP server. 49 * 50 * Returns true if discovery cancelled, false if a matching activity is 51 * not found. 52 * 53 ******************************************************************************/ 54 bool SDP_CancelServiceSearch(const tSDP_DISCOVERY_DB* p_db); 55 56 /******************************************************************************* 57 * 58 * Function SDP_ServiceSearchRequest 59 * 60 * Description This function queries an SDP server for information. 61 * 62 * Returns true if discovery started, false if failed. 63 * 64 ******************************************************************************/ 65 bool SDP_ServiceSearchRequest(const RawAddress& p_bd_addr, 66 tSDP_DISCOVERY_DB* p_db, tSDP_DISC_CMPL_CB* p_cb); 67 68 /******************************************************************************* 69 * 70 * Function SDP_ServiceSearchAttributeRequest 71 * 72 * Description This function queries an SDP server for information. 73 * 74 * The difference between this API function and the function 75 * SDP_ServiceSearchRequest is that this one does a 76 * combined ServiceSearchAttributeRequest SDP function. 77 * 78 * Returns true if discovery started, false if failed. 79 * 80 ******************************************************************************/ 81 bool SDP_ServiceSearchAttributeRequest(const RawAddress& p_bd_addr, 82 tSDP_DISCOVERY_DB* p_db, 83 tSDP_DISC_CMPL_CB* p_cb); 84 85 /******************************************************************************* 86 * 87 * Function SDP_ServiceSearchAttributeRequest2 88 * 89 * Description This function queries an SDP server for information. 90 * 91 * The difference between this API function and the function 92 * SDP_ServiceSearchRequest is that this one does a 93 * combined ServiceSearchAttributeRequest SDP function with the 94 * user data piggyback 95 * 96 * Returns true if discovery started, false if failed. 97 * 98 ******************************************************************************/ 99 bool SDP_ServiceSearchAttributeRequest2( 100 const RawAddress& p_bd_addr, tSDP_DISCOVERY_DB* p_db, 101 base::RepeatingCallback<tSDP_DISC_CMPL_CB> complete_callback); 102 103 /* API of utilities to find data in the local discovery database */ 104 105 /******************************************************************************* 106 * 107 * Function SDP_FindAttributeInRec 108 * 109 * Description This function searches an SDP discovery record for a 110 * specific attribute. 111 * 112 * Returns Pointer to matching attribute entry, or NULL 113 * 114 ******************************************************************************/ 115 tSDP_DISC_ATTR* SDP_FindAttributeInRec(const tSDP_DISC_REC* p_rec, 116 uint16_t attr_id); 117 118 /******************************************************************************* 119 * 120 * Function SDP_FindServiceInDb 121 * 122 * Description This function queries an SDP database for a specific 123 * service. If the p_start_rec pointer is NULL, it looks from 124 * the beginning of the database, else it continues from the 125 * next record after p_start_rec. 126 * 127 * Returns Pointer to record containing service class, or NULL 128 * 129 ******************************************************************************/ 130 tSDP_DISC_REC* SDP_FindServiceInDb(const tSDP_DISCOVERY_DB* p_db, 131 uint16_t service_uuid, 132 tSDP_DISC_REC* p_start_rec); 133 134 /******************************************************************************* 135 * 136 * Function SDP_FindServiceUUIDInDb 137 * 138 * Description This function queries an SDP database for a specific 139 * service. If the p_start_rec pointer is NULL, it looks from 140 * the beginning of the database, else it continues from the 141 * next record after p_start_rec. 142 * 143 * NOTE the only difference between this function and the previous 144 * function "SDP_FindServiceInDb()" is that this function takes 145 * a Uuid input. 146 * 147 * Returns Pointer to record containing service class, or NULL 148 * 149 ******************************************************************************/ 150 tSDP_DISC_REC* SDP_FindServiceUUIDInDb(const tSDP_DISCOVERY_DB* p_db, 151 const bluetooth::Uuid& uuid, 152 tSDP_DISC_REC* p_start_rec); 153 154 /******************************************************************************* 155 * 156 * Function SDP_FindServiceUUIDInRec_128bit 157 * 158 * Description Read the 128-bit service UUID within a record, 159 * if there is any. 160 * 161 * Parameters: p_rec - pointer to a SDP record. 162 * p_uuid - output parameter to save the UUID found. 163 * 164 * Returns true if found, otherwise false. 165 * 166 ******************************************************************************/ 167 bool SDP_FindServiceUUIDInRec_128bit(const tSDP_DISC_REC* p_rec, 168 bluetooth::Uuid* p_uuid); 169 170 /******************************************************************************* 171 * 172 * Function SDP_FindServiceUUIDInRec 173 * 174 * Description Read the service UUID within a record, 175 * if there is any. 176 * 177 * Parameters: p_rec - pointer to a SDP record. 178 * p_uuid - pointer to a UUID 179 * 180 * Returns true if found, otherwise false. 181 * 182 ******************************************************************************/ 183 bool SDP_FindServiceUUIDInRec(const tSDP_DISC_REC* p_rec, 184 bluetooth::Uuid* p_uuid); 185 186 /******************************************************************************* 187 * 188 * Function SDP_FindServiceInDb_128bit 189 * 190 * Description Query an SDP database for a specific service. 191 * If the p_start_rec pointer is NULL, look from the beginning 192 * of the database, else continue from the next record after 193 * p_start_rec. 194 * 195 * Returns Pointer to record containing service class, or NULL 196 * 197 ******************************************************************************/ 198 tSDP_DISC_REC* SDP_FindServiceInDb_128bit(const tSDP_DISCOVERY_DB* p_db, 199 tSDP_DISC_REC* p_start_rec); 200 201 /******************************************************************************* 202 * 203 * Function SDP_FindProtocolListElemInRec 204 * 205 * Description This function looks at a specific discovery record for a 206 * protocol list element. 207 * 208 * Returns true if found, false if not 209 * If found, the passed protocol list element is filled in. 210 * 211 ******************************************************************************/ 212 bool SDP_FindProtocolListElemInRec(const tSDP_DISC_REC* p_rec, 213 uint16_t layer_uuid, 214 tSDP_PROTOCOL_ELEM* p_elem); 215 216 /******************************************************************************* 217 * 218 * Function SDP_FindProfileVersionInRec 219 * 220 * Description This function looks at a specific discovery record for the 221 * Profile list descriptor, and pulls out the version number. 222 * The version number consists of an 8-bit major version and 223 * an 8-bit minor version. 224 * 225 * Returns true if found, false if not 226 * If found, the major and minor version numbers that were 227 * passed in are filled in. 228 * 229 ******************************************************************************/ 230 bool SDP_FindProfileVersionInRec(const tSDP_DISC_REC* p_rec, 231 uint16_t profile_uuid, uint16_t* p_version); 232 233 /* API into SDP for local service database updates */ 234 235 /******************************************************************************* 236 * 237 * Function SDP_CreateRecord 238 * 239 * Description This function is called to create a record in the database. 240 * This would be through the SDP database maintenance API. The 241 * record is created empty, the application should then call 242 * "add_attribute" to add the record's attributes. 243 * 244 * Returns Record handle if OK, else 0. 245 * 246 ******************************************************************************/ 247 uint32_t SDP_CreateRecord(void); 248 249 /******************************************************************************* 250 * 251 * Function SDP_DeleteRecord 252 * 253 * Description This function is called to add a record (or all records) 254 * from the database. This would be through the SDP database 255 * maintenance API. 256 * 257 * If a record handle of 0 is passed, all records are deleted. 258 * 259 * Returns true if succeeded, else false 260 * 261 ******************************************************************************/ 262 bool SDP_DeleteRecord(uint32_t handle); 263 264 /******************************************************************************* 265 * 266 * Function SDP_AddAttribute 267 * 268 * Description This function is called to add an attribute to a record. 269 * This would be through the SDP database maintenance API. 270 * If the attribute already exists in the record, it is 271 * replaced with the new value. 272 * 273 * NOTE Attribute values must be passed as a Big Endian stream. 274 * 275 * Returns true if added OK, else false 276 * 277 ******************************************************************************/ 278 bool SDP_AddAttribute(uint32_t handle, uint16_t attr_id, uint8_t attr_type, 279 uint32_t attr_len, uint8_t* p_val); 280 281 /******************************************************************************* 282 * 283 * Function SDP_AddSequence 284 * 285 * Description This function is called to add a sequence to a record. 286 * This would be through the SDP database maintenance API. 287 * If the sequence already exists in the record, it is replaced 288 * with the new sequence. 289 * 290 * NOTE Element values must be passed as a Big Endian stream. 291 * 292 * Returns true if added OK, else false 293 * 294 ******************************************************************************/ 295 bool SDP_AddSequence(uint32_t handle, uint16_t attr_id, uint16_t num_elem, 296 uint8_t type[], uint8_t len[], uint8_t* p_val[]); 297 298 /******************************************************************************* 299 * 300 * Function SDP_AddUuidSequence 301 * 302 * Description This function is called to add a UUID sequence to a record. 303 * This would be through the SDP database maintenance API. 304 * If the sequence already exists in the record, it is replaced 305 * with the new sequence. 306 * 307 * Returns true if added OK, else false 308 * 309 ******************************************************************************/ 310 bool SDP_AddUuidSequence(uint32_t handle, uint16_t attr_id, uint16_t num_uuids, 311 uint16_t* p_uuids); 312 313 /******************************************************************************* 314 * 315 * Function SDP_AddProtocolList 316 * 317 * Description This function is called to add a protocol descriptor list to 318 * a record. This would be through the SDP database 319 * maintenance API. If the protocol list already exists in the 320 * record, it is replaced with the new list. 321 * 322 * Returns true if added OK, else false 323 * 324 ******************************************************************************/ 325 bool SDP_AddProtocolList(uint32_t handle, uint16_t num_elem, 326 tSDP_PROTOCOL_ELEM* p_elem_list); 327 328 /******************************************************************************* 329 * 330 * Function SDP_AddAdditionProtoLists 331 * 332 * Description This function is called to add a protocol descriptor list to 333 * a record. This would be through the SDP database maintenance 334 * API. If the protocol list already exists in the record, it 335 * is replaced with the new list. 336 * 337 * Returns true if added OK, else false 338 * 339 ******************************************************************************/ 340 bool SDP_AddAdditionProtoLists(uint32_t handle, uint16_t num_elem, 341 tSDP_PROTO_LIST_ELEM* p_proto_list); 342 343 /******************************************************************************* 344 * 345 * Function SDP_AddProfileDescriptorList 346 * 347 * Description This function is called to add a profile descriptor list to 348 * a record. This would be through the SDP database maintenance 349 * API. If the version already exists in the record, it is 350 * replaced with the new one. 351 * 352 * Returns true if added OK, else false 353 * 354 ******************************************************************************/ 355 bool SDP_AddProfileDescriptorList(uint32_t handle, uint16_t profile_uuid, 356 uint16_t version); 357 358 /******************************************************************************* 359 * 360 * Function SDP_AddLanguageBaseAttrIDList 361 * 362 * Description This function is called to add a language base attr list to 363 * a record. This would be through the SDP database maintenance 364 * API. If the version already exists in the record, it is 365 * replaced with the new one. 366 * 367 * Returns true if added OK, else false 368 * 369 ******************************************************************************/ 370 bool SDP_AddLanguageBaseAttrIDList(uint32_t handle, uint16_t lang, 371 uint16_t char_enc, uint16_t base_id); 372 373 /******************************************************************************* 374 * 375 * Function SDP_AddServiceClassIdList 376 * 377 * Description This function is called to add a service list to a record. 378 * This would be through the SDP database maintenance API. 379 * If the service list already exists in the record, it is 380 * replaced with the new list. 381 * 382 * Returns true if added OK, else false 383 * 384 ******************************************************************************/ 385 bool SDP_AddServiceClassIdList(uint32_t handle, uint16_t num_services, 386 uint16_t* p_service_uuids); 387 388 /* Device Identification APIs */ 389 390 /******************************************************************************* 391 * 392 * Function SDP_SetLocalDiRecord 393 * 394 * Description This function adds a DI record to the local SDP database. 395 * 396 * Returns Returns SDP_SUCCESS if record added successfully, else error 397 * 398 ******************************************************************************/ 399 uint16_t SDP_SetLocalDiRecord(const tSDP_DI_RECORD* device_info, 400 uint32_t* p_handle); 401 402 /******************************************************************************* 403 * 404 * Function SDP_DiDiscover 405 * 406 * Description This function queries a remote device for DI information. 407 * 408 * Returns SDP_SUCCESS if query started successfully, else error 409 * 410 ******************************************************************************/ 411 tSDP_STATUS SDP_DiDiscover(const RawAddress& remote_device, 412 tSDP_DISCOVERY_DB* p_db, uint32_t len, 413 tSDP_DISC_CMPL_CB* p_cb); 414 415 /******************************************************************************* 416 * 417 * Function SDP_GetNumDiRecords 418 * 419 * Description Searches specified database for DI records 420 * 421 * Returns number of DI records found 422 * 423 ******************************************************************************/ 424 uint8_t SDP_GetNumDiRecords(const tSDP_DISCOVERY_DB* p_db); 425 426 /******************************************************************************* 427 * 428 * Function SDP_GetDiRecord 429 * 430 * Description This function retrieves a remote device's DI record from 431 * the specified database. 432 * 433 * Returns SDP_SUCCESS if record retrieved, else error 434 * 435 ******************************************************************************/ 436 uint16_t SDP_GetDiRecord(uint8_t getRecordIndex, 437 tSDP_DI_GET_RECORD* device_info, 438 const tSDP_DISCOVERY_DB* p_db); 439