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