blob: ea6941cdb46d0a030361372b565adf95e3d297cd [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07003 * Copyright 1999-2012 Broadcom Corporation
The Android Open Source Project5738f832012-12-12 16:00:35 -08004 *
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 file contains internally used SDP definitions
22 *
23 ******************************************************************************/
24
Myles Watson911d1ae2016-11-28 16:44:40 -080025#ifndef SDP_INT_H
26#define SDP_INT_H
The Android Open Source Project5738f832012-12-12 16:00:35 -080027
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -070028#include "bluetooth/uuid.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080029#include "bt_target.h"
Myles Watson911d1ae2016-11-28 16:44:40 -080030#include "l2c_api.h"
Pavlin Radoslavov78bcff72015-12-04 17:36:34 -080031#include "osi/include/alarm.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080032#include "sdp_api.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080033
The Android Open Source Project5738f832012-12-12 16:00:35 -080034/* Continuation length - we use a 2-byte offset */
Myles Watson911d1ae2016-11-28 16:44:40 -080035#define SDP_CONTINUATION_LEN 2
36#define SDP_MAX_CONTINUATION_LEN 16 /* As per the spec */
The Android Open Source Project5738f832012-12-12 16:00:35 -080037
38/* Timeout definitions. */
Myles Watson911d1ae2016-11-28 16:44:40 -080039#define SDP_INACT_TIMEOUT_MS (30 * 1000) /* Inactivity timeout (in ms) */
The Android Open Source Project5738f832012-12-12 16:00:35 -080040
The Android Open Source Project5738f832012-12-12 16:00:35 -080041/* Define the Protocol Data Unit (PDU) types.
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -070042 */
Myles Watson911d1ae2016-11-28 16:44:40 -080043#define SDP_PDU_ERROR_RESPONSE 0x01
44#define SDP_PDU_SERVICE_SEARCH_REQ 0x02
45#define SDP_PDU_SERVICE_SEARCH_RSP 0x03
46#define SDP_PDU_SERVICE_ATTR_REQ 0x04
47#define SDP_PDU_SERVICE_ATTR_RSP 0x05
48#define SDP_PDU_SERVICE_SEARCH_ATTR_REQ 0x06
49#define SDP_PDU_SERVICE_SEARCH_ATTR_RSP 0x07
The Android Open Source Project5738f832012-12-12 16:00:35 -080050
51/* Max UUIDs and attributes we support per sequence */
Myles Watson911d1ae2016-11-28 16:44:40 -080052#define MAX_UUIDS_PER_SEQ 16
53#define MAX_ATTR_PER_SEQ 16
The Android Open Source Project5738f832012-12-12 16:00:35 -080054
55/* Max length we support for any attribute */
The Android Open Source Project5738f832012-12-12 16:00:35 -080056#ifdef SDP_MAX_ATTR_LEN
57#define MAX_ATTR_LEN SDP_MAX_ATTR_LEN
58#else
Myles Watson911d1ae2016-11-28 16:44:40 -080059#define MAX_ATTR_LEN 256
The Android Open Source Project5738f832012-12-12 16:00:35 -080060#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -080061
62/* Internal UUID sequence representation */
Myles Watson911d1ae2016-11-28 16:44:40 -080063typedef struct {
64 uint16_t len;
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -070065 uint8_t value[bluetooth::Uuid::kNumBytes128];
The Android Open Source Project5738f832012-12-12 16:00:35 -080066} tUID_ENT;
67
Myles Watson911d1ae2016-11-28 16:44:40 -080068typedef struct {
69 uint16_t num_uids;
70 tUID_ENT uuid_entry[MAX_UUIDS_PER_SEQ];
The Android Open Source Project5738f832012-12-12 16:00:35 -080071} tSDP_UUID_SEQ;
72
The Android Open Source Project5738f832012-12-12 16:00:35 -080073/* Internal attribute sequence definitions */
Myles Watson911d1ae2016-11-28 16:44:40 -080074typedef struct {
75 uint16_t start;
76 uint16_t end;
The Android Open Source Project5738f832012-12-12 16:00:35 -080077} tATT_ENT;
78
Myles Watson911d1ae2016-11-28 16:44:40 -080079typedef struct {
80 uint16_t num_attr;
81 tATT_ENT attr_entry[MAX_ATTR_PER_SEQ];
The Android Open Source Project5738f832012-12-12 16:00:35 -080082} tSDP_ATTR_SEQ;
83
The Android Open Source Project5738f832012-12-12 16:00:35 -080084/* Define the attribute element of the SDP database record */
Myles Watson911d1ae2016-11-28 16:44:40 -080085typedef struct {
86 uint32_t len; /* Number of bytes in the entry */
87 uint8_t* value_ptr; /* Points to attr_pad */
88 uint16_t id;
89 uint8_t type;
The Android Open Source Project5738f832012-12-12 16:00:35 -080090} tSDP_ATTRIBUTE;
91
92/* An SDP record consists of a handle, and 1 or more attributes */
Myles Watson911d1ae2016-11-28 16:44:40 -080093typedef struct {
94 uint32_t record_handle;
95 uint32_t free_pad_ptr;
96 uint16_t num_attributes;
97 tSDP_ATTRIBUTE attribute[SDP_MAX_REC_ATTR];
98 uint8_t attr_pad[SDP_MAX_PAD_LEN];
The Android Open Source Project5738f832012-12-12 16:00:35 -080099} tSDP_RECORD;
100
The Android Open Source Project5738f832012-12-12 16:00:35 -0800101/* Define the SDP database */
Myles Watson911d1ae2016-11-28 16:44:40 -0800102typedef struct {
103 uint32_t
104 di_primary_handle; /* Device ID Primary record or NULL if nonexistent */
105 uint16_t num_records;
106 tSDP_RECORD record[SDP_MAX_RECORDS];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800107} tSDP_DB;
108
Marie Janssend19e0782016-07-15 12:48:27 -0700109#if (SDP_SERVER_ENABLED == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800110/* Continuation information for the SDP server response */
Myles Watson911d1ae2016-11-28 16:44:40 -0800111typedef struct {
112 uint16_t next_attr_index; /* attr index for next continuation response */
113 uint16_t next_attr_start_id; /* attr id to start with for the attr index in
114 next cont. response */
115 tSDP_RECORD* prev_sdp_rec; /* last sdp record that was completely sent in the
116 response */
117 bool last_attr_seq_desc_sent; /* whether attr seq length has been sent
118 previously */
119 uint16_t attr_offset; /* offset within the attr to keep trak of partial
120 attributes in the responses */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800121} tSDP_CONT_INFO;
Myles Watson911d1ae2016-11-28 16:44:40 -0800122#endif /* SDP_SERVER_ENABLED == TRUE */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800123
124/* Define the SDP Connection Control Block */
Myles Watson911d1ae2016-11-28 16:44:40 -0800125typedef struct {
126#define SDP_STATE_IDLE 0
127#define SDP_STATE_CONN_SETUP 1
128#define SDP_STATE_CFG_SETUP 2
129#define SDP_STATE_CONNECTED 3
130 uint8_t con_state;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800131
Myles Watson911d1ae2016-11-28 16:44:40 -0800132#define SDP_FLAGS_IS_ORIG 0x01
133#define SDP_FLAGS_HIS_CFG_DONE 0x02
134#define SDP_FLAGS_MY_CFG_DONE 0x04
135 uint8_t con_flags;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800136
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700137 RawAddress device_address;
Myles Watson911d1ae2016-11-28 16:44:40 -0800138 alarm_t* sdp_conn_timer;
139 uint16_t rem_mtu_size;
140 uint16_t connection_id;
141 uint16_t list_len; /* length of the response in the GKI buffer */
142 uint8_t* rsp_list; /* pointer to GKI buffer holding response */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800143
Myles Watson911d1ae2016-11-28 16:44:40 -0800144 tSDP_DISCOVERY_DB* p_db; /* Database to save info into */
145 tSDP_DISC_CMPL_CB* p_cb; /* Callback for discovery done */
146 tSDP_DISC_CMPL_CB2*
147 p_cb2; /* Callback for discovery done piggy back with the user data */
148 void* user_data; /* piggy back user data */
149 uint32_t
150 handles[SDP_MAX_DISC_SERVER_RECS]; /* Discovered server record handles */
151 uint16_t num_handles; /* Number of server handles */
152 uint16_t cur_handle; /* Current handle being processed */
153 uint16_t transaction_id;
154 uint16_t disconnect_reason; /* Disconnect reason */
Marie Janssend19e0782016-07-15 12:48:27 -0700155#if (SDP_BROWSE_PLUS == TRUE)
Myles Watson911d1ae2016-11-28 16:44:40 -0800156 uint16_t cur_uuid_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800157#endif
158
Myles Watson911d1ae2016-11-28 16:44:40 -0800159#define SDP_DISC_WAIT_CONN 0
160#define SDP_DISC_WAIT_HANDLES 1
161#define SDP_DISC_WAIT_ATTR 2
162#define SDP_DISC_WAIT_SEARCH_ATTR 3
163#define SDP_DISC_WAIT_CANCEL 5
The Android Open Source Project5738f832012-12-12 16:00:35 -0800164
Myles Watson911d1ae2016-11-28 16:44:40 -0800165 uint8_t disc_state;
166 uint8_t is_attr_search;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800167
Marie Janssend19e0782016-07-15 12:48:27 -0700168#if (SDP_SERVER_ENABLED == TRUE)
Myles Watson911d1ae2016-11-28 16:44:40 -0800169 uint16_t cont_offset; /* Continuation state data in the server response */
170 tSDP_CONT_INFO cont_info; /* structure to hold continuation information for
171 the server response */
172#endif /* SDP_SERVER_ENABLED == TRUE */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800173
174} tCONN_CB;
175
The Android Open Source Project5738f832012-12-12 16:00:35 -0800176/* The main SDP control block */
Myles Watson911d1ae2016-11-28 16:44:40 -0800177typedef struct {
178 tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */
179 tCONN_CB ccb[SDP_MAX_CONNECTIONS];
Marie Janssend19e0782016-07-15 12:48:27 -0700180#if (SDP_SERVER_ENABLED == TRUE)
Myles Watson911d1ae2016-11-28 16:44:40 -0800181 tSDP_DB server_db;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800182#endif
Myles Watson911d1ae2016-11-28 16:44:40 -0800183 tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */
184 uint16_t max_attr_list_size; /* Max attribute list size to use */
185 uint16_t max_recs_per_search; /* Max records we want per seaarch */
186 uint8_t trace_level;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800187} tSDP_CB;
188
The Android Open Source Project5738f832012-12-12 16:00:35 -0800189/* Global SDP data */
Myles Watson911d1ae2016-11-28 16:44:40 -0800190extern tSDP_CB sdp_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800191
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -0700192/* Functions provided by sdp_main.cc */
Myles Watson911d1ae2016-11-28 16:44:40 -0800193extern void sdp_init(void);
Pavlin Radoslavovef6a4a02018-01-11 17:28:16 -0800194extern void sdp_free(void);
Myles Watson911d1ae2016-11-28 16:44:40 -0800195extern void sdp_disconnect(tCONN_CB* p_ccb, uint16_t reason);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800196
Myles Watson911d1ae2016-11-28 16:44:40 -0800197extern void sdp_conn_timer_timeout(void* data);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800198
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700199extern tCONN_CB* sdp_conn_originate(const RawAddress& p_bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800200
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -0700201/* Functions provided by sdp_utils.cc
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700202 */
Jack Hed62d5972019-02-01 18:30:21 -0800203extern void sdpu_log_attribute_metrics(const RawAddress& bda,
204 tSDP_DISCOVERY_DB* p_db);
Myles Watson911d1ae2016-11-28 16:44:40 -0800205extern tCONN_CB* sdpu_find_ccb_by_cid(uint16_t cid);
206extern tCONN_CB* sdpu_find_ccb_by_db(tSDP_DISCOVERY_DB* p_db);
207extern tCONN_CB* sdpu_allocate_ccb(void);
208extern void sdpu_release_ccb(tCONN_CB* p_ccb);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800209
Myles Watson911d1ae2016-11-28 16:44:40 -0800210extern uint8_t* sdpu_build_attrib_seq(uint8_t* p_out, uint16_t* p_attr,
211 uint16_t num_attrs);
212extern uint8_t* sdpu_build_attrib_entry(uint8_t* p_out, tSDP_ATTRIBUTE* p_attr);
213extern void sdpu_build_n_send_error(tCONN_CB* p_ccb, uint16_t trans_num,
214 uint16_t error_code, char* p_error_text);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800215
Myles Watson911d1ae2016-11-28 16:44:40 -0800216extern uint8_t* sdpu_extract_attr_seq(uint8_t* p, uint16_t param_len,
217 tSDP_ATTR_SEQ* p_seq);
218extern uint8_t* sdpu_extract_uid_seq(uint8_t* p, uint16_t param_len,
219 tSDP_UUID_SEQ* p_seq);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800220
Ted Wang3a967722019-04-29 10:11:04 +0800221extern uint8_t* sdpu_get_len_from_type(uint8_t* p, uint8_t* p_end, uint8_t type,
Myles Watson911d1ae2016-11-28 16:44:40 -0800222 uint32_t* p_len);
223extern bool sdpu_is_base_uuid(uint8_t* p_uuid);
224extern bool sdpu_compare_uuid_arrays(uint8_t* p_uuid1, uint32_t len1,
225 uint8_t* p_uuid2, uint16_t len2);
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700226extern bool sdpu_compare_uuid_with_attr(const bluetooth::Uuid& uuid,
Myles Watson911d1ae2016-11-28 16:44:40 -0800227 tSDP_DISC_ATTR* p_attr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800228
Myles Watson911d1ae2016-11-28 16:44:40 -0800229extern void sdpu_sort_attr_list(uint16_t num_attr, tSDP_DISCOVERY_DB* p_db);
230extern uint16_t sdpu_get_list_len(tSDP_UUID_SEQ* uid_seq,
231 tSDP_ATTR_SEQ* attr_seq);
232extern uint16_t sdpu_get_attrib_seq_len(tSDP_RECORD* p_rec,
233 tSDP_ATTR_SEQ* attr_seq);
234extern uint16_t sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE* p_attr);
235extern uint8_t* sdpu_build_partial_attrib_entry(uint8_t* p_out,
236 tSDP_ATTRIBUTE* p_attr,
237 uint16_t len, uint16_t* offset);
Ted Wangf875ec42020-05-18 18:02:34 +0800238extern uint16_t sdpu_is_avrcp_profile_description_list(tSDP_ATTRIBUTE* p_attr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800239
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -0700240/* Functions provided by sdp_db.cc
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700241 */
Myles Watson911d1ae2016-11-28 16:44:40 -0800242extern tSDP_RECORD* sdp_db_service_search(tSDP_RECORD* p_rec,
243 tSDP_UUID_SEQ* p_seq);
244extern tSDP_RECORD* sdp_db_find_record(uint32_t handle);
245extern tSDP_ATTRIBUTE* sdp_db_find_attr_in_rec(tSDP_RECORD* p_rec,
246 uint16_t start_attr,
247 uint16_t end_attr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800248
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -0700249/* Functions provided by sdp_server.cc
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700250 */
Marie Janssend19e0782016-07-15 12:48:27 -0700251#if (SDP_SERVER_ENABLED == TRUE)
Myles Watson911d1ae2016-11-28 16:44:40 -0800252extern void sdp_server_handle_client_req(tCONN_CB* p_ccb, BT_HDR* p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800253#else
254#define sdp_server_handle_client_req(p_ccb, p_msg)
255#endif
256
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -0700257/* Functions provided by sdp_discovery.cc
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700258 */
Myles Watson911d1ae2016-11-28 16:44:40 -0800259extern void sdp_disc_connected(tCONN_CB* p_ccb);
260extern void sdp_disc_server_rsp(tCONN_CB* p_ccb, BT_HDR* p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800261
The Android Open Source Project5738f832012-12-12 16:00:35 -0800262#endif