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 typedef struct {
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 t_sdp_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 } tSDP_DISC_ATVAL;
48 
49 typedef struct t_sdp_disc_attr {
50   struct t_sdp_disc_attr* p_next_attr; /* Addr of next linked attr     */
51   uint16_t attr_id;                    /* Attribute ID                 */
52   uint16_t attr_len_type;              /* Length and type fields       */
53   tSDP_DISC_ATVAL attr_value;          /* Variable length entry data   */
54 } tSDP_DISC_ATTR;
55 
56 typedef struct t_sdp_disc_rec {
57   tSDP_DISC_ATTR* p_first_attr;      /* First attribute of record    */
58   struct t_sdp_disc_rec* p_next_rec; /* Addr of next linked record   */
59   uint32_t time_read;                /* The time the record was read */
60   RawAddress remote_bd_addr;         /* Remote BD address            */
61 } tSDP_DISC_REC;
62 
63 typedef struct {
64   uint32_t mem_size;          /* Memory size of the DB        */
65   uint32_t mem_free;          /* Memory still available       */
66   tSDP_DISC_REC* p_first_rec; /* Addr of first record in DB   */
67   uint16_t num_uuid_filters;  /* Number of UUIds to filter    */
68   bluetooth::Uuid uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */
69   uint16_t num_attr_filters; /* Number of attribute filters  */
70   uint16_t attr_filters[SDP_MAX_ATTR_FILTERS]; /* Attributes to filter */
71   uint8_t* p_free_mem; /* Pointer to free memory       */
72   uint8_t*
73       raw_data; /* Received record from server. allocated/released by client  */
74   uint32_t raw_size; /* size of raw_data */
75   uint32_t raw_used; /* length of raw_data used */
76 } tSDP_DISCOVERY_DB;
77 
78 /* This structure is used to add protocol lists and find protocol elements */
79 typedef struct {
80   uint16_t protocol_uuid;
81   uint16_t num_params;
82   uint16_t params[SDP_MAX_PROTOCOL_PARAMS];
83 } tSDP_PROTOCOL_ELEM;
84 
85 typedef struct {
86   uint16_t num_elems;
87   tSDP_PROTOCOL_ELEM list_elem[SDP_MAX_LIST_ELEMS];
88 } tSDP_PROTO_LIST_ELEM;
89