blob: f4a3493e0c254be1ae46c16da9dd00c470fdef62 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 1999-2012 Broadcom Corporation
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 file contains internally used SDP definitions
22 *
23 ******************************************************************************/
24
25#ifndef SDP_INT_H
26#define SDP_INT_H
27
28#include "bt_target.h"
Pavlin Radoslavov78bcff72015-12-04 17:36:34 -080029#include "osi/include/alarm.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080030#include "sdp_api.h"
31#include "l2c_api.h"
32
33
34/* Continuation length - we use a 2-byte offset */
35#define SDP_CONTINUATION_LEN 2
36#define SDP_MAX_CONTINUATION_LEN 16 /* As per the spec */
37
38/* Timeout definitions. */
Pavlin Radoslavov78bcff72015-12-04 17:36:34 -080039#define SDP_INACT_TIMEOUT_MS (30 * 1000) /* Inactivity timeout (in ms) */
The Android Open Source Project5738f832012-12-12 16:00:35 -080040
41
42/* Define the Out-Flow default values. */
43#define SDP_OFLOW_QOS_FLAG 0
44#define SDP_OFLOW_SERV_TYPE 0
45#define SDP_OFLOW_TOKEN_RATE 0
46#define SDP_OFLOW_TOKEN_BUCKET_SIZE 0
47#define SDP_OFLOW_PEAK_BANDWIDTH 0
48#define SDP_OFLOW_LATENCY 0
49#define SDP_OFLOW_DELAY_VARIATION 0
50
51/* Define the In-Flow default values. */
52#define SDP_IFLOW_QOS_FLAG 0
53#define SDP_IFLOW_SERV_TYPE 0
54#define SDP_IFLOW_TOKEN_RATE 0
55#define SDP_IFLOW_TOKEN_BUCKET_SIZE 0
56#define SDP_IFLOW_PEAK_BANDWIDTH 0
57#define SDP_IFLOW_LATENCY 0
58#define SDP_IFLOW_DELAY_VARIATION 0
59
60#define SDP_LINK_TO 0
61
62/* Define the type of device notification. */
63/* (Inquiry Scan and Page Scan) */
64#define SDP_DEVICE_NOTI_LEN sizeof (BT_HDR) + \
65 HCIC_PREAMBLE_SIZE + \
66 HCIC_PARAM_SIZE_WRITE_PARAM1
67
68#define SDP_DEVICE_NOTI_FLAG 0x03
69
70/* Define the Protocol Data Unit (PDU) types.
71*/
72#define SDP_PDU_ERROR_RESPONSE 0x01
73#define SDP_PDU_SERVICE_SEARCH_REQ 0x02
74#define SDP_PDU_SERVICE_SEARCH_RSP 0x03
75#define SDP_PDU_SERVICE_ATTR_REQ 0x04
76#define SDP_PDU_SERVICE_ATTR_RSP 0x05
77#define SDP_PDU_SERVICE_SEARCH_ATTR_REQ 0x06
78#define SDP_PDU_SERVICE_SEARCH_ATTR_RSP 0x07
79
80/* Max UUIDs and attributes we support per sequence */
81#define MAX_UUIDS_PER_SEQ 16
82#define MAX_ATTR_PER_SEQ 16
83
84/* Max length we support for any attribute */
The Android Open Source Project5738f832012-12-12 16:00:35 -080085#ifdef SDP_MAX_ATTR_LEN
86#define MAX_ATTR_LEN SDP_MAX_ATTR_LEN
87#else
88#define MAX_ATTR_LEN 256
89#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -080090
91/* Internal UUID sequence representation */
92typedef struct
93{
94 UINT16 len;
95 UINT8 value[MAX_UUID_SIZE];
96} tUID_ENT;
97
98typedef struct
99{
100 UINT16 num_uids;
101 tUID_ENT uuid_entry[MAX_UUIDS_PER_SEQ];
102} tSDP_UUID_SEQ;
103
104
105/* Internal attribute sequence definitions */
106typedef struct
107{
108 UINT16 start;
109 UINT16 end;
110} tATT_ENT;
111
112typedef struct
113{
114 UINT16 num_attr;
115 tATT_ENT attr_entry[MAX_ATTR_PER_SEQ];
116} tSDP_ATTR_SEQ;
117
118
119/* Define the attribute element of the SDP database record */
120typedef struct
121{
122 UINT32 len; /* Number of bytes in the entry */
123 UINT8 *value_ptr; /* Points to attr_pad */
124 UINT16 id;
125 UINT8 type;
126} tSDP_ATTRIBUTE;
127
128/* An SDP record consists of a handle, and 1 or more attributes */
129typedef struct
130{
131 UINT32 record_handle;
132 UINT32 free_pad_ptr;
133 UINT16 num_attributes;
134 tSDP_ATTRIBUTE attribute[SDP_MAX_REC_ATTR];
135 UINT8 attr_pad[SDP_MAX_PAD_LEN];
136} tSDP_RECORD;
137
138
139/* Define the SDP database */
140typedef struct
141{
142 UINT32 di_primary_handle; /* Device ID Primary record or NULL if nonexistent */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800143 UINT16 num_records;
144 tSDP_RECORD record[SDP_MAX_RECORDS];
145} tSDP_DB;
146
147enum
148{
149 SDP_IS_SEARCH,
150 SDP_IS_ATTR_SEARCH,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800151};
152
153#if SDP_SERVER_ENABLED == TRUE
154/* Continuation information for the SDP server response */
155typedef struct
156{
157 UINT16 next_attr_index; /* attr index for next continuation response */
158 UINT16 next_attr_start_id; /* attr id to start with for the attr index in next cont. response */
159 tSDP_RECORD *prev_sdp_rec; /* last sdp record that was completely sent in the response */
Manu Viswanadhan74ac5a02016-09-26 16:47:51 +0530160 tSDP_RECORD *curr_sdp_rec; /* sdp record that is currently being sent in the response */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800161 BOOLEAN last_attr_seq_desc_sent; /* whether attr seq length has been sent previously */
162 UINT16 attr_offset; /* offset within the attr to keep trak of partial attributes in the responses */
163} tSDP_CONT_INFO;
164#endif /* SDP_SERVER_ENABLED == TRUE */
165
166/* Define the SDP Connection Control Block */
167typedef struct
168{
169#define SDP_STATE_IDLE 0
170#define SDP_STATE_CONN_SETUP 1
171#define SDP_STATE_CFG_SETUP 2
172#define SDP_STATE_CONNECTED 3
173 UINT8 con_state;
174
175#define SDP_FLAGS_IS_ORIG 0x01
176#define SDP_FLAGS_HIS_CFG_DONE 0x02
177#define SDP_FLAGS_MY_CFG_DONE 0x04
178 UINT8 con_flags;
179
180 BD_ADDR device_address;
Pavlin Radoslavov78bcff72015-12-04 17:36:34 -0800181 alarm_t *sdp_conn_timer;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800182 UINT16 rem_mtu_size;
183 UINT16 connection_id;
184 UINT16 list_len; /* length of the response in the GKI buffer */
185 UINT8 *rsp_list; /* pointer to GKI buffer holding response */
186
187#if SDP_CLIENT_ENABLED == TRUE
188 tSDP_DISCOVERY_DB *p_db; /* Database to save info into */
189 tSDP_DISC_CMPL_CB *p_cb; /* Callback for discovery done */
190 tSDP_DISC_CMPL_CB2 *p_cb2; /* Callback for discovery done piggy back with the user data */
191 void *user_data; /* piggy back user data */
192 UINT32 handles[SDP_MAX_DISC_SERVER_RECS]; /* Discovered server record handles */
193 UINT16 num_handles; /* Number of server handles */
194 UINT16 cur_handle; /* Current handle being processed */
195 UINT16 transaction_id;
196 UINT16 disconnect_reason; /* Disconnect reason */
197#if (defined(SDP_BROWSE_PLUS) && SDP_BROWSE_PLUS == TRUE)
198 UINT16 cur_uuid_idx;
199#endif
200
201#define SDP_DISC_WAIT_CONN 0
202#define SDP_DISC_WAIT_HANDLES 1
203#define SDP_DISC_WAIT_ATTR 2
204#define SDP_DISC_WAIT_SEARCH_ATTR 3
The Android Open Source Project5738f832012-12-12 16:00:35 -0800205#define SDP_DISC_WAIT_CANCEL 5
206
207 UINT8 disc_state;
208 UINT8 is_attr_search;
209#endif /* SDP_CLIENT_ENABLED == TRUE */
210
211#if SDP_SERVER_ENABLED == TRUE
212 UINT16 cont_offset; /* Continuation state data in the server response */
213 tSDP_CONT_INFO cont_info; /* structure to hold continuation information for the server response */
214#endif /* SDP_SERVER_ENABLED == TRUE */
215
216} tCONN_CB;
217
218
219/* The main SDP control block */
220typedef struct
221{
222 tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */
223 tCONN_CB ccb[SDP_MAX_CONNECTIONS];
224#if SDP_SERVER_ENABLED == TRUE
225 tSDP_DB server_db;
226#endif
227 tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */
228 UINT16 max_attr_list_size; /* Max attribute list size to use */
229 UINT16 max_recs_per_search; /* Max records we want per seaarch */
230 UINT8 trace_level;
231} tSDP_CB;
232
233#ifdef __cplusplus
234extern "C" {
235#endif
236/* Global SDP data */
237#if SDP_DYNAMIC_MEMORY == FALSE
June R. Tate-Gans24933b52014-09-24 15:25:02 -0700238extern tSDP_CB sdp_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800239#else
June R. Tate-Gans24933b52014-09-24 15:25:02 -0700240extern tSDP_CB *sdp_cb_ptr;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800241#define sdp_cb (*sdp_cb_ptr)
242#endif
243
244#ifdef __cplusplus
245}
246#endif
247
248/* Functions provided by sdp_main.c */
June R. Tate-Gans24933b52014-09-24 15:25:02 -0700249extern void sdp_init (void);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800250extern void sdp_disconnect (tCONN_CB*p_ccb, UINT16 reason);
251
252#if (defined(SDP_DEBUG) && SDP_DEBUG == TRUE)
June R. Tate-Gans24933b52014-09-24 15:25:02 -0700253extern UINT16 sdp_set_max_attr_list_size (UINT16 max_size);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800254#endif
255
256/* Functions provided by sdp_conn.c
257*/
258extern void sdp_conn_rcv_l2e_conn_ind (BT_HDR *p_msg);
259extern void sdp_conn_rcv_l2e_conn_cfm (BT_HDR *p_msg);
260extern void sdp_conn_rcv_l2e_disc (BT_HDR *p_msg);
261extern void sdp_conn_rcv_l2e_config_ind (BT_HDR *p_msg);
262extern void sdp_conn_rcv_l2e_config_cfm (BT_HDR *p_msg);
263extern void sdp_conn_rcv_l2e_conn_failed (BT_HDR *p_msg);
264extern void sdp_conn_rcv_l2e_connected (BT_HDR *p_msg);
265extern void sdp_conn_rcv_l2e_conn_failed (BT_HDR *p_msg);
266extern void sdp_conn_rcv_l2e_data (BT_HDR *p_msg);
Pavlin Radoslavov78bcff72015-12-04 17:36:34 -0800267extern void sdp_conn_timer_timeout(void *data);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800268
269extern tCONN_CB *sdp_conn_originate (UINT8 *p_bd_addr);
270
271/* Functions provided by sdp_utils.c
272*/
273extern tCONN_CB *sdpu_find_ccb_by_cid (UINT16 cid);
274extern tCONN_CB *sdpu_find_ccb_by_db (tSDP_DISCOVERY_DB *p_db);
275extern tCONN_CB *sdpu_allocate_ccb (void);
276extern void sdpu_release_ccb (tCONN_CB *p_ccb);
Manu Viswanadhan74ac5a02016-09-26 16:47:51 +0530277extern void sdpu_update_ccb_cont_info (UINT32 handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800278
279extern UINT8 *sdpu_build_attrib_seq (UINT8 *p_out, UINT16 *p_attr, UINT16 num_attrs);
280extern UINT8 *sdpu_build_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr);
281extern void sdpu_build_n_send_error (tCONN_CB *p_ccb, UINT16 trans_num, UINT16 error_code, char *p_error_text);
282
283extern UINT8 *sdpu_extract_attr_seq (UINT8 *p, UINT16 param_len, tSDP_ATTR_SEQ *p_seq);
284extern UINT8 *sdpu_extract_uid_seq (UINT8 *p, UINT16 param_len, tSDP_UUID_SEQ *p_seq);
285
June R. Tate-Gans24933b52014-09-24 15:25:02 -0700286extern UINT8 *sdpu_get_len_from_type (UINT8 *p, UINT8 type, UINT32 *p_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800287extern BOOLEAN sdpu_is_base_uuid (UINT8 *p_uuid);
288extern BOOLEAN sdpu_compare_uuid_arrays (UINT8 *p_uuid1, UINT32 len1, UINT8 *p_uuid2, UINT16 len2);
June R. Tate-Gans24933b52014-09-24 15:25:02 -0700289extern BOOLEAN sdpu_compare_bt_uuids (tBT_UUID *p_uuid1, tBT_UUID *p_uuid2);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800290extern BOOLEAN sdpu_compare_uuid_with_attr (tBT_UUID *p_btuuid, tSDP_DISC_ATTR *p_attr);
291
292extern void sdpu_sort_attr_list( UINT16 num_attr, tSDP_DISCOVERY_DB *p_db );
293extern UINT16 sdpu_get_list_len( tSDP_UUID_SEQ *uid_seq, tSDP_ATTR_SEQ *attr_seq );
294extern UINT16 sdpu_get_attrib_seq_len(tSDP_RECORD *p_rec, tSDP_ATTR_SEQ *attr_seq);
295extern UINT16 sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE *p_attr);
296extern UINT8 *sdpu_build_partial_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr, UINT16 len, UINT16 *offset);
297extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8* p_uuid128);
298
299/* Functions provided by sdp_db.c
300*/
301extern tSDP_RECORD *sdp_db_service_search (tSDP_RECORD *p_rec, tSDP_UUID_SEQ *p_seq);
302extern tSDP_RECORD *sdp_db_find_record (UINT32 handle);
303extern tSDP_ATTRIBUTE *sdp_db_find_attr_in_rec (tSDP_RECORD *p_rec, UINT16 start_attr, UINT16 end_attr);
304
305
306/* Functions provided by sdp_server.c
307*/
308#if SDP_SERVER_ENABLED == TRUE
309extern void sdp_server_handle_client_req (tCONN_CB *p_ccb, BT_HDR *p_msg);
310#else
311#define sdp_server_handle_client_req(p_ccb, p_msg)
312#endif
313
Ayan Ghoshb4198f82014-07-25 17:51:32 +0530314extern BOOLEAN sdp_dev_blacklisted_for_avrcp15 (BD_ADDR addr);
315extern int sdp_get_stored_avrc_tg_version(BD_ADDR addr);
316
317
The Android Open Source Project5738f832012-12-12 16:00:35 -0800318/* Functions provided by sdp_discovery.c
319*/
320#if SDP_CLIENT_ENABLED == TRUE
321extern void sdp_disc_connected (tCONN_CB *p_ccb);
322extern void sdp_disc_server_rsp (tCONN_CB *p_ccb, BT_HDR *p_msg);
323#else
324#define sdp_disc_connected(p_ccb)
325#define sdp_disc_server_rsp(p_ccb, p_msg)
326#endif
327
328
329
330#endif