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 <cstdint>
22 
23 #include "internal_include/bt_target.h"
24 #include "types/bluetooth/uuid.h"
25 #include "types/raw_address.h"
26 
27 /* Masks for attr_value field of tSDP_DISC_ATTR */
28 #define SDP_DISC_ATTR_LEN_MASK 0x0FFF
29 #define SDP_DISC_ATTR_TYPE(len_type) ((len_type) >> 12)
30 #define SDP_DISC_ATTR_LEN(len_type) ((len_type) & SDP_DISC_ATTR_LEN_MASK)
31 
32 #define SDP_MAX_LIST_ELEMS 3
33 
34 /* Define a structure to hold the discovered service information. */
35 struct tSDP_DISC_ATVAL {
36   union {
37     uint8_t u8;                         /* 8-bit integer            */
38     uint16_t u16;                       /* 16-bit integer           */
39     uint32_t u32;                       /* 32-bit integer           */
40     struct tSDP_DISC_ATTR* p_sub_attr;  /* Addr of first sub-attr (list)*/
41     uint8_t array[];                    /* Variable length field    */
42                                         /* flexible array member    */
43                                         /* requiring backing store  */
44                                         /* from SDP DB    */
45   } v;
46 };
47 
48 struct tSDP_DISC_ATTR {
49   struct tSDP_DISC_ATTR* p_next_attr;  /* Addr of next linked attr     */
50   uint16_t attr_id;                    /* Attribute ID                 */
51   uint16_t attr_len_type;              /* Length and type fields       */
52   tSDP_DISC_ATVAL attr_value;          /* Variable length entry data   */
53 };
54 
55 struct tSDP_DISC_REC {
56   tSDP_DISC_ATTR* p_first_attr;      /* First attribute of record    */
57   struct tSDP_DISC_REC* p_next_rec;  /* Addr of next linked record   */
58   uint32_t time_read;                /* The time the record was read */
59   RawAddress remote_bd_addr;         /* Remote BD address            */
60 };
61 
62 // Typedef alias used by profiles
63 typedef tSDP_DISC_REC t_sdp_disc_rec;
64 
65 struct tSDP_DISCOVERY_DB {
66   uint32_t mem_size;                                  /* Memory size of the DB        */
67   uint32_t mem_free;                                  /* Memory still available       */
68   tSDP_DISC_REC* p_first_rec;                         /* Addr of first record in DB   */
69   uint16_t num_uuid_filters;                          /* Number of UUIds to filter    */
70   bluetooth::Uuid uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */
71   uint16_t num_attr_filters;                          /* Number of attribute filters  */
72   uint16_t attr_filters[SDP_MAX_ATTR_FILTERS];        /* Attributes to filter */
73   uint8_t* p_free_mem;                                /* Pointer to free memory       */
74   uint8_t* raw_data; /* Received record from server. allocated/released by client  */
75   uint32_t raw_size; /* size of raw_data */
76   uint32_t raw_used; /* length of raw_data used */
77 };
78 
79 /* This structure is used to add protocol lists and find protocol elements */
80 struct tSDP_PROTOCOL_ELEM {
81   uint16_t protocol_uuid;
82   uint16_t num_params;
83   uint16_t params[SDP_MAX_PROTOCOL_PARAMS];
84 };
85 
86 struct tSDP_PROTO_LIST_ELEM {
87   uint16_t num_elems;
88   tSDP_PROTOCOL_ELEM list_elem[SDP_MAX_LIST_ELEMS];
89 };
90