blob: 74816dd711379493a7132758d5c2195d423af87b [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
Chris Manton5f080b92021-08-21 16:27:49 -070028#include <cstdint>
29
The Android Open Source Project624a7872012-12-12 16:00:35 -080030#include "bt_target.h"
Pavlin Radoslavov30698fa2015-12-04 17:36:34 -080031#include "osi/include/alarm.h"
Chris Manton05074022021-09-16 22:15:07 -070032#include "stack/include/bt_hdr.h"
Chris Manton5f080b92021-08-21 16:27:49 -070033#include "stack/include/l2c_api.h"
34#include "types/bluetooth/uuid.h"
35#include "types/raw_address.h"
The Android Open Source Project624a7872012-12-12 16:00:35 -080036
The Android Open Source Project624a7872012-12-12 16:00:35 -080037/* Continuation length - we use a 2-byte offset */
Myles Watsonf8a21202016-11-28 16:44:40 -080038#define SDP_CONTINUATION_LEN 2
39#define SDP_MAX_CONTINUATION_LEN 16 /* As per the spec */
The Android Open Source Project624a7872012-12-12 16:00:35 -080040
41/* Timeout definitions. */
Myles Watsonf8a21202016-11-28 16:44:40 -080042#define SDP_INACT_TIMEOUT_MS (30 * 1000) /* Inactivity timeout (in ms) */
The Android Open Source Project624a7872012-12-12 16:00:35 -080043
The Android Open Source Project624a7872012-12-12 16:00:35 -080044/* Define the Protocol Data Unit (PDU) types.
Jakub Pawlowski2238a882017-07-10 09:56:09 -070045 */
Myles Watsonf8a21202016-11-28 16:44:40 -080046#define SDP_PDU_ERROR_RESPONSE 0x01
47#define SDP_PDU_SERVICE_SEARCH_REQ 0x02
48#define SDP_PDU_SERVICE_SEARCH_RSP 0x03
49#define SDP_PDU_SERVICE_ATTR_REQ 0x04
50#define SDP_PDU_SERVICE_ATTR_RSP 0x05
51#define SDP_PDU_SERVICE_SEARCH_ATTR_REQ 0x06
52#define SDP_PDU_SERVICE_SEARCH_ATTR_RSP 0x07
The Android Open Source Project624a7872012-12-12 16:00:35 -080053
54/* Max UUIDs and attributes we support per sequence */
Myles Watsonf8a21202016-11-28 16:44:40 -080055#define MAX_UUIDS_PER_SEQ 16
56#define MAX_ATTR_PER_SEQ 16
The Android Open Source Project624a7872012-12-12 16:00:35 -080057
58/* Max length we support for any attribute */
The Android Open Source Project624a7872012-12-12 16:00:35 -080059#ifdef SDP_MAX_ATTR_LEN
60#define MAX_ATTR_LEN SDP_MAX_ATTR_LEN
61#else
Myles Watsonf8a21202016-11-28 16:44:40 -080062#define MAX_ATTR_LEN 256
The Android Open Source Project624a7872012-12-12 16:00:35 -080063#endif
The Android Open Source Project624a7872012-12-12 16:00:35 -080064
65/* Internal UUID sequence representation */
Myles Watsonf8a21202016-11-28 16:44:40 -080066typedef struct {
67 uint16_t len;
Jakub Pawlowski2238a882017-07-10 09:56:09 -070068 uint8_t value[bluetooth::Uuid::kNumBytes128];
The Android Open Source Project624a7872012-12-12 16:00:35 -080069} tUID_ENT;
70
Myles Watsonf8a21202016-11-28 16:44:40 -080071typedef struct {
72 uint16_t num_uids;
73 tUID_ENT uuid_entry[MAX_UUIDS_PER_SEQ];
The Android Open Source Project624a7872012-12-12 16:00:35 -080074} tSDP_UUID_SEQ;
75
The Android Open Source Project624a7872012-12-12 16:00:35 -080076/* Internal attribute sequence definitions */
Myles Watsonf8a21202016-11-28 16:44:40 -080077typedef struct {
78 uint16_t start;
79 uint16_t end;
The Android Open Source Project624a7872012-12-12 16:00:35 -080080} tATT_ENT;
81
Myles Watsonf8a21202016-11-28 16:44:40 -080082typedef struct {
83 uint16_t num_attr;
84 tATT_ENT attr_entry[MAX_ATTR_PER_SEQ];
The Android Open Source Project624a7872012-12-12 16:00:35 -080085} tSDP_ATTR_SEQ;
86
The Android Open Source Project624a7872012-12-12 16:00:35 -080087/* Define the attribute element of the SDP database record */
Myles Watsonf8a21202016-11-28 16:44:40 -080088typedef struct {
89 uint32_t len; /* Number of bytes in the entry */
90 uint8_t* value_ptr; /* Points to attr_pad */
91 uint16_t id;
92 uint8_t type;
The Android Open Source Project624a7872012-12-12 16:00:35 -080093} tSDP_ATTRIBUTE;
94
95/* An SDP record consists of a handle, and 1 or more attributes */
Myles Watsonf8a21202016-11-28 16:44:40 -080096typedef struct {
97 uint32_t record_handle;
98 uint32_t free_pad_ptr;
99 uint16_t num_attributes;
100 tSDP_ATTRIBUTE attribute[SDP_MAX_REC_ATTR];
101 uint8_t attr_pad[SDP_MAX_PAD_LEN];
The Android Open Source Project624a7872012-12-12 16:00:35 -0800102} tSDP_RECORD;
103
The Android Open Source Project624a7872012-12-12 16:00:35 -0800104/* Define the SDP database */
Myles Watsonf8a21202016-11-28 16:44:40 -0800105typedef struct {
106 uint32_t
107 di_primary_handle; /* Device ID Primary record or NULL if nonexistent */
108 uint16_t num_records;
109 tSDP_RECORD record[SDP_MAX_RECORDS];
The Android Open Source Project624a7872012-12-12 16:00:35 -0800110} tSDP_DB;
111
The Android Open Source Project624a7872012-12-12 16:00:35 -0800112/* Continuation information for the SDP server response */
Myles Watsonf8a21202016-11-28 16:44:40 -0800113typedef struct {
114 uint16_t next_attr_index; /* attr index for next continuation response */
115 uint16_t next_attr_start_id; /* attr id to start with for the attr index in
116 next cont. response */
Chris Mantonb734c122021-09-17 18:34:58 -0700117 const tSDP_RECORD* prev_sdp_rec; /* last sdp record that was completely sent
118 in the response */
Myles Watsonf8a21202016-11-28 16:44:40 -0800119 bool last_attr_seq_desc_sent; /* whether attr seq length has been sent
120 previously */
121 uint16_t attr_offset; /* offset within the attr to keep trak of partial
122 attributes in the responses */
The Android Open Source Project624a7872012-12-12 16:00:35 -0800123} tSDP_CONT_INFO;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800124
125/* Define the SDP Connection Control Block */
Myles Watsonf8a21202016-11-28 16:44:40 -0800126typedef struct {
127#define SDP_STATE_IDLE 0
128#define SDP_STATE_CONN_SETUP 1
129#define SDP_STATE_CFG_SETUP 2
130#define SDP_STATE_CONNECTED 3
131 uint8_t con_state;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800132
Myles Watsonf8a21202016-11-28 16:44:40 -0800133#define SDP_FLAGS_IS_ORIG 0x01
134#define SDP_FLAGS_HIS_CFG_DONE 0x02
135#define SDP_FLAGS_MY_CFG_DONE 0x04
136 uint8_t con_flags;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800137
Jakub Pawlowskid8e815c2017-06-24 17:30:18 -0700138 RawAddress device_address;
Myles Watsonf8a21202016-11-28 16:44:40 -0800139 alarm_t* sdp_conn_timer;
140 uint16_t rem_mtu_size;
141 uint16_t connection_id;
142 uint16_t list_len; /* length of the response in the GKI buffer */
143 uint8_t* rsp_list; /* pointer to GKI buffer holding response */
The Android Open Source Project624a7872012-12-12 16:00:35 -0800144
Myles Watsonf8a21202016-11-28 16:44:40 -0800145 tSDP_DISCOVERY_DB* p_db; /* Database to save info into */
146 tSDP_DISC_CMPL_CB* p_cb; /* Callback for discovery done */
147 tSDP_DISC_CMPL_CB2*
148 p_cb2; /* Callback for discovery done piggy back with the user data */
Chris Mantonca598e62021-09-17 17:59:31 -0700149 const void* user_data; /* piggy back user data */
Myles Watsonf8a21202016-11-28 16:44:40 -0800150 uint32_t
151 handles[SDP_MAX_DISC_SERVER_RECS]; /* Discovered server record handles */
152 uint16_t num_handles; /* Number of server handles */
153 uint16_t cur_handle; /* Current handle being processed */
154 uint16_t transaction_id;
155 uint16_t disconnect_reason; /* Disconnect reason */
The Android Open Source Project624a7872012-12-12 16:00:35 -0800156
Myles Watsonf8a21202016-11-28 16:44:40 -0800157#define SDP_DISC_WAIT_CONN 0
158#define SDP_DISC_WAIT_HANDLES 1
159#define SDP_DISC_WAIT_ATTR 2
160#define SDP_DISC_WAIT_SEARCH_ATTR 3
161#define SDP_DISC_WAIT_CANCEL 5
The Android Open Source Project624a7872012-12-12 16:00:35 -0800162
Myles Watsonf8a21202016-11-28 16:44:40 -0800163 uint8_t disc_state;
164 uint8_t is_attr_search;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800165
Myles Watsonf8a21202016-11-28 16:44:40 -0800166 uint16_t cont_offset; /* Continuation state data in the server response */
167 tSDP_CONT_INFO cont_info; /* structure to hold continuation information for
168 the server response */
The Android Open Source Project624a7872012-12-12 16:00:35 -0800169
170} tCONN_CB;
171
The Android Open Source Project624a7872012-12-12 16:00:35 -0800172/* The main SDP control block */
Myles Watsonf8a21202016-11-28 16:44:40 -0800173typedef struct {
174 tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */
175 tCONN_CB ccb[SDP_MAX_CONNECTIONS];
Myles Watsonf8a21202016-11-28 16:44:40 -0800176 tSDP_DB server_db;
Myles Watsonf8a21202016-11-28 16:44:40 -0800177 tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */
178 uint16_t max_attr_list_size; /* Max attribute list size to use */
179 uint16_t max_recs_per_search; /* Max records we want per seaarch */
180 uint8_t trace_level;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800181} tSDP_CB;
182
The Android Open Source Project624a7872012-12-12 16:00:35 -0800183/* Global SDP data */
Myles Watsonf8a21202016-11-28 16:44:40 -0800184extern tSDP_CB sdp_cb;
The Android Open Source Project624a7872012-12-12 16:00:35 -0800185
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700186/* Functions provided by sdp_main.cc */
Myles Watsonf8a21202016-11-28 16:44:40 -0800187extern void sdp_init(void);
Pavlin Radoslavov50baa2c2018-01-11 17:28:16 -0800188extern void sdp_free(void);
Chris Mantone36a7902021-03-15 17:14:10 -0700189extern void sdp_disconnect(tCONN_CB* p_ccb, tSDP_REASON reason);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800190
Myles Watsonf8a21202016-11-28 16:44:40 -0800191extern void sdp_conn_timer_timeout(void* data);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800192
Jakub Pawlowskid8e815c2017-06-24 17:30:18 -0700193extern tCONN_CB* sdp_conn_originate(const RawAddress& p_bd_addr);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800194
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700195/* Functions provided by sdp_utils.cc
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700196 */
Jack He3c162a82019-02-01 18:30:21 -0800197extern void sdpu_log_attribute_metrics(const RawAddress& bda,
198 tSDP_DISCOVERY_DB* p_db);
Myles Watsonf8a21202016-11-28 16:44:40 -0800199extern tCONN_CB* sdpu_find_ccb_by_cid(uint16_t cid);
Chris Manton84878902021-09-17 15:10:19 -0700200extern tCONN_CB* sdpu_find_ccb_by_db(const tSDP_DISCOVERY_DB* p_db);
Myles Watsonf8a21202016-11-28 16:44:40 -0800201extern tCONN_CB* sdpu_allocate_ccb(void);
202extern void sdpu_release_ccb(tCONN_CB* p_ccb);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800203
Myles Watsonf8a21202016-11-28 16:44:40 -0800204extern uint8_t* sdpu_build_attrib_seq(uint8_t* p_out, uint16_t* p_attr,
205 uint16_t num_attrs);
Chris Mantonb734c122021-09-17 18:34:58 -0700206extern uint8_t* sdpu_build_attrib_entry(uint8_t* p_out,
207 const tSDP_ATTRIBUTE* p_attr);
Myles Watsonf8a21202016-11-28 16:44:40 -0800208extern void sdpu_build_n_send_error(tCONN_CB* p_ccb, uint16_t trans_num,
209 uint16_t error_code, char* p_error_text);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800210
Myles Watsonf8a21202016-11-28 16:44:40 -0800211extern uint8_t* sdpu_extract_attr_seq(uint8_t* p, uint16_t param_len,
212 tSDP_ATTR_SEQ* p_seq);
213extern uint8_t* sdpu_extract_uid_seq(uint8_t* p, uint16_t param_len,
214 tSDP_UUID_SEQ* p_seq);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800215
Ted Wang2703ef62019-04-29 10:11:04 +0800216extern uint8_t* sdpu_get_len_from_type(uint8_t* p, uint8_t* p_end, uint8_t type,
Myles Watsonf8a21202016-11-28 16:44:40 -0800217 uint32_t* p_len);
218extern bool sdpu_is_base_uuid(uint8_t* p_uuid);
Chris Manton666e6e62021-09-17 19:56:01 -0700219extern bool sdpu_compare_uuid_arrays(const uint8_t* p_uuid1, uint32_t len1,
220 const uint8_t* p_uuid2, uint16_t len2);
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700221extern bool sdpu_compare_uuid_with_attr(const bluetooth::Uuid& uuid,
Myles Watsonf8a21202016-11-28 16:44:40 -0800222 tSDP_DISC_ATTR* p_attr);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800223
Myles Watsonf8a21202016-11-28 16:44:40 -0800224extern void sdpu_sort_attr_list(uint16_t num_attr, tSDP_DISCOVERY_DB* p_db);
225extern uint16_t sdpu_get_list_len(tSDP_UUID_SEQ* uid_seq,
226 tSDP_ATTR_SEQ* attr_seq);
Chris Mantonb734c122021-09-17 18:34:58 -0700227extern uint16_t sdpu_get_attrib_seq_len(const tSDP_RECORD* p_rec,
Chris Manton666e6e62021-09-17 19:56:01 -0700228 const tSDP_ATTR_SEQ* attr_seq);
Chris Mantonb734c122021-09-17 18:34:58 -0700229extern uint16_t sdpu_get_attrib_entry_len(const tSDP_ATTRIBUTE* p_attr);
Myles Watsonf8a21202016-11-28 16:44:40 -0800230extern uint8_t* sdpu_build_partial_attrib_entry(uint8_t* p_out,
Chris Mantonb734c122021-09-17 18:34:58 -0700231 const tSDP_ATTRIBUTE* p_attr,
Myles Watsonf8a21202016-11-28 16:44:40 -0800232 uint16_t len, uint16_t* offset);
Chris Mantonb734c122021-09-17 18:34:58 -0700233extern uint16_t sdpu_is_avrcp_profile_description_list(
234 const tSDP_ATTRIBUTE* p_attr);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800235
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700236/* Functions provided by sdp_db.cc
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700237 */
Chris Mantonb734c122021-09-17 18:34:58 -0700238extern const tSDP_RECORD* sdp_db_service_search(const tSDP_RECORD* p_rec,
Chris Manton666e6e62021-09-17 19:56:01 -0700239 const tSDP_UUID_SEQ* p_seq);
Myles Watsonf8a21202016-11-28 16:44:40 -0800240extern tSDP_RECORD* sdp_db_find_record(uint32_t handle);
Chris Mantonb734c122021-09-17 18:34:58 -0700241extern const tSDP_ATTRIBUTE* sdp_db_find_attr_in_rec(const tSDP_RECORD* p_rec,
242 uint16_t start_attr,
243 uint16_t end_attr);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800244
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700245/* Functions provided by sdp_server.cc
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700246 */
Myles Watsonf8a21202016-11-28 16:44:40 -0800247extern void sdp_server_handle_client_req(tCONN_CB* p_ccb, BT_HDR* p_msg);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800248
Pavlin Radoslavov0c00b7d2016-10-14 19:34:48 -0700249/* Functions provided by sdp_discovery.cc
Jakub Pawlowski2238a882017-07-10 09:56:09 -0700250 */
Myles Watsonf8a21202016-11-28 16:44:40 -0800251extern void sdp_disc_connected(tCONN_CB* p_ccb);
252extern void sdp_disc_server_rsp(tCONN_CB* p_ccb, BT_HDR* p_msg);
The Android Open Source Project624a7872012-12-12 16:00:35 -0800253
The Android Open Source Project624a7872012-12-12 16:00:35 -0800254#endif