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/strings/stringprintf.h>
22
23 #include <cstdint>
24
25 #include "bt_target.h"
26 #include "sdpdefs.h"
27 #include "types/bluetooth/uuid.h"
28 #include "types/raw_address.h"
29
30 /*****************************************************************************
31 * Constants
32 ****************************************************************************/
33
34 /* Success code and error codes */
35 typedef enum : uint16_t {
36 SDP_SUCCESS = 0x0000,
37 SDP_INVALID_VERSION = 0x0001,
38 SDP_INVALID_SERV_REC_HDL = 0x0002,
39 SDP_INVALID_REQ_SYNTAX = 0x0003,
40 SDP_INVALID_PDU_SIZE = 0x0004,
41 SDP_INVALID_CONT_STATE = 0x0005,
42 SDP_NO_RESOURCES = 0x0006,
43 SDP_DI_REG_FAILED = 0x0007,
44 SDP_DI_DISC_FAILED = 0x0008,
45 SDP_NO_DI_RECORD_FOUND = 0x0009,
46 SDP_ERR_ATTR_NOT_PRESENT = 0x000A,
47 SDP_ILLEGAL_PARAMETER = 0x000B,
48
49 HID_SDP_NO_SERV_UUID = (SDP_ILLEGAL_PARAMETER + 1),
50 HID_SDP_MANDATORY_MISSING,
51
52 SDP_NO_RECS_MATCH = 0xFFF0,
53 SDP_CONN_FAILED = 0xFFF1,
54 SDP_CFG_FAILED = 0xFFF2,
55 SDP_GENERIC_ERROR = 0xFFF3,
56 SDP_DB_FULL = 0xFFF4,
57 SDP_CANCEL = 0xFFF8,
58 } tSDP_STATUS;
59 using tSDP_RESULT = tSDP_STATUS;
60 using tSDP_REASON = tSDP_STATUS;
61
62 #define CASE_RETURN_TEXT(code) \
63 case code: \
64 return #code
65
sdp_status_text(const tSDP_STATUS & status)66 inline std::string sdp_status_text(const tSDP_STATUS& status) {
67 switch (status) {
68 CASE_RETURN_TEXT(SDP_SUCCESS);
69 CASE_RETURN_TEXT(SDP_INVALID_VERSION);
70 CASE_RETURN_TEXT(SDP_INVALID_SERV_REC_HDL);
71 CASE_RETURN_TEXT(SDP_INVALID_REQ_SYNTAX);
72 CASE_RETURN_TEXT(SDP_INVALID_PDU_SIZE);
73 CASE_RETURN_TEXT(SDP_INVALID_CONT_STATE);
74 CASE_RETURN_TEXT(SDP_NO_RESOURCES);
75 CASE_RETURN_TEXT(SDP_DI_REG_FAILED);
76 CASE_RETURN_TEXT(SDP_DI_DISC_FAILED);
77 CASE_RETURN_TEXT(SDP_NO_DI_RECORD_FOUND);
78 CASE_RETURN_TEXT(SDP_ERR_ATTR_NOT_PRESENT);
79 CASE_RETURN_TEXT(SDP_ILLEGAL_PARAMETER);
80
81 CASE_RETURN_TEXT(HID_SDP_NO_SERV_UUID);
82 CASE_RETURN_TEXT(HID_SDP_MANDATORY_MISSING);
83
84 CASE_RETURN_TEXT(SDP_NO_RECS_MATCH);
85 CASE_RETURN_TEXT(SDP_CONN_FAILED);
86 CASE_RETURN_TEXT(SDP_CFG_FAILED);
87 CASE_RETURN_TEXT(SDP_GENERIC_ERROR);
88 CASE_RETURN_TEXT(SDP_DB_FULL);
89 CASE_RETURN_TEXT(SDP_CANCEL);
90 default:
91 return base::StringPrintf("UNKNOWN[%hu]", status);
92 }
93 }
94 const auto sdp_result_text = sdp_status_text;
95
96 #undef CASE_RETURN_TEXT
97
98 /* Masks for attr_value field of tSDP_DISC_ATTR */
99 #define SDP_DISC_ATTR_LEN_MASK 0x0FFF
100 #define SDP_DISC_ATTR_TYPE(len_type) ((len_type) >> 12)
101 #define SDP_DISC_ATTR_LEN(len_type) ((len_type)&SDP_DISC_ATTR_LEN_MASK)
102
103 /* Maximum number of protocol list items (list_elem in tSDP_PROTOCOL_ELEM) */
104 #define SDP_MAX_LIST_ELEMS 3
105
106 /*****************************************************************************
107 * Type Definitions
108 ****************************************************************************/
109
110 /* Define a callback function for when discovery is complete. */
111 typedef void(tSDP_DISC_CMPL_CB)(tSDP_RESULT result);
112 typedef void(tSDP_DISC_CMPL_CB2)(tSDP_RESULT result, const void* user_data);
113
114 typedef struct {
115 RawAddress peer_addr;
116 uint16_t peer_mtu;
117 } tSDP_DR_OPEN;
118
119 typedef struct {
120 uint8_t* p_data;
121 uint16_t data_len;
122 } tSDP_DR_DATA;
123
124 typedef union {
125 tSDP_DR_OPEN open;
126 tSDP_DR_DATA data;
127 } tSDP_DATA;
128
129 /* Define a structure to hold the discovered service information. */
130 typedef struct {
131 union {
132 uint8_t u8; /* 8-bit integer */
133 uint16_t u16; /* 16-bit integer */
134 uint32_t u32; /* 32-bit integer */
135 struct t_sdp_disc_attr* p_sub_attr; /* Addr of first sub-attr (list)*/
136 uint8_t array[]; /* Variable length field */
137 /* flexible array member */
138 /* requiring backing store */
139 /* from SDP DB */
140 } v;
141
142 } tSDP_DISC_ATVAL;
143
144 typedef struct t_sdp_disc_attr {
145 struct t_sdp_disc_attr* p_next_attr; /* Addr of next linked attr */
146 uint16_t attr_id; /* Attribute ID */
147 uint16_t attr_len_type; /* Length and type fields */
148 tSDP_DISC_ATVAL attr_value; /* Variable length entry data */
149 } tSDP_DISC_ATTR;
150
151 typedef struct t_sdp_disc_rec {
152 tSDP_DISC_ATTR* p_first_attr; /* First attribute of record */
153 struct t_sdp_disc_rec* p_next_rec; /* Addr of next linked record */
154 uint32_t time_read; /* The time the record was read */
155 RawAddress remote_bd_addr; /* Remote BD address */
156 } tSDP_DISC_REC;
157
158 typedef struct {
159 uint32_t mem_size; /* Memory size of the DB */
160 uint32_t mem_free; /* Memory still available */
161 tSDP_DISC_REC* p_first_rec; /* Addr of first record in DB */
162 uint16_t num_uuid_filters; /* Number of UUIds to filter */
163 bluetooth::Uuid uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */
164 uint16_t num_attr_filters; /* Number of attribute filters */
165 uint16_t attr_filters[SDP_MAX_ATTR_FILTERS]; /* Attributes to filter */
166 uint8_t* p_free_mem; /* Pointer to free memory */
167 uint8_t*
168 raw_data; /* Received record from server. allocated/released by client */
169 uint32_t raw_size; /* size of raw_data */
170 uint32_t raw_used; /* length of raw_data used */
171 } tSDP_DISCOVERY_DB;
172
173 /* This structure is used to add protocol lists and find protocol elements */
174 typedef struct {
175 uint16_t protocol_uuid;
176 uint16_t num_params;
177 uint16_t params[SDP_MAX_PROTOCOL_PARAMS];
178 } tSDP_PROTOCOL_ELEM;
179
180 typedef struct {
181 uint16_t num_elems;
182 tSDP_PROTOCOL_ELEM list_elem[SDP_MAX_LIST_ELEMS];
183 } tSDP_PROTO_LIST_ELEM;
184
185 /* Device Identification (DI) data structure
186 */
187 /* Used to set the DI record */
188 typedef struct t_sdp_di_record {
189 uint16_t vendor;
190 uint16_t vendor_id_source;
191 uint16_t product;
192 uint16_t version;
193 bool primary_record;
194 char client_executable_url[SDP_MAX_ATTR_LEN]; /* optional */
195 char service_description[SDP_MAX_ATTR_LEN]; /* optional */
196 char documentation_url[SDP_MAX_ATTR_LEN]; /* optional */
197 } tSDP_DI_RECORD;
198
199 /* Used to get the DI record */
200 typedef struct t_sdp_di_get_record {
201 uint16_t spec_id;
202 tSDP_DI_RECORD rec;
203 } tSDP_DI_GET_RECORD;
204
205 /* API into the SDP layer for service discovery. */
206
207 /*******************************************************************************
208 *
209 * Function SDP_InitDiscoveryDb
210 *
211 * Description This function is called to initialize a discovery database.
212 *
213 * Returns true if successful, false if one or more parameters are bad
214 *
215 ******************************************************************************/
216 bool SDP_InitDiscoveryDb(tSDP_DISCOVERY_DB* p_db, uint32_t len,
217 uint16_t num_uuid, const bluetooth::Uuid* p_uuid_list,
218 uint16_t num_attr, const uint16_t* p_attr_list);
219
220 /*******************************************************************************
221 *
222 * Function SDP_CancelServiceSearch
223 *
224 * Description This function cancels an active query to an SDP server.
225 *
226 * Returns true if discovery cancelled, false if a matching activity is
227 * not found.
228 *
229 ******************************************************************************/
230 bool SDP_CancelServiceSearch(const tSDP_DISCOVERY_DB* p_db);
231
232 /*******************************************************************************
233 *
234 * Function SDP_ServiceSearchRequest
235 *
236 * Description This function queries an SDP server for information.
237 *
238 * Returns true if discovery started, false if failed.
239 *
240 ******************************************************************************/
241 bool SDP_ServiceSearchRequest(const RawAddress& p_bd_addr,
242 tSDP_DISCOVERY_DB* p_db, tSDP_DISC_CMPL_CB* p_cb);
243
244 /*******************************************************************************
245 *
246 * Function SDP_ServiceSearchAttributeRequest
247 *
248 * Description This function queries an SDP server for information.
249 *
250 * The difference between this API function and the function
251 * SDP_ServiceSearchRequest is that this one does a
252 * combined ServiceSearchAttributeRequest SDP function.
253 *
254 * Returns true if discovery started, false if failed.
255 *
256 ******************************************************************************/
257 bool SDP_ServiceSearchAttributeRequest(const RawAddress& p_bd_addr,
258 tSDP_DISCOVERY_DB* p_db,
259 tSDP_DISC_CMPL_CB* p_cb);
260
261 /*******************************************************************************
262 *
263 * Function SDP_ServiceSearchAttributeRequest2
264 *
265 * Description This function queries an SDP server for information.
266 *
267 * The difference between this API function and the function
268 * SDP_ServiceSearchRequest is that this one does a
269 * combined ServiceSearchAttributeRequest SDP function with the
270 * user data piggyback
271 *
272 * Returns true if discovery started, false if failed.
273 *
274 ******************************************************************************/
275 bool SDP_ServiceSearchAttributeRequest2(const RawAddress& p_bd_addr,
276 tSDP_DISCOVERY_DB* p_db,
277 tSDP_DISC_CMPL_CB2* p_cb,
278 const void* user_data);
279
280 /* API of utilities to find data in the local discovery database */
281
282 /*******************************************************************************
283 *
284 * Function SDP_FindAttributeInRec
285 *
286 * Description This function searches an SDP discovery record for a
287 * specific attribute.
288 *
289 * Returns Pointer to matching attribute entry, or NULL
290 *
291 ******************************************************************************/
292 tSDP_DISC_ATTR* SDP_FindAttributeInRec(const tSDP_DISC_REC* p_rec,
293 uint16_t attr_id);
294
295 /*******************************************************************************
296 *
297 * Function SDP_FindServiceInDb
298 *
299 * Description This function queries an SDP database for a specific
300 * service. If the p_start_rec pointer is NULL, it looks from
301 * the beginning of the database, else it continues from the
302 * next record after p_start_rec.
303 *
304 * Returns Pointer to record containing service class, or NULL
305 *
306 ******************************************************************************/
307 tSDP_DISC_REC* SDP_FindServiceInDb(const tSDP_DISCOVERY_DB* p_db,
308 uint16_t service_uuid,
309 tSDP_DISC_REC* p_start_rec);
310
311 /*******************************************************************************
312 *
313 * Function SDP_FindServiceUUIDInDb
314 *
315 * Description This function queries an SDP database for a specific
316 * service. If the p_start_rec pointer is NULL, it looks from
317 * the beginning of the database, else it continues from the
318 * next record after p_start_rec.
319 *
320 * NOTE the only difference between this function and the previous
321 * function "SDP_FindServiceInDb()" is that this function takes
322 * a Uuid input.
323 *
324 * Returns Pointer to record containing service class, or NULL
325 *
326 ******************************************************************************/
327 tSDP_DISC_REC* SDP_FindServiceUUIDInDb(const tSDP_DISCOVERY_DB* p_db,
328 const bluetooth::Uuid& uuid,
329 tSDP_DISC_REC* p_start_rec);
330
331 /*******************************************************************************
332 *
333 * Function SDP_FindServiceUUIDInRec_128bit
334 *
335 * Description Read the 128-bit service UUID within a record,
336 * if there is any.
337 *
338 * Parameters: p_rec - pointer to a SDP record.
339 * p_uuid - output parameter to save the UUID found.
340 *
341 * Returns true if found, otherwise false.
342 *
343 ******************************************************************************/
344 bool SDP_FindServiceUUIDInRec_128bit(const tSDP_DISC_REC* p_rec,
345 bluetooth::Uuid* p_uuid);
346
347 /*******************************************************************************
348 *
349 * Function SDP_FindServiceInDb_128bit
350 *
351 * Description Query an SDP database for a specific service.
352 * If the p_start_rec pointer is NULL, look from the beginning
353 * of the database, else continue from the next record after
354 * p_start_rec.
355 *
356 * Returns Pointer to record containing service class, or NULL
357 *
358 ******************************************************************************/
359 tSDP_DISC_REC* SDP_FindServiceInDb_128bit(const tSDP_DISCOVERY_DB* p_db,
360 tSDP_DISC_REC* p_start_rec);
361
362 /*******************************************************************************
363 *
364 * Function SDP_FindProtocolListElemInRec
365 *
366 * Description This function looks at a specific discovery record for a
367 * protocol list element.
368 *
369 * Returns true if found, false if not
370 * If found, the passed protocol list element is filled in.
371 *
372 ******************************************************************************/
373 bool SDP_FindProtocolListElemInRec(const tSDP_DISC_REC* p_rec,
374 uint16_t layer_uuid,
375 tSDP_PROTOCOL_ELEM* p_elem);
376
377 /*******************************************************************************
378 *
379 * Function SDP_FindProfileVersionInRec
380 *
381 * Description This function looks at a specific discovery record for the
382 * Profile list descriptor, and pulls out the version number.
383 * The version number consists of an 8-bit major version and
384 * an 8-bit minor version.
385 *
386 * Returns true if found, false if not
387 * If found, the major and minor version numbers that were
388 * passed in are filled in.
389 *
390 ******************************************************************************/
391 bool SDP_FindProfileVersionInRec(const tSDP_DISC_REC* p_rec,
392 uint16_t profile_uuid, uint16_t* p_version);
393
394 /* API into SDP for local service database updates */
395
396 /*******************************************************************************
397 *
398 * Function SDP_CreateRecord
399 *
400 * Description This function is called to create a record in the database.
401 * This would be through the SDP database maintenance API. The
402 * record is created empty, teh application should then call
403 * "add_attribute" to add the record's attributes.
404 *
405 * Returns Record handle if OK, else 0.
406 *
407 ******************************************************************************/
408 uint32_t SDP_CreateRecord(void);
409
410 /*******************************************************************************
411 *
412 * Function SDP_DeleteRecord
413 *
414 * Description This function is called to add a record (or all records)
415 * from the database. This would be through the SDP database
416 * maintenance API.
417 *
418 * If a record handle of 0 is passed, all records are deleted.
419 *
420 * Returns true if succeeded, else false
421 *
422 ******************************************************************************/
423 bool SDP_DeleteRecord(uint32_t handle);
424
425 /*******************************************************************************
426 *
427 * Function SDP_AddAttribute
428 *
429 * Description This function is called to add an attribute to a record.
430 * This would be through the SDP database maintenance API.
431 * If the attribute already exists in the record, it is
432 * replaced with the new value.
433 *
434 * NOTE Attribute values must be passed as a Big Endian stream.
435 *
436 * Returns true if added OK, else false
437 *
438 ******************************************************************************/
439 bool SDP_AddAttribute(uint32_t handle, uint16_t attr_id, uint8_t attr_type,
440 uint32_t attr_len, uint8_t* p_val);
441
442 /*******************************************************************************
443 *
444 * Function SDP_AddSequence
445 *
446 * Description This function is called to add a sequence to a record.
447 * This would be through the SDP database maintenance API.
448 * If the sequence already exists in the record, it is replaced
449 * with the new sequence.
450 *
451 * NOTE Element values must be passed as a Big Endian stream.
452 *
453 * Returns true if added OK, else false
454 *
455 ******************************************************************************/
456 bool SDP_AddSequence(uint32_t handle, uint16_t attr_id, uint16_t num_elem,
457 uint8_t type[], uint8_t len[], uint8_t* p_val[]);
458
459 /*******************************************************************************
460 *
461 * Function SDP_AddUuidSequence
462 *
463 * Description This function is called to add a UUID sequence to a record.
464 * This would be through the SDP database maintenance API.
465 * If the sequence already exists in the record, it is replaced
466 * with the new sequence.
467 *
468 * Returns true if added OK, else false
469 *
470 ******************************************************************************/
471 bool SDP_AddUuidSequence(uint32_t handle, uint16_t attr_id, uint16_t num_uuids,
472 uint16_t* p_uuids);
473
474 /*******************************************************************************
475 *
476 * Function SDP_AddProtocolList
477 *
478 * Description This function is called to add a protocol descriptor list to
479 * a record. This would be through the SDP database
480 * maintenance API. If the protocol list already exists in the
481 * record, it is replaced with the new list.
482 *
483 * Returns true if added OK, else false
484 *
485 ******************************************************************************/
486 bool SDP_AddProtocolList(uint32_t handle, uint16_t num_elem,
487 tSDP_PROTOCOL_ELEM* p_elem_list);
488
489 /*******************************************************************************
490 *
491 * Function SDP_AddAdditionProtoLists
492 *
493 * Description This function is called to add a protocol descriptor list to
494 * a record. This would be through the SDP database maintenance
495 * API. If the protocol list already exists in the record, it
496 * is replaced with the new list.
497 *
498 * Returns true if added OK, else false
499 *
500 ******************************************************************************/
501 bool SDP_AddAdditionProtoLists(uint32_t handle, uint16_t num_elem,
502 tSDP_PROTO_LIST_ELEM* p_proto_list);
503
504 /*******************************************************************************
505 *
506 * Function SDP_AddProfileDescriptorList
507 *
508 * Description This function is called to add a profile descriptor list to
509 * a record. This would be through the SDP database maintenance
510 * API. If the version already exists in the record, it is
511 * replaced with the new one.
512 *
513 * Returns true if added OK, else false
514 *
515 ******************************************************************************/
516 bool SDP_AddProfileDescriptorList(uint32_t handle, uint16_t profile_uuid,
517 uint16_t version);
518
519 /*******************************************************************************
520 *
521 * Function SDP_AddLanguageBaseAttrIDList
522 *
523 * Description This function is called to add a language base attr list to
524 * a record. This would be through the SDP database maintenance
525 * API. If the version already exists in the record, it is
526 * replaced with the new one.
527 *
528 * Returns true if added OK, else false
529 *
530 ******************************************************************************/
531 bool SDP_AddLanguageBaseAttrIDList(uint32_t handle, uint16_t lang,
532 uint16_t char_enc, uint16_t base_id);
533
534 /*******************************************************************************
535 *
536 * Function SDP_AddServiceClassIdList
537 *
538 * Description This function is called to add a service list to a record.
539 * This would be through the SDP database maintenance API.
540 * If the service list already exists in the record, it is
541 * replaced with the new list.
542 *
543 * Returns true if added OK, else false
544 *
545 ******************************************************************************/
546 bool SDP_AddServiceClassIdList(uint32_t handle, uint16_t num_services,
547 uint16_t* p_service_uuids);
548
549 /*******************************************************************************
550 *
551 * Function SDP_DeleteAttribute
552 *
553 * Description Delete an attribute from a record.
554 * This would be through the SDP database maintenance API.
555 *
556 * Returns true if deleted OK, else false if not found
557 *
558 ******************************************************************************/
559 bool SDP_DeleteAttribute(uint32_t handle, uint16_t attr_id);
560
561 /* Device Identification APIs */
562
563 /*******************************************************************************
564 *
565 * Function SDP_SetLocalDiRecord
566 *
567 * Description This function adds a DI record to the local SDP database.
568 *
569 * Returns Returns SDP_SUCCESS if record added successfully, else error
570 *
571 ******************************************************************************/
572 uint16_t SDP_SetLocalDiRecord(const tSDP_DI_RECORD* device_info,
573 uint32_t* p_handle);
574
575 /*******************************************************************************
576 *
577 * Function SDP_DiDiscover
578 *
579 * Description This function queries a remote device for DI information.
580 *
581 * Returns SDP_SUCCESS if query started successfully, else error
582 *
583 ******************************************************************************/
584 tSDP_STATUS SDP_DiDiscover(const RawAddress& remote_device,
585 tSDP_DISCOVERY_DB* p_db, uint32_t len,
586 tSDP_DISC_CMPL_CB* p_cb);
587
588 /*******************************************************************************
589 *
590 * Function SDP_GetNumDiRecords
591 *
592 * Description Searches specified database for DI records
593 *
594 * Returns number of DI records found
595 *
596 ******************************************************************************/
597 uint8_t SDP_GetNumDiRecords(const tSDP_DISCOVERY_DB* p_db);
598
599 /*******************************************************************************
600 *
601 * Function SDP_GetDiRecord
602 *
603 * Description This function retrieves a remote device's DI record from
604 * the specified database.
605 *
606 * Returns SDP_SUCCESS if record retrieved, else error
607 *
608 ******************************************************************************/
609 uint16_t SDP_GetDiRecord(uint8_t getRecordIndex,
610 tSDP_DI_GET_RECORD* device_info,
611 const tSDP_DISCOVERY_DB* p_db);
612
613 /*******************************************************************************
614 *
615 * Function SDP_SetTraceLevel
616 *
617 * Description This function sets the trace level for SDP. If called with
618 * a value of 0xFF, it simply reads the current trace level.
619 *
620 * Returns the new (current) trace level
621 *
622 ******************************************************************************/
623 uint8_t SDP_SetTraceLevel(uint8_t new_level);
624
625 /*******************************************************************************
626 *
627 * Function SDP_FindServiceUUIDInRec
628 *
629 * Description Read the service UUID within a record,
630 * if there is any.
631 *
632 * Parameters: p_rec - pointer to a SDP record.
633 * p_uuid - pointer to a UUID
634 *
635 * Returns true if found, otherwise false.
636 *
637 ******************************************************************************/
638 bool SDP_FindServiceUUIDInRec(const tSDP_DISC_REC* p_rec,
639 bluetooth::Uuid* p_uuid);
640
641 namespace bluetooth {
642 namespace legacy {
643 namespace stack {
644 namespace sdp {
645
646 struct tSdpApi {
647 struct {
648 /*******************************************************************************
649 Function SDP_InitDiscoveryDb
650
651 Description This function is called to initialize a discovery
652 database.
653
654 Parameters: p_db - (input) address of an area of memory where
655 the discovery database is managed.
656 len - (input) size (in bytes) of the memory
657 NOTE: This must be larger than sizeof(tSDP_DISCOVERY_DB)
658 num_uuid - (input) number of UUID filters applied
659 p_uuid_list - (input) list of UUID filters
660 num_attr - (input) number of attribute filters
661 applied
662 p_attr_list - (input) list of attribute filters
663
664 Returns true if successful, false if one or more parameters are
665 bad
666 ******************************************************************************/
667 bool (*SDP_InitDiscoveryDb)(tSDP_DISCOVERY_DB*, uint32_t, uint16_t,
668 const bluetooth::Uuid*, uint16_t,
669 const uint16_t*);
670
671 /*******************************************************************************
672
673 Function SDP_CancelServiceSearch
674
675 Description This function cancels an active query to an SDP server.
676
677 Parameters: p_db - (input) address of an area of memory where
678 the discovery database is managed.
679
680 Returns true if discovery cancelled, false if a matching
681 activity is not found.
682
683 ******************************************************************************/
684 bool (*SDP_CancelServiceSearch)(const tSDP_DISCOVERY_DB*);
685
686 /*******************************************************************************
687
688 Function SDP_ServiceSearchRequest
689
690 Description This function queries an SDP server for information.
691
692 Parameters: p_db - (input) address of an area of memory where
693 the discovery database is managed.
694 p_cb - (input) callback executed when complete
695
696 Returns true if discovery started, false if failed.
697
698 ******************************************************************************/
699 bool (*SDP_ServiceSearchRequest)(const RawAddress&, tSDP_DISCOVERY_DB*,
700 tSDP_DISC_CMPL_CB*);
701
702 /*******************************************************************************
703
704 Function SDP_ServiceSearchAttributeRequest
705
706 Description This function queries an SDP server for information.
707
708 The difference between this API function and the
709 function SDP_ServiceSearchRequest is that this one does
710 a combined ServiceSearchAttributeRequest SDP function.
711
712 Parameters: bd_addr - (input) device address for service search
713 p_db - (input) address of an area of memory where
714 the discovery database is managed.
715 p_cb - (input) callback executed when complete
716
717 Returns true if discovery started, false if failed.
718
719 ******************************************************************************/
720 bool (*SDP_ServiceSearchAttributeRequest)(const RawAddress&,
721 tSDP_DISCOVERY_DB*,
722 tSDP_DISC_CMPL_CB*);
723
724 /*******************************************************************************
725
726 Function SDP_ServiceSearchAttributeRequest2
727
728 Description This function queries an SDP server for information.
729
730 The difference between this API function and the
731 function SDP_ServiceSearchRequest is that this one does
732 a combined ServiceSearchAttributeRequest SDP function
733 with the user data piggyback
734
735 parameters: bd_addr - (input) device address for service search
736 p_db - (input) address of an area of memory where
737 the discovery database is managed.
738 p_cb2 - (input) callback executed when complete
739 p_data - (input) user data
740
741 Returns true if discovery started, false if failed.
742
743 ******************************************************************************/
744 bool (*SDP_ServiceSearchAttributeRequest2)(const RawAddress&,
745 tSDP_DISCOVERY_DB*,
746 tSDP_DISC_CMPL_CB2*,
747 const void*);
748 } service;
749
750 struct {
751 /*******************************************************************************
752
753 Function SDP_FindServiceInDb
754
755 Description This function queries an SDP database for a specific
756 service. If the p_start_rec pointer is NULL, it looks
757 from the beginning of the database, else it continues
758 from the next record after p_start_rec.
759
760 parameters: p_db - (input) address of an area of memory where
761 the discovery database is managed.
762 uuid16 - (input) Uuid to search in db
763 disc_rec - (output) Record found, null otherwise
764
765 Returns Pointer to record containing service class, or NULL
766
767 ******************************************************************************/
768 tSDP_DISC_REC* (*SDP_FindServiceInDb)(const tSDP_DISCOVERY_DB*, uint16_t,
769 tSDP_DISC_REC*);
770
771 /*******************************************************************************
772
773 Function SDP_FindServiceUUIDInDb
774
775 Description This function queries an SDP database for a specific
776 service. If the p_start_rec pointer is NULL, it looks
777 from the beginning of the database, else it continues
778 from the next record after p_start_rec.
779
780 NOTE the only difference between this function and the
781 previous function "SDP_FindServiceInDb()" is that this
782 function takes a Uuid input.
783
784 parameters: p_db - (input) address of an area of memory where
785 the discovery database is managed.
786 uuid - (input) Uuid to search in db
787 disc_rec - (input) Start record, null from beginning
788
789 Returns Pointer to record containing service class, or NULL
790
791 ******************************************************************************/
792 tSDP_DISC_REC* (*SDP_FindServiceUUIDInDb)(const tSDP_DISCOVERY_DB*,
793 const bluetooth::Uuid&,
794 tSDP_DISC_REC*);
795
796 /*******************************************************************************
797
798 Function SDP_FindServiceInDb_128bit
799
800 Description Query an SDP database for a specific service.
801 If the p_start_rec pointer is NULL, look from the
802 beginning of the database, else continue from the next
803 record after p_start_rec.
804
805 parameters: p_db - (input) address of an area of memory where
806 the discovery database is managed.
807 disc_rec - (input) Start record, null from beginning
808
809 Returns Pointer to record containing service class, or NULL
810
811 ******************************************************************************/
812 tSDP_DISC_REC* (*SDP_FindServiceInDb_128bit)(const tSDP_DISCOVERY_DB*,
813 tSDP_DISC_REC*);
814 } db;
815
816 struct {
817 /*******************************************************************************
818
819 Local discovery database API
820
821 Function SDP_FindAttributeInRec
822
823 Description This function searches an SDP discovery record for a
824 specific attribute.
825
826 parameters: disc_rec - (input) Start record must not be null
827 attr_id - (input) Attribute id to search
828
829 Returns Pointer to matching attribute entry, or NULL
830
831 ******************************************************************************/
832 tSDP_DISC_ATTR* (*SDP_FindAttributeInRec)(const tSDP_DISC_REC*, uint16_t);
833
834 /*******************************************************************************
835
836 Function SDP_FindServiceUUIDInRec_128bit
837
838 Description Read the 128-bit service UUID within a record;
839 if there is any.
840
841 Parameters: p_rec - (input) pointer to a SDP record.
842 p_uuid - (output) parameter to save the UUID found.
843
844 Returns true if found, otherwise false.
845
846 ******************************************************************************/
847 bool (*SDP_FindServiceUUIDInRec_128bit)(const tSDP_DISC_REC*,
848 bluetooth::Uuid*);
849
850 /*******************************************************************************
851
852 Function SDP_FindProtocolListElemInRec
853
854 Description This function looks at a specific discovery record for a
855 protocol list element.
856
857 Parameters: p_rec - (input) pointer to a SDP record.
858 p_uuid - (input) layer UUID.
859 p_elem - (output) protocol element
860
861 Returns true if found, false if not
862 If found, the passed protocol list element is filled in.
863
864 ******************************************************************************/
865 bool (*SDP_FindProtocolListElemInRec)(const tSDP_DISC_REC*, uint16_t,
866 tSDP_PROTOCOL_ELEM*);
867
868 /*******************************************************************************
869
870 Function SDP_FindProfileVersionInRec
871
872 Description This function looks at a specific discovery record for
873 the Profile list descriptor, and pulls out the version
874 number. The version number consists of an 8-bit major
875 version and an 8-bit minor version.
876
877 Parameters: p_rec - (input) pointer to a SDP record.
878 p_uuid - (input) profile UUID.
879 p_elem - (output) major and minor version numbers
880
881 Returns true if found, false if not
882
883 ******************************************************************************/
884 bool (*SDP_FindProfileVersionInRec)(const tSDP_DISC_REC*, uint16_t,
885 uint16_t*);
886
887 /*******************************************************************************
888
889 Function SDP_FindServiceUUIDInRec
890
891 Description Read the service UUID within a record;
892 if there is any.
893
894 Parameters: p_rec - (input) pointer to a SDP record.
895 p_uuid - (output) found UUID or null.
896
897 Returns true if found, otherwise false.
898
899 ******************************************************************************/
900 bool (*SDP_FindServiceUUIDInRec)(const tSDP_DISC_REC* p_rec,
901 bluetooth::Uuid* p_uuid);
902 } record;
903
904 struct {
905 /*******************************************************************************
906
907 API into SDP for Local service database updates
908
909 Function SDP_CreateRecord
910
911 Description This function is called to create a record in the
912 database. This would be through the SDP database
913 maintenance API. The record is created empty, teh
914 application should then call "add_attribute" *to add
915 the record's attributes.
916
917 Returns Record handle if OK, else 0.
918
919 ******************************************************************************/
920 uint32_t (*SDP_CreateRecord)(void);
921
922 /*******************************************************************************
923
924 Function SDP_DeleteRecord
925
926 Description This function is called to add a record (or all records)
927 from the database. This would be through the SDP
928 database maintenance API.
929
930 Parameters: handle - (input) Handle to delete, 0 for all records
931 to be deleted
932
933 Returns true if succeeded, else false
934
935 ******************************************************************************/
936 bool (*SDP_DeleteRecord)(uint32_t);
937
938 /*******************************************************************************
939
940 Function SDP_AddAttribute
941
942 Description This function is called to add an attribute to a record.
943 This would be through the SDP database maintenance API.
944 If the attribute already exists in the record, it is
945 replaced with the new value.
946
947 NOTE Attribute values must be passed as a Big Endian stream.
948
949 Parameters: handle - (input) Handle to add
950 attr_id - (input) Attribute id to add
951 attr_type - (input) Attribute type to add
952 attr_len - (input) Attribute data length
953 p_val - (input) Attribute data value
954
955 Returns true if added OK, else false
956
957 ******************************************************************************/
958 bool (*SDP_AddAttribute)(uint32_t handle, uint16_t attr_id,
959 uint8_t attr_type, uint32_t attr_len,
960 uint8_t* p_val);
961
962 /*******************************************************************************
963
964 Function SDP_AddSequence
965
966 Description This function is called to add a sequence to a record.
967 This would be through the SDP database maintenance API.
968 If the sequence already exists in the record, it is
969 replaced with the new sequence.
970
971 NOTE Element values must be passed as a Big Endian stream.
972
973 Parameters: handle - (input) Handle to add
974 attr_id - (input) Attribute id to add
975 num_elem - (input) Number of elements in array
976 type[] - (input) Element type
977 len[] - (input) Element data length
978 p_val[] - (input) Element data value
979
980 Returns true if added OK, else false
981
982 ******************************************************************************/
983 bool (*SDP_AddSequence)(uint32_t handle, uint16_t attr_id,
984 uint16_t num_elem, uint8_t type[], uint8_t len[],
985 uint8_t* p_val[]);
986
987 /*******************************************************************************
988
989 Function SDP_AddUuidSequence
990
991 Description This function is called to add a UUID sequence to a
992 record. This would be through the SDP database
993 maintenance API. If the sequence already exists in the
994 record, it is replaced with the new sequence.
995
996 Parameters: handle - (input) Handle to add
997 attr_id - (input) Attribute id to add
998 num_uuids - (input) Number of uuids in array
999 p_uuids[] - (input) Array uuid
1000
1001 Returns true if added OK, else false
1002
1003 ******************************************************************************/
1004 bool (*SDP_AddUuidSequence)(uint32_t handle, uint16_t attr_id,
1005 uint16_t num_uuids, uint16_t* p_uuids);
1006
1007 /*******************************************************************************
1008
1009 Function SDP_AddProtocolList
1010
1011 Description This function is called to add a protocol descriptor
1012 list to a record. This would be through the SDP database
1013 maintenance API. If the protocol list already exists in
1014 the record, it is replaced with the new list.
1015
1016 Parameters: handle - (input) Handle to add
1017 num_elem - (input) Number of elements to add
1018 elem_list[]- (input) Element data list to add
1019
1020 Returns true if added OK, else false
1021
1022 ******************************************************************************/
1023 bool (*SDP_AddProtocolList)(uint32_t handle, uint16_t num_elem,
1024 tSDP_PROTOCOL_ELEM* p_elem_list);
1025
1026 /*******************************************************************************
1027
1028 Function SDP_AddAdditionProtoLists
1029
1030 Description This function is called to add a protocol descriptor
1031 list to a record. This would be through the SDP database
1032 maintenance API. If the protocol list already exists in
1033 the record, it is replaced with the new list.
1034
1035 Parameters: handle - (input) Handle to add
1036 num_elem - (input) Number of elements to add
1037 proto_list[]- (input) Element data list to add
1038
1039 Returns true if added OK, else false
1040
1041 ******************************************************************************/
1042 bool (*SDP_AddAdditionProtoLists)(uint32_t handle, uint16_t num_elem,
1043 tSDP_PROTO_LIST_ELEM* p_proto_list);
1044
1045 /*******************************************************************************
1046
1047 Function SDP_AddProfileDescriptorList
1048
1049 Description This function is called to add a profile descriptor list
1050 to a record. This would be through the SDP database
1051 maintenance API. If the version already exists in the
1052 record, it is replaced with the new one.
1053
1054 Parameters: handle - (input) Handle to add
1055 uuid - (input) Uuid to add
1056 version - (input) major and minor version
1057
1058 Returns true if added OK, else false
1059
1060 ******************************************************************************/
1061 bool (*SDP_AddProfileDescriptorList)(uint32_t handle, uint16_t profile_uuid,
1062 uint16_t version);
1063
1064 /*******************************************************************************
1065
1066 Function SDP_AddLanguageBaseAttrIDList
1067
1068 Description This function is called to add a language base attr list
1069 to a record. This would be through the SDP database
1070 maintenance API. If the version already exists in the
1071 record, it is replaced with the new one.
1072
1073 Parameters: handle - (input) Handle to add
1074 lang - (input) language base descriptor
1075 char_enc - (input) character encoding
1076 base_id - (input) base id
1077
1078 Returns true if added OK, else false
1079
1080 ******************************************************************************/
1081 bool (*SDP_AddLanguageBaseAttrIDList)(uint32_t handle, uint16_t lang,
1082 uint16_t char_enc, uint16_t base_id);
1083
1084 /*******************************************************************************
1085
1086 Function SDP_AddServiceClassIdList
1087
1088 Description This function is called to add a service list to a
1089 record. This would be through the SDP database
1090 maintenance API. If the service list already exists in
1091 the record, it is replaced with the new list.
1092
1093 Parameters: handle - (input) Handle to add
1094 num_services - (input) number of services to add
1095 uuids[] - (input) list of service uuids to add
1096
1097 Returns true if added OK, else false
1098
1099 ******************************************************************************/
1100 bool (*SDP_AddServiceClassIdList)(uint32_t handle, uint16_t num_services,
1101 uint16_t* p_service_uuids);
1102
1103 /*******************************************************************************
1104
1105 Function SDP_DeleteAttribute
1106
1107 Description Delete an attribute from a record.
1108 This would be through the SDP database maintenance API.
1109
1110 Parameters: handle - (input) Handle to add
1111 attr_id - (input) attribute id to delete
1112
1113 Returns true if deleted OK, else false if not found
1114
1115 ******************************************************************************/
1116 bool (*SDP_DeleteAttribute)(uint32_t handle, uint16_t attr_id);
1117 } handle;
1118
1119 struct {
1120 /*******************************************************************************
1121
1122 Device Identification API
1123
1124 Function SDP_SetLocalDiRecord
1125
1126 Description This function adds a DI record to the local SDP
1127 database.
1128
1129 Parameters: info - (input) device identification record
1130 p_handle - (output) handle of record if successful
1131
1132 Returns Returns SDP_SUCCESS if record added successfully, else
1133 error
1134
1135 ******************************************************************************/
1136 uint16_t (*SDP_SetLocalDiRecord)(const tSDP_DI_RECORD* device_info,
1137 uint32_t* p_handle);
1138
1139 /*******************************************************************************
1140
1141 Device Identification API
1142
1143 Function SDP_DiDiscover
1144
1145 Description This function queries a remote device for DI
1146 information.
1147
1148 Parameters: bd_addr - (input) remote device
1149 p_db - (input) dicovery database
1150 len - (input ) data base length
1151 p_cb - (input) callback when complete
1152
1153 Returns SDP_SUCCESS if query started successfully, else error
1154
1155 ******************************************************************************/
1156 tSDP_STATUS (*SDP_DiDiscover)(const RawAddress& remote_device,
1157 tSDP_DISCOVERY_DB* p_db, uint32_t len,
1158 tSDP_DISC_CMPL_CB* p_cb);
1159
1160 /*******************************************************************************
1161
1162 Device Identification API
1163
1164 Function SDP_GetNumDiRecords
1165
1166 Description Searches specified database for DI records
1167
1168 Parameters: p_db - (input) dicovery database
1169
1170 Returns number of DI records found
1171
1172 ******************************************************************************/
1173 uint8_t (*SDP_GetNumDiRecords)(const tSDP_DISCOVERY_DB* p_db);
1174
1175 /*******************************************************************************
1176
1177 Device Identification API
1178
1179 Function SDP_GetDiRecord
1180
1181 Description This function retrieves a remote device's DI record from
1182 the specified database.
1183
1184 Parameters: index - (input) record index to retrieve
1185 device_info - (input) dicovery database
1186 p_cb - (input) callback when complete
1187
1188 Returns SDP_SUCCESS if record retrieved, else error
1189
1190 ******************************************************************************/
1191 uint16_t (*SDP_GetDiRecord)(uint8_t getRecordIndex,
1192 tSDP_DI_GET_RECORD* device_info,
1193 const tSDP_DISCOVERY_DB* p_db);
1194
1195 } device_id;
1196 };
1197
1198 const struct tSdpApi* get_legacy_stack_sdp_api();
1199
1200 struct tLegacyStackSdbCallback {
1201 void(tSDP_DISC_CMPL_CB)(tSDP_RESULT result);
1202 void(tSDP_DISC_CMPL_CB2)(tSDP_RESULT result, const void* user_data);
1203 };
1204
1205 } // namespace sdp
1206 } // namespace stack
1207 } // namespace legacy
1208 } // namespace bluetooth
1209