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