blob: 770bf7fed85afc83665542fdf567218dbb691bd9 [file] [log] [blame]
The Android Open Source Project624a7872012-12-12 16:00:35 -08001/******************************************************************************
2 *
Jakub Pawlowski3b10fdd2017-09-18 09:00:20 -07003 * Copyright 1999-2012 Broadcom Corporation
The Android Open Source Project624a7872012-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 Watsonf8a21202016-11-28 16:44:40 -080025#ifndef SDP_INT_H
26#define SDP_INT_H
The Android Open Source Project624a7872012-12-12 16:00:35 -080027
Jakub Pawlowski2238a882017-07-10 09:56:09 -070028#include "bluetooth/uuid.h"
The Android Open Source Project624a7872012-12-12 16:00:35 -080029#include "bt_target.h"
Myles Watsonf8a21202016-11-28 16:44:40 -080030#include "l2c_api.h"
Pavlin Radoslavov30698fa2015-12-04 17:36:34 -080031#include "osi/include/alarm.h"
The Android Open Source Project624a7872012-12-12 16:00:35 -080032#include "sdp_api.h"
The Android Open Source Project624a7872012-12-12 16:00:35 -080033
The Android Open Source Project624a7872012-12-12 16:00:35 -080034/* Continuation length - we use a 2-byte offset */
Myles Watsonf8a21202016-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 Project624a7872012-12-12 16:00:35 -080037
38/* Timeout definitions. */
Myles Watsonf8a21202016-11-28 16:44:40 -080039#define SDP_INACT_TIMEOUT_MS (30 * 1000) /* Inactivity timeout (in ms) */
The Android Open Source Project624a7872012-12-12 16:00:35 -080040
The Android Open Source Project624a7872012-12-12 16:00:35 -080041/* Define the Protocol Data Unit (PDU) types.
Jakub Pawlowski2238a882017-07-10 09:56:09 -070042 */
Myles Watsonf8a21202016-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 Project624a7872012-12-12 16:00:35 -080050
51/* Max UUIDs and attributes we support per sequence */
Myles Watsonf8a21202016-11-28 16:44:40 -080052#define MAX_UUIDS_PER_SEQ 16
53#define MAX_ATTR_PER_SEQ 16
The Android Open Source Project624a7872012-12-12 16:00:35 -080054
55/* Max length we support for any attribute */
The Android Open Source Project624a7872012-12-12 16:00:35 -080056#ifdef SDP_MAX_ATTR_LEN
57#define MAX_ATTR_LEN SDP_MAX_ATTR_LEN
58#else
Myles Watsonf8a21202016-11-28 16:44:40 -080059#define MAX_ATTR_LEN 256
The Android Open Source Project624a7872012-12-12 16:00:35 -080060#endif
The Android Open Source Project624a7872012-12-12 16:00:35 -080061
62/* Internal UUID sequence representation */
Myles Watsonf8a21202016-11-28 16:44:40 -080063typedef struct {
64 uint16_t len;
Jakub Pawlowski2238a882017-07-10 09:56:09 -070065 uint8_t value[bluetooth::Uuid::kNumBytes128];
The Android Open Source Project624a7872012-12-12 16:00:35 -080066} tUID_ENT;
67
Myles Watsonf8a21202016-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 Project624a7872012-12-12 16:00:35 -080071} tSDP_UUID_SEQ;
72
The Android Open Source Project624a7872012-12-12 16:00:35 -080073/* Internal attribute sequence definitions */
Myles Watsonf8a21202016-11-28 16:44:40 -080074typedef struct {
75 uint16_t start;
76 uint16_t end;
The Android Open Source Project624a7872012-12-12 16:00:35 -080077} tATT_ENT;
78
Myles Watsonf8a21202016-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 Project624a7872012-12-12 16:00:35 -080082} tSDP_ATTR_SEQ;
83
The Android Open Source Project624a7872012-12-12 16:00:35 -080084/* Define the attribute element of the SDP database record */
Myles Watsonf8a21202016-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 Project624a7872012-12-12 16:00:35 -080090} tSDP_ATTRIBUTE;
91
92/* An SDP record consists of a handle, and 1 or more attributes */
Myles Watsonf8a21202016-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 Project624a7872012-12-12 16:00:35 -080099} tSDP_RECORD;
100
The Android Open Source Project624a7872012-12-12 16:00:35 -0800101/* Define the SDP database */
Myles Watsonf8a21202016-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 Project624a7872012-12-12 16:00:35 -0800107} tSDP_DB;
108
The Android Open Source Project624a7872012-12-12 16:00:35 -0800109/* Continuation information for the SDP server response */
Myles Watsonf8a21202016-11-28 16:44:40 -0800110typedef struct {
111 uint16_t next_attr_index; /* attr index for next continuation response */
112 uint16_t next_attr_start_id; /* attr id to start with for the attr index in
113 next cont. response */
114 tSDP_RECORD* prev_sdp_rec; /* last sdp record that was completely sent in the
115 response */
116 bool last_attr_seq_desc_sent; /* whether attr seq length has been sent
117 previously */
118 uint16_t attr_offset; /* offset within the attr to keep trak of partial
119 attributes in the responses */
The Android Open Source Project624a7872012-12-12 16:00:35 -0800120} tSDP_CONT_INFO;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800121
122/* Define the SDP Connection Control Block */
Myles Watsonf8a21202016-11-28 16:44:40 -0800123typedef struct {
124#define SDP_STATE_IDLE 0
125#define SDP_STATE_CONN_SETUP 1
126#define SDP_STATE_CFG_SETUP 2
127#define SDP_STATE_CONNECTED 3
128 uint8_t con_state;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800129
Myles Watsonf8a21202016-11-28 16:44:40 -0800130#define SDP_FLAGS_IS_ORIG 0x01
131#define SDP_FLAGS_HIS_CFG_DONE 0x02
132#define SDP_FLAGS_MY_CFG_DONE 0x04
133 uint8_t con_flags;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800134
Jakub Pawlowskid8e815c2017-06-24 17:30:18 -0700135 RawAddress device_address;
Myles Watsonf8a21202016-11-28 16:44:40 -0800136 alarm_t* sdp_conn_timer;
137 uint16_t rem_mtu_size;
138 uint16_t connection_id;
139 uint16_t list_len; /* length of the response in the GKI buffer */
140 uint8_t* rsp_list; /* pointer to GKI buffer holding response */
The Android Open Source Project624a7872012-12-12 16:00:35 -0800141
Myles Watsonf8a21202016-11-28 16:44:40 -0800142 tSDP_DISCOVERY_DB* p_db; /* Database to save info into */
143 tSDP_DISC_CMPL_CB* p_cb; /* Callback for discovery done */
144 tSDP_DISC_CMPL_CB2*
145 p_cb2; /* Callback for discovery done piggy back with the user data */
146 void* user_data; /* piggy back user data */
147 uint32_t
148 handles[SDP_MAX_DISC_SERVER_RECS]; /* Discovered server record handles */
149 uint16_t num_handles; /* Number of server handles */
150 uint16_t cur_handle; /* Current handle being processed */
151 uint16_t transaction_id;
152 uint16_t disconnect_reason; /* Disconnect reason */
The Android Open Source Project624a7872012-12-12 16:00:35 -0800153
Myles Watsonf8a21202016-11-28 16:44:40 -0800154#define SDP_DISC_WAIT_CONN 0
155#define SDP_DISC_WAIT_HANDLES 1
156#define SDP_DISC_WAIT_ATTR 2
157#define SDP_DISC_WAIT_SEARCH_ATTR 3
158#define SDP_DISC_WAIT_CANCEL 5
The Android Open Source Project624a7872012-12-12 16:00:35 -0800159
Myles Watsonf8a21202016-11-28 16:44:40 -0800160 uint8_t disc_state;
161 uint8_t is_attr_search;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800162
Myles Watsonf8a21202016-11-28 16:44:40 -0800163 uint16_t cont_offset; /* Continuation state data in the server response */
164 tSDP_CONT_INFO cont_info; /* structure to hold continuation information for
165 the server response */
The Android Open Source Project624a7872012-12-12 16:00:35 -0800166
167} tCONN_CB;
168
The Android Open Source Project624a7872012-12-12 16:00:35 -0800169/* The main SDP control block */
Myles Watsonf8a21202016-11-28 16:44:40 -0800170typedef struct {
171 tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */
172 tCONN_CB ccb[SDP_MAX_CONNECTIONS];
Myles Watsonf8a21202016-11-28 16:44:40 -0800173 tSDP_DB server_db;
Myles Watsonf8a21202016-11-28 16:44:40 -0800174 tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */
175 uint16_t max_attr_list_size; /* Max attribute list size to use */
176 uint16_t max_recs_per_search; /* Max records we want per seaarch */
177 uint8_t trace_level;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800178} tSDP_CB;
179
The Android Open Source Project624a7872012-12-12 16:00:35 -0800180/* Global SDP data */
Myles Watsonf8a21202016-11-28 16:44:40 -0800181extern tSDP_CB sdp_cb;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800182
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700183/* Functions provided by sdp_main.cc */
Myles Watsonf8a21202016-11-28 16:44:40 -0800184extern void sdp_init(void);
Pavlin Radoslavov50baa2c2018-01-11 17:28:16 -0800185extern void sdp_free(void);
Chris Mantone36a7902021-03-15 17:14:10 -0700186extern void sdp_disconnect(tCONN_CB* p_ccb, tSDP_REASON reason);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800187
Myles Watsonf8a21202016-11-28 16:44:40 -0800188extern void sdp_conn_timer_timeout(void* data);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800189
Jakub Pawlowskid8e815c2017-06-24 17:30:18 -0700190extern tCONN_CB* sdp_conn_originate(const RawAddress& p_bd_addr);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800191
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700192/* Functions provided by sdp_utils.cc
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700193 */
Jack He3c162a82019-02-01 18:30:21 -0800194extern void sdpu_log_attribute_metrics(const RawAddress& bda,
195 tSDP_DISCOVERY_DB* p_db);
Myles Watsonf8a21202016-11-28 16:44:40 -0800196extern tCONN_CB* sdpu_find_ccb_by_cid(uint16_t cid);
197extern tCONN_CB* sdpu_find_ccb_by_db(tSDP_DISCOVERY_DB* p_db);
198extern tCONN_CB* sdpu_allocate_ccb(void);
199extern void sdpu_release_ccb(tCONN_CB* p_ccb);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800200
Myles Watsonf8a21202016-11-28 16:44:40 -0800201extern uint8_t* sdpu_build_attrib_seq(uint8_t* p_out, uint16_t* p_attr,
202 uint16_t num_attrs);
203extern uint8_t* sdpu_build_attrib_entry(uint8_t* p_out, tSDP_ATTRIBUTE* p_attr);
204extern void sdpu_build_n_send_error(tCONN_CB* p_ccb, uint16_t trans_num,
205 uint16_t error_code, char* p_error_text);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800206
Myles Watsonf8a21202016-11-28 16:44:40 -0800207extern uint8_t* sdpu_extract_attr_seq(uint8_t* p, uint16_t param_len,
208 tSDP_ATTR_SEQ* p_seq);
209extern uint8_t* sdpu_extract_uid_seq(uint8_t* p, uint16_t param_len,
210 tSDP_UUID_SEQ* p_seq);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800211
Ted Wang2703ef62019-04-29 10:11:04 +0800212extern uint8_t* sdpu_get_len_from_type(uint8_t* p, uint8_t* p_end, uint8_t type,
Myles Watsonf8a21202016-11-28 16:44:40 -0800213 uint32_t* p_len);
214extern bool sdpu_is_base_uuid(uint8_t* p_uuid);
215extern bool sdpu_compare_uuid_arrays(uint8_t* p_uuid1, uint32_t len1,
216 uint8_t* p_uuid2, uint16_t len2);
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700217extern bool sdpu_compare_uuid_with_attr(const bluetooth::Uuid& uuid,
Myles Watsonf8a21202016-11-28 16:44:40 -0800218 tSDP_DISC_ATTR* p_attr);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800219
Myles Watsonf8a21202016-11-28 16:44:40 -0800220extern void sdpu_sort_attr_list(uint16_t num_attr, tSDP_DISCOVERY_DB* p_db);
221extern uint16_t sdpu_get_list_len(tSDP_UUID_SEQ* uid_seq,
222 tSDP_ATTR_SEQ* attr_seq);
223extern uint16_t sdpu_get_attrib_seq_len(tSDP_RECORD* p_rec,
224 tSDP_ATTR_SEQ* attr_seq);
225extern uint16_t sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE* p_attr);
226extern uint8_t* sdpu_build_partial_attrib_entry(uint8_t* p_out,
227 tSDP_ATTRIBUTE* p_attr,
228 uint16_t len, uint16_t* offset);
Ted Wangf212f4f2020-05-18 18:02:34 +0800229extern uint16_t sdpu_is_avrcp_profile_description_list(tSDP_ATTRIBUTE* p_attr);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800230
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700231/* Functions provided by sdp_db.cc
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700232 */
Myles Watsonf8a21202016-11-28 16:44:40 -0800233extern tSDP_RECORD* sdp_db_service_search(tSDP_RECORD* p_rec,
234 tSDP_UUID_SEQ* p_seq);
235extern tSDP_RECORD* sdp_db_find_record(uint32_t handle);
236extern tSDP_ATTRIBUTE* sdp_db_find_attr_in_rec(tSDP_RECORD* p_rec,
237 uint16_t start_attr,
238 uint16_t end_attr);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800239
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700240/* Functions provided by sdp_server.cc
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700241 */
Myles Watsonf8a21202016-11-28 16:44:40 -0800242extern void sdp_server_handle_client_req(tCONN_CB* p_ccb, BT_HDR* p_msg);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800243
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700244/* Functions provided by sdp_discovery.cc
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700245 */
Myles Watsonf8a21202016-11-28 16:44:40 -0800246extern void sdp_disc_connected(tCONN_CB* p_ccb);
247extern void sdp_disc_server_rsp(tCONN_CB* p_ccb, BT_HDR* p_msg);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800248
The Android Open Source Project624a7872012-12-12 16:00:35 -0800249#endif