summaryrefslogtreecommitdiff
path: root/system/stack/include/sdp_api.h
blob: a23ba0502d107f42669a73370d9e5331dfac7ea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
/******************************************************************************
 *
 *  Copyright 1999-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

#pragma once

#include <base/functional/callback_forward.h>

#include <cstdint>

#include "stack/include/sdp_callback.h"
#include "stack/include/sdp_device_id.h"
#include "stack/include/sdp_status.h"
#include "stack/include/sdpdefs.h"
#include "stack/sdp/internal/sdp_api.h"
#include "stack/sdp/sdp_discovery_db.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

namespace bluetooth {
namespace legacy {
namespace stack {
namespace sdp {

struct tSdpApi {
  struct {
    /*******************************************************************************
      Function         SDP_InitDiscoveryDb

      Description      This function is called to initialize a discovery
                       database.

      Parameters:      p_db        - (input) address of an area of memory where
                                             the discovery database is managed.
                       len         - (input) size (in bytes) of the memory
                        NOTE: This must be larger than sizeof(tSDP_DISCOVERY_DB)
                       num_uuid    - (input) number of UUID filters applied
                       p_uuid_list - (input) list of UUID filters
                       num_attr    - (input) number of attribute filters
                                             applied
                       p_attr_list - (input) list of attribute filters

      Returns          true if successful, false if one or more parameters are
                       bad
     ******************************************************************************/
    [[nodiscard]] bool (*SDP_InitDiscoveryDb)(tSDP_DISCOVERY_DB*, uint32_t, uint16_t,
                                              const bluetooth::Uuid*, uint16_t, const uint16_t*);

    /*******************************************************************************

      Function         SDP_CancelServiceSearch

      Description      This function cancels an active query to an SDP server.

      Parameters:      p_db        - (input) address of an area of memory where
                                             the discovery database is managed.

      Returns          true if discovery cancelled, false if a matching
                       activity is not found.

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_CancelServiceSearch)(const tSDP_DISCOVERY_DB*);

    /*******************************************************************************

      Function         SDP_ServiceSearchRequest

      Description      This function queries an SDP server for information.

      Parameters:      p_db        - (input) address of an area of memory where
                                             the discovery database is managed.
                       p_cb        - (input) callback executed when complete

      Returns          true if discovery started, false if failed.

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_ServiceSearchRequest)(const RawAddress&, tSDP_DISCOVERY_DB*,
                                                   tSDP_DISC_CMPL_CB*);

    /*******************************************************************************

      Function         SDP_ServiceSearchAttributeRequest

      Description      This function queries an SDP server for information.

                       The difference between this API function and the
                       function SDP_ServiceSearchRequest is that this one does
                       a combined ServiceSearchAttributeRequest SDP function.

      Parameters:      bd_addr     - (input) device address for service search
                       p_db        - (input) address of an area of memory where
                                             the discovery database is managed.
                       p_cb        - (input) callback executed when complete

      Returns          true if discovery started, false if failed.

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_ServiceSearchAttributeRequest)(const RawAddress&, tSDP_DISCOVERY_DB*,
                                                            tSDP_DISC_CMPL_CB*);

    /*******************************************************************************

      Function         SDP_ServiceSearchAttributeRequest2

      Description      This function queries an SDP server for information.

                       The difference between this API function and the
                       function SDP_ServiceSearchRequest is that this one does
                       a combined ServiceSearchAttributeRequest SDP function
                       with the user data piggyback

      parameters:      bd_addr     - (input) device address for service search
                       p_db        - (input) address of an area of memory where
                                             the discovery database is managed.
                       complete_callback - (input) callback executed when
     complete

      Returns          true if discovery started, false if failed.

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_ServiceSearchAttributeRequest2)(
            const RawAddress&, tSDP_DISCOVERY_DB*,
            base::RepeatingCallback<tSDP_DISC_CMPL_CB> complete_callback);
  } service;

  struct {
    /*******************************************************************************

      Function         SDP_FindServiceInDb

      Description      This function queries an SDP database for a specific
                       service. If the p_start_rec pointer is NULL, it looks
                       from the beginning of the database, else it continues
                       from the next record after p_start_rec.

      parameters:      p_db        - (input) address of an area of memory where
                                             the discovery database is managed.
                       uuid16      - (input) Uuid to search in db
                       disc_rec    - (output) Record found, null otherwise

      Returns          Pointer to record containing service class, or NULL

     ******************************************************************************/
    [[nodiscard]] tSDP_DISC_REC* (*SDP_FindServiceInDb)(const tSDP_DISCOVERY_DB*, uint16_t,
                                                        tSDP_DISC_REC*);

    /*******************************************************************************

      Function         SDP_FindServiceUUIDInDb

      Description      This function queries an SDP database for a specific
                       service. If the p_start_rec pointer is NULL, it looks
                       from the beginning of the database, else it continues
                       from the next record after p_start_rec.

      NOTE             the only difference between this function and the
                       previous function "SDP_FindServiceInDb()" is that this
                       function takes a Uuid input.

      parameters:      p_db        - (input) address of an area of memory where
                                             the discovery database is managed.
                       uuid        - (input) Uuid to search in db
                       disc_rec    - (input) Start record, null from beginning

      Returns          Pointer to record containing service class, or NULL

     ******************************************************************************/
    [[nodiscard]] tSDP_DISC_REC* (*SDP_FindServiceUUIDInDb)(const tSDP_DISCOVERY_DB*,
                                                            const bluetooth::Uuid&, tSDP_DISC_REC*);

    /*******************************************************************************

      Function         SDP_FindServiceInDb_128bit

      Description      Query an SDP database for a specific service.
                       If the p_start_rec pointer is NULL, look from the
                       beginning of the database, else continue from the next
                       record after p_start_rec.

      parameters:      p_db        - (input) address of an area of memory where
                                             the discovery database is managed.
                       disc_rec    - (input) Start record, null from beginning

      Returns          Pointer to record containing service class, or NULL

     ******************************************************************************/
    [[nodiscard]] tSDP_DISC_REC* (*SDP_FindServiceInDb_128bit)(const tSDP_DISCOVERY_DB*,
                                                               tSDP_DISC_REC*);
  } db;

  struct {
    /*******************************************************************************

      Local discovery database API

      Function         SDP_FindAttributeInRec

      Description      This function searches an SDP discovery record for a
                       specific attribute.

      parameters:      disc_rec    - (input) Start record must not be null
                       attr_id     - (input) Attribute id to search

      Returns          Pointer to matching attribute entry, or NULL

     ******************************************************************************/
    [[nodiscard]] tSDP_DISC_ATTR* (*SDP_FindAttributeInRec)(const tSDP_DISC_REC*, uint16_t);

    /*******************************************************************************

      Function         SDP_FindServiceUUIDInRec_128bit

      Description      Read the 128-bit service UUID within a record;
                       if there is any.

      Parameters:      p_rec      - (input) pointer to a SDP record.
                       p_uuid     - (output) parameter to save the UUID found.

      Returns          true if found, otherwise false.

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_FindServiceUUIDInRec_128bit)(const tSDP_DISC_REC*, bluetooth::Uuid*);

    /*******************************************************************************

      Function         SDP_FindProtocolListElemInRec

      Description      This function looks at a specific discovery record for a
                       protocol list element.

      Parameters:      p_rec      - (input) pointer to a SDP record.
                       p_uuid     - (input) layer UUID.
                       p_elem     - (output) protocol element

      Returns          true if found, false if not
                       If found, the passed protocol list element is filled in.

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_FindProtocolListElemInRec)(const tSDP_DISC_REC*, uint16_t,
                                                        tSDP_PROTOCOL_ELEM*);

    /*******************************************************************************

      Function         SDP_FindProfileVersionInRec

      Description      This function looks at a specific discovery record for
                       the Profile list descriptor, and pulls out the version
                       number. The version number consists of an 8-bit major
                       version and an 8-bit minor version.

      Parameters:      p_rec      - (input) pointer to a SDP record.
                       p_uuid     - (input) profile UUID.
                       p_elem     - (output) major and minor version numbers

      Returns          true if found, false if not

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_FindProfileVersionInRec)(const tSDP_DISC_REC*, uint16_t, uint16_t*);

    /*******************************************************************************

      Function         SDP_FindServiceUUIDInRec

      Description      Read the service UUID within a record;
                       if there is any.

      Parameters:      p_rec      - (input) pointer to a SDP record.
                       p_uuid     - (output) found UUID or null.

      Returns          true if found, otherwise false.

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_FindServiceUUIDInRec)(const tSDP_DISC_REC* p_rec,
                                                   bluetooth::Uuid* p_uuid);
  } record;

  struct {
    /*******************************************************************************

      API into SDP for Local service database updates

      Function         SDP_CreateRecord

      Description      This function is called to create a record in the
                       database. This would be through the SDP database
                       maintenance API. The record is created empty, the
                       application should then call "add_attribute" *to add
                       the record's attributes.

      Returns          Record handle if OK, else 0.

     ******************************************************************************/
    [[nodiscard]] uint32_t (*SDP_CreateRecord)(void);

    /*******************************************************************************

      Function         SDP_DeleteRecord

      Description      This function is called to add a record (or all records)
                       from the database. This would be through the SDP
                       database maintenance API.

      Parameters:      handle     - (input) Handle to delete, 0 for all records
                                            to be deleted

      Returns          true if succeeded, else false

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_DeleteRecord)(uint32_t);

    /*******************************************************************************

      Function         SDP_AddAttribute

      Description      This function is called to add an attribute to a record.
                       This would be through the SDP database maintenance API.
                       If the attribute already exists in the record, it is
                       replaced with the new value.

      NOTE             Attribute values must be passed as a Big Endian stream.

      Parameters:      handle     - (input) Handle to add
                       attr_id    - (input) Attribute id to add
                       attr_type  - (input) Attribute type to add
                       attr_len   - (input) Attribute data length
                       p_val      - (input) Attribute data value

      Returns          true if added OK, else false

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_AddAttribute)(uint32_t handle, uint16_t attr_id, uint8_t attr_type,
                                           uint32_t attr_len, uint8_t* p_val);

    /*******************************************************************************

      Function         SDP_AddSequence

      Description      This function is called to add a sequence to a record.
                       This would be through the SDP database maintenance API.
                       If the sequence already exists in the record, it is
                       replaced with the new sequence.

      NOTE             Element values must be passed as a Big Endian stream.

      Parameters:      handle     - (input) Handle to add
                       attr_id    - (input) Attribute id to add
                       num_elem   - (input) Number of elements in array
                       type[]     - (input) Element type
                       len[]      - (input) Element data length
                       p_val[]    - (input) Element data value

      Returns          true if added OK, else false

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_AddSequence)(uint32_t handle, uint16_t attr_id, uint16_t num_elem,
                                          uint8_t type[], uint8_t len[], uint8_t* p_val[]);

    /*******************************************************************************

      Function         SDP_AddUuidSequence

      Description      This function is called to add a UUID sequence to a
                       record. This would be through the SDP database
                       maintenance API. If the sequence already exists in the
                      record, it is replaced with the new sequence.

      Parameters:      handle     - (input) Handle to add
                       attr_id    - (input) Attribute id to add
                       num_uuids  - (input) Number of uuids in array
                       p_uuids[]  - (input) Array uuid

      Returns          true if added OK, else false

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_AddUuidSequence)(uint32_t handle, uint16_t attr_id, uint16_t num_uuids,
                                              uint16_t* p_uuids);

    /*******************************************************************************

      Function         SDP_AddProtocolList

      Description      This function is called to add a protocol descriptor
                       list to a record. This would be through the SDP database
                       maintenance API. If the protocol list already exists in
                       the record, it is replaced with the new list.

      Parameters:      handle     - (input) Handle to add
                       num_elem   - (input) Number of elements to add
                       elem_list[]- (input) Element data list to add

      Returns          true if added OK, else false

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_AddProtocolList)(uint32_t handle, uint16_t num_elem,
                                              tSDP_PROTOCOL_ELEM* p_elem_list);

    /*******************************************************************************

      Function         SDP_AddAdditionProtoLists

      Description      This function is called to add a protocol descriptor
                       list to a record. This would be through the SDP database
                       maintenance API. If the protocol list already exists in
                       the record, it is replaced with the new list.

      Parameters:      handle     - (input) Handle to add
                       num_elem   - (input) Number of elements to add
                       proto_list[]- (input) Element data list to add

      Returns          true if added OK, else false

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_AddAdditionProtoLists)(uint32_t handle, uint16_t num_elem,
                                                    tSDP_PROTO_LIST_ELEM* p_proto_list);

    /*******************************************************************************

      Function         SDP_AddProfileDescriptorList

      Description      This function is called to add a profile descriptor list
                       to a record. This would be through the SDP database
                       maintenance API. If the version already exists in the
                       record, it is replaced with the new one.

      Parameters:      handle     - (input) Handle to add
                       uuid       - (input) Uuid to add
                       version    - (input) major and minor version

      Returns          true if added OK, else false

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_AddProfileDescriptorList)(uint32_t handle, uint16_t profile_uuid,
                                                       uint16_t version);

    /*******************************************************************************

      Function         SDP_AddLanguageBaseAttrIDList

      Description      This function is called to add a language base attr list
                       to a record. This would be through the SDP database
                       maintenance API. If the version already exists in the
                       record, it is replaced with the new one.

      Parameters:      handle     - (input) Handle to add
                       lang       - (input) language base descriptor
                       char_enc   - (input) character encoding
                       base_id    - (input) base id

      Returns          true if added OK, else false

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_AddLanguageBaseAttrIDList)(uint32_t handle, uint16_t lang,
                                                        uint16_t char_enc, uint16_t base_id);

    /*******************************************************************************

      Function         SDP_AddServiceClassIdList

      Description      This function is called to add a service list to a
                       record. This would be through the SDP database
                       maintenance API. If the service list already exists in
                       the record, it is replaced with the new list.

      Parameters:      handle       - (input) Handle to add
                       num_services - (input) number of services to add
                       uuids[]      - (input) list of service uuids to add

      Returns          true if added OK, else false

     ******************************************************************************/
    [[nodiscard]] bool (*SDP_AddServiceClassIdList)(uint32_t handle, uint16_t num_services,
                                                    uint16_t* p_service_uuids);
  } handle;

  struct {
    /*******************************************************************************

      Device Identification API

      Function         SDP_SetLocalDiRecord

      Description      This function adds a DI record to the local SDP
                       database.

      Parameters:      info         - (input) device identification record
                       p_handle     - (output) handle of record if successful

      Returns          Returns tSDP_STATUS::SDP_SUCCESS if record added successfully, else
                       error

     ******************************************************************************/
    [[nodiscard]] tSDP_STATUS (*SDP_SetLocalDiRecord)(const tSDP_DI_RECORD* device_info,
                                                      uint32_t* p_handle);

    /*******************************************************************************

      Device Identification API

      Function         SDP_DiDiscover

      Description      This function queries a remote device for DI
                       information.

      Parameters:      bd_addr      - (input) remote device
                       p_db         - (input) dicovery database
                       len          - (input ) data base length
                       p_cb         - (input) callback when complete

      Returns          tSDP_STATUS::SDP_SUCCESS if query started successfully, else error

     ******************************************************************************/
    [[nodiscard]] tSDP_STATUS (*SDP_DiDiscover)(const RawAddress& remote_device,
                                                tSDP_DISCOVERY_DB* p_db, uint32_t len,
                                                tSDP_DISC_CMPL_CB* p_cb);

    /*******************************************************************************

      Device Identification API

      Function         SDP_GetNumDiRecords

      Description      Searches specified database for DI records

      Parameters:      p_db         - (input) dicovery database

      Returns          number of DI records found

     ******************************************************************************/
    [[nodiscard]] uint8_t (*SDP_GetNumDiRecords)(const tSDP_DISCOVERY_DB* p_db);

    /*******************************************************************************

      Device Identification API

      Function         SDP_GetDiRecord

      Description      This function retrieves a remote device's DI record from
                       the specified database.

      Parameters:      index        - (input) record index to retrieve
                       device_info  - (input) dicovery database
                       p_cb         - (input) callback when complete

      Returns          tSDP_STATUS::SDP_SUCCESS if record retrieved, else error

     ******************************************************************************/
    [[nodiscard]] tSDP_STATUS (*SDP_GetDiRecord)(uint8_t getRecordIndex,
                                                 tSDP_DI_GET_RECORD* device_info,
                                                 const tSDP_DISCOVERY_DB* p_db);
  } device_id;
};

const struct tSdpApi* get_legacy_stack_sdp_api();

struct tLegacyStackSdbCallback {
  void(tSDP_DISC_CMPL_CB)(const RawAddress& bd_addr, tSDP_RESULT result);
  void(tSDP_DISC_CMPL_CB2)(const RawAddress& bd_addr, tSDP_RESULT result, const void* user_data);
};

}  // namespace sdp
}  // namespace stack
}  // namespace legacy
}  // namespace bluetooth

/*******************************************************************************
 *
 * Function         SDP_Dumpsys
 *
 * Description      Dumps readable content of the module to the filedescriptor
 *
 * Parameters:      fd        - Valid file descriptor
 *
 * Returns          None
 *
 ******************************************************************************/
void SDP_Dumpsys(int fd);