1 /******************************************************************************
2 *
3 * Copyright 2015 The Android Open Source Project
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 /******************************************************************************
20 *
21 * This is the public interface file for the BTA SDP I/F
22 *
23 ******************************************************************************/
24 #ifndef BTA_SDP_API_H
25 #define BTA_SDP_API_H
26
27 #include <cstdint>
28 #include <string>
29
30 #include "include/hardware/bt_sdp.h" // bluetooth_sdp_record
31 #include "macros.h"
32 #include "stack/sdp/sdp_discovery_db.h"
33 #include "types/bluetooth/uuid.h"
34 #include "types/raw_address.h"
35
36 using bluetooth::Uuid;
37
38 /* status values */
39 typedef enum : uint8_t {
40 BTA_SDP_SUCCESS = 0, /* Successful operation. */
41 BTA_SDP_FAILURE = 1, /* Generic failure. */
42 BTA_SDP_BUSY = 2, /* Temporarily can not handle this request. */
43 } tBTA_SDP_STATUS;
44
bta_sdp_status_text(const tBTA_SDP_STATUS & status)45 inline std::string bta_sdp_status_text(const tBTA_SDP_STATUS& status) {
46 switch (status) {
47 CASE_RETURN_TEXT(BTA_SDP_SUCCESS);
48 CASE_RETURN_TEXT(BTA_SDP_FAILURE);
49 CASE_RETURN_TEXT(BTA_SDP_BUSY);
50 default:
51 return std::format("UNKNOWN[{}]", static_cast<uint8_t>(status));
52 }
53 }
54
55 /* SDP I/F callback events */
56 /* events received by tBTA_SDP_DM_CBACK */
57 #define BTA_SDP_ENABLE_EVT 0 /* SDP service i/f enabled*/
58 #define BTA_SDP_SEARCH_EVT 1 /* SDP Service started */
59 #define BTA_SDP_SEARCH_COMP_EVT 2 /* SDP search complete */
60 #define BTA_SDP_CREATE_RECORD_USER_EVT 3 /* SDP search complete */
61 #define BTA_SDP_REMOVE_RECORD_USER_EVT 4 /* SDP search complete */
62 #define BTA_SDP_MAX_EVT 5 /* max number of SDP events */
63
64 #define BTA_SDP_MAX_RECORDS 15
65
66 typedef uint16_t tBTA_SDP_EVT;
67
68 /* data associated with BTA_SDP_DISCOVERY_COMP_EVT */
69 typedef struct {
70 tBTA_SDP_STATUS status;
71 RawAddress remote_addr;
72 bluetooth::Uuid uuid;
73 int record_count;
74 bluetooth_sdp_record records[BTA_SDP_MAX_RECORDS];
75 } tBTA_SDP_SEARCH_COMP;
76
77 typedef union {
78 tBTA_SDP_STATUS status; /* BTA_SDP_SEARCH_EVT */
79 tBTA_SDP_SEARCH_COMP sdp_search_comp; /* BTA_SDP_SEARCH_COMP_EVT */
80 } tBTA_SDP;
81
82 /* SDP DM Interface callback */
83 typedef void(tBTA_SDP_DM_CBACK)(tBTA_SDP_EVT event, tBTA_SDP* p_data, void* user_data);
84
85 /* MCE configuration structure */
86 typedef struct {
87 uint16_t sdp_db_size; /* The size of p_sdp_db */
88 tSDP_DISCOVERY_DB* p_sdp_db; /* The data buffer to keep SDP database */
89 } tBTA_SDP_CFG;
90
91 /*******************************************************************************
92 *
93 * Function BTA_SdpEnable
94 *
95 * Description Enable the SDP I/F service. When the enable
96 * operation is complete the callback function will be
97 * called with a BTA_SDP_ENABLE_EVT. This function must
98 * be called before other functions in the MCE API are
99 * called.
100 *
101 * Returns BTA_SDP_SUCCESS if successful.
102 * BTA_SDP_FAIL if internal failure.
103 *
104 ******************************************************************************/
105 tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK* p_cback);
106
107 /*******************************************************************************
108 *
109 * Function BTA_SdpSearch
110 *
111 * Description Start a search for sdp records for a specific BD_ADDR with a
112 * specific profile uuid.
113 * When the search operation is completed, the callback
114 * function will be called with a BTA_SDP_SEARCH_EVT.
115 * Returns BTA_SDP_SUCCESS if successful.
116 * BTA_SDP_FAIL if internal failure.
117 *
118 ******************************************************************************/
119 tBTA_SDP_STATUS BTA_SdpSearch(const RawAddress& bd_addr, const bluetooth::Uuid& uuid);
120
121 /*******************************************************************************
122 *
123 * Function BTA_SdpCreateRecordByUser
124 *
125 * Description This function is used to request a callback to create a SDP
126 * record. The registered callback will be called with event
127 * BTA_SDP_CREATE_RECORD_USER_EVT.
128 *
129 * Returns BTA_SDP_SUCCESS, if the request is being processed.
130 * BTA_SDP_FAILURE, otherwise.
131 *
132 ******************************************************************************/
133 tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data);
134
135 /*******************************************************************************
136 *
137 * Function BTA_SdpRemoveRecordByUser
138 *
139 * Description This function is used to request a callback to remove a SDP
140 * record. The registered callback will be called with event
141 * BTA_SDP_REMOVE_RECORD_USER_EVT.
142 *
143 * Returns BTA_SDP_SUCCESS, if the request is being processed.
144 * BTA_SDP_FAILURE, otherwise.
145 *
146 ******************************************************************************/
147 tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void* user_data);
148
149 #endif /* BTA_SDP_API_H */
150