1 /****************************************************************************** 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 "common/bt_target.h" 29 #include "common/bt_defs.h" 30 #include "stack/sdp_api.h" 31 #include "stack/l2c_api.h" 32 #include "osi/list.h" 33 34 #if (SDP_INCLUDED == TRUE) 35 /* Continuation length - we use a 2-byte offset */ 36 #define SDP_CONTINUATION_LEN 2 37 #define SDP_MAX_CONTINUATION_LEN 16 /* As per the spec */ 38 39 /* Timeout definitions. */ 40 #define SDP_INACT_TIMEOUT 30 /* Inactivity timeout */ 41 #if BT_SDP_BQB_INCLUDED 42 #define SDP_BQB_INACT_TIMEOUT 90 /* Inactivity timeout for BQB test */ 43 #endif /* BT_SDP_BQB_INCLUDED */ 44 45 /* Define the Out-Flow default values. */ 46 #define SDP_OFLOW_QOS_FLAG 0 47 #define SDP_OFLOW_SERV_TYPE 0 48 #define SDP_OFLOW_TOKEN_RATE 0 49 #define SDP_OFLOW_TOKEN_BUCKET_SIZE 0 50 #define SDP_OFLOW_PEAK_BANDWIDTH 0 51 #define SDP_OFLOW_LATENCY 0 52 #define SDP_OFLOW_DELAY_VARIATION 0 53 54 /* Define the In-Flow default values. */ 55 #define SDP_IFLOW_QOS_FLAG 0 56 #define SDP_IFLOW_SERV_TYPE 0 57 #define SDP_IFLOW_TOKEN_RATE 0 58 #define SDP_IFLOW_TOKEN_BUCKET_SIZE 0 59 #define SDP_IFLOW_PEAK_BANDWIDTH 0 60 #define SDP_IFLOW_LATENCY 0 61 #define SDP_IFLOW_DELAY_VARIATION 0 62 63 #define SDP_LINK_TO 0 64 65 /* Define the type of device notification. */ 66 /* (Inquiry Scan and Page Scan) */ 67 #define SDP_DEVICE_NOTI_LEN sizeof (BT_HDR) + \ 68 HCIC_PREAMBLE_SIZE + \ 69 HCIC_PARAM_SIZE_WRITE_PARAM1 70 71 #define SDP_DEVICE_NOTI_FLAG 0x03 72 73 /* Define the Protocol Data Unit (PDU) types. 74 */ 75 #define SDP_PDU_ERROR_RESPONSE 0x01 76 #define SDP_PDU_SERVICE_SEARCH_REQ 0x02 77 #define SDP_PDU_SERVICE_SEARCH_RSP 0x03 78 #define SDP_PDU_SERVICE_ATTR_REQ 0x04 79 #define SDP_PDU_SERVICE_ATTR_RSP 0x05 80 #define SDP_PDU_SERVICE_SEARCH_ATTR_REQ 0x06 81 #define SDP_PDU_SERVICE_SEARCH_ATTR_RSP 0x07 82 83 /* Max UUIDs and attributes we support per sequence */ 84 #define MAX_UUIDS_PER_SEQ 8 85 #define MAX_ATTR_PER_SEQ 8 86 87 /* Max length we support for any attribute */ 88 // btla-specific ++ 89 #ifdef SDP_MAX_ATTR_LEN 90 #define MAX_ATTR_LEN SDP_MAX_ATTR_LEN 91 #else 92 #define MAX_ATTR_LEN 256 93 #endif 94 // btla-specific -- 95 96 /* Internal UUID sequence representation */ 97 typedef struct { 98 UINT16 len; 99 UINT8 value[MAX_UUID_SIZE]; 100 } tUID_ENT; 101 102 typedef struct { 103 UINT16 num_uids; 104 tUID_ENT uuid_entry[MAX_UUIDS_PER_SEQ]; 105 } tSDP_UUID_SEQ; 106 107 108 /* Internal attribute sequence definitions */ 109 typedef struct { 110 UINT16 start; 111 UINT16 end; 112 } tATT_ENT; 113 114 typedef struct { 115 UINT16 num_attr; 116 tATT_ENT attr_entry[MAX_ATTR_PER_SEQ]; 117 } tSDP_ATTR_SEQ; 118 119 120 /* Define the attribute element of the SDP database record */ 121 typedef struct { 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 */ 129 typedef struct { 130 UINT32 record_handle; 131 UINT32 free_pad_ptr; 132 UINT16 num_attributes; 133 tSDP_ATTRIBUTE attribute[SDP_MAX_REC_ATTR]; 134 UINT8 attr_pad[SDP_MAX_PAD_LEN]; 135 } tSDP_RECORD; 136 137 138 /* Define the SDP database */ 139 typedef struct { 140 UINT32 di_primary_handle; /* Device ID Primary record or NULL if nonexistent */ 141 UINT16 num_records; 142 list_t *p_record_list; 143 } tSDP_DB; 144 145 enum { 146 SDP_IS_SEARCH, 147 SDP_IS_ATTR_SEARCH, 148 }; 149 150 #if SDP_SERVER_ENABLED == TRUE 151 /* Continuation information for the SDP server response */ 152 typedef struct { 153 UINT16 next_attr_index; /* attr index for next continuation response */ 154 UINT16 next_attr_start_id; /* attr id to start with for the attr index in next cont. response */ 155 tSDP_RECORD *prev_sdp_rec; /* last sdp record that was completely sent in the response */ 156 BOOLEAN last_attr_seq_desc_sent; /* whether attr seq length has been sent previously */ 157 UINT16 attr_offset; /* offset within the attr to keep trak of partial attributes in the responses */ 158 } tSDP_CONT_INFO; 159 #endif /* SDP_SERVER_ENABLED == TRUE */ 160 161 /* Define the SDP Connection Control Block */ 162 typedef struct { 163 #define SDP_STATE_IDLE 0 164 #define SDP_STATE_CONN_SETUP 1 165 #define SDP_STATE_CFG_SETUP 2 166 #define SDP_STATE_CONNECTED 3 167 UINT8 con_state; 168 169 #define SDP_FLAGS_IS_ORIG 0x01 170 #define SDP_FLAGS_HIS_CFG_DONE 0x02 171 #define SDP_FLAGS_MY_CFG_DONE 0x04 172 UINT8 con_flags; 173 174 BD_ADDR device_address; 175 TIMER_LIST_ENT timer_entry; 176 UINT16 rem_mtu_size; 177 UINT16 connection_id; 178 UINT16 list_len; /* length of the response in the GKI buffer */ 179 UINT8 *rsp_list; /* pointer to GKI buffer holding response */ 180 181 #if SDP_CLIENT_ENABLED == TRUE 182 tSDP_DISCOVERY_DB *p_db; /* Database to save info into */ 183 tSDP_DISC_CMPL_CB *p_cb; /* Callback for discovery done */ 184 tSDP_DISC_CMPL_CB2 *p_cb2; /* Callback for discovery done piggy back with the user data */ 185 void *user_data; /* piggy back user data */ 186 UINT32 handles[SDP_MAX_DISC_SERVER_RECS]; /* Discovered server record handles */ 187 UINT16 num_handles; /* Number of server handles */ 188 UINT16 cur_handle; /* Current handle being processed */ 189 UINT16 transaction_id; 190 UINT16 disconnect_reason; /* Disconnect reason */ 191 #if (defined(SDP_BROWSE_PLUS) && SDP_BROWSE_PLUS == TRUE) 192 UINT16 cur_uuid_idx; 193 #endif 194 195 #define SDP_DISC_WAIT_CONN 0 196 #define SDP_DISC_WAIT_HANDLES 1 197 #define SDP_DISC_WAIT_ATTR 2 198 #define SDP_DISC_WAIT_SEARCH_ATTR 3 199 #define SDP_DISC_WAIT_CANCEL 5 200 201 UINT8 disc_state; 202 UINT8 is_attr_search; 203 #endif /* SDP_CLIENT_ENABLED == TRUE */ 204 205 #if SDP_SERVER_ENABLED == TRUE 206 UINT16 cont_offset; /* Continuation state data in the server response */ 207 tSDP_CONT_INFO cont_info; /* structure to hold continuation information for the server response */ 208 #endif /* SDP_SERVER_ENABLED == TRUE */ 209 210 } tCONN_CB; 211 212 213 /* The main SDP control block */ 214 typedef struct { 215 tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */ 216 tCONN_CB ccb[SDP_MAX_CONNECTIONS]; 217 #if SDP_SERVER_ENABLED == TRUE 218 tSDP_DB server_db; 219 #endif 220 tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */ 221 UINT16 max_attr_list_size; /* Max attribute list size to use */ 222 UINT16 max_recs_per_search; /* Max records we want per seaarch */ 223 UINT8 trace_level; 224 } tSDP_CB; 225 226 #ifdef __cplusplus 227 extern "C" { 228 #endif 229 /* Global SDP data */ 230 #if SDP_DYNAMIC_MEMORY == FALSE 231 extern tSDP_CB sdp_cb; 232 #else 233 extern tSDP_CB *sdp_cb_ptr; 234 #define sdp_cb (*sdp_cb_ptr) 235 #endif 236 237 #ifdef __cplusplus 238 } 239 #endif 240 241 /* Functions provided by sdp_main.c */ 242 extern void sdp_init (void); 243 extern void sdp_deinit (void); 244 extern void sdp_disconnect (tCONN_CB *p_ccb, UINT16 reason); 245 246 #if (defined(SDP_DEBUG) && SDP_DEBUG == TRUE) 247 extern UINT16 sdp_set_max_attr_list_size (UINT16 max_size); 248 #endif 249 250 /* Functions provided by sdp_conn.c 251 */ 252 extern void sdp_conn_rcv_l2e_conn_ind (BT_HDR *p_msg); 253 extern void sdp_conn_rcv_l2e_conn_cfm (BT_HDR *p_msg); 254 extern void sdp_conn_rcv_l2e_disc (BT_HDR *p_msg); 255 extern void sdp_conn_rcv_l2e_config_ind (BT_HDR *p_msg); 256 extern void sdp_conn_rcv_l2e_config_cfm (BT_HDR *p_msg); 257 extern void sdp_conn_rcv_l2e_conn_failed (BT_HDR *p_msg); 258 extern void sdp_conn_rcv_l2e_connected (BT_HDR *p_msg); 259 extern void sdp_conn_rcv_l2e_conn_failed (BT_HDR *p_msg); 260 extern void sdp_conn_rcv_l2e_data (BT_HDR *p_msg); 261 extern void sdp_conn_timeout (tCONN_CB *p_ccb); 262 263 extern tCONN_CB *sdp_conn_originate (UINT8 *p_bd_addr); 264 265 /* Functions provided by sdp_utils.c 266 */ 267 extern tCONN_CB *sdpu_find_ccb_by_cid (UINT16 cid); 268 extern tCONN_CB *sdpu_find_ccb_by_db (tSDP_DISCOVERY_DB *p_db); 269 extern tCONN_CB *sdpu_allocate_ccb (void); 270 extern void sdpu_release_ccb (tCONN_CB *p_ccb); 271 272 extern UINT8 *sdpu_build_attrib_seq (UINT8 *p_out, UINT16 *p_attr, UINT16 num_attrs); 273 extern UINT8 *sdpu_build_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr); 274 extern void sdpu_build_n_send_error (tCONN_CB *p_ccb, UINT16 trans_num, UINT16 error_code, char *p_error_text); 275 276 extern UINT8 *sdpu_extract_attr_seq (UINT8 *p, UINT16 param_len, tSDP_ATTR_SEQ *p_seq); 277 extern UINT8 *sdpu_extract_uid_seq (UINT8 *p, UINT16 param_len, tSDP_UUID_SEQ *p_seq); 278 279 extern UINT8 *sdpu_get_len_from_type (UINT8 *p, UINT8 type, UINT32 *p_len); 280 extern BOOLEAN sdpu_is_base_uuid (UINT8 *p_uuid); 281 extern BOOLEAN sdpu_compare_uuid_arrays (UINT8 *p_uuid1, UINT32 len1, UINT8 *p_uuid2, UINT16 len2); 282 extern BOOLEAN sdpu_compare_bt_uuids (tBT_UUID *p_uuid1, tBT_UUID *p_uuid2); 283 extern BOOLEAN sdpu_compare_uuid_with_attr (tBT_UUID *p_btuuid, tSDP_DISC_ATTR *p_attr); 284 285 extern void sdpu_sort_attr_list( UINT16 num_attr, tSDP_DISCOVERY_DB *p_db ); 286 extern UINT16 sdpu_get_list_len( tSDP_UUID_SEQ *uid_seq, tSDP_ATTR_SEQ *attr_seq ); 287 extern UINT16 sdpu_get_attrib_seq_len(tSDP_RECORD *p_rec, tSDP_ATTR_SEQ *attr_seq); 288 extern UINT16 sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE *p_attr); 289 extern UINT8 *sdpu_build_partial_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr, UINT16 len, UINT16 *offset); 290 extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8 *p_uuid128); 291 292 /* Functions provided by sdp_db.c 293 */ 294 extern tSDP_RECORD *sdp_db_service_search (tSDP_RECORD *p_rec, tSDP_UUID_SEQ *p_seq); 295 extern tSDP_RECORD *sdp_db_find_record (UINT32 handle); 296 extern tSDP_ATTRIBUTE *sdp_db_find_attr_in_rec (tSDP_RECORD *p_rec, UINT16 start_attr, UINT16 end_attr); 297 298 299 /* Functions provided by sdp_server.c 300 */ 301 #if SDP_SERVER_ENABLED == TRUE 302 extern void sdp_server_handle_client_req (tCONN_CB *p_ccb, BT_HDR *p_msg); 303 #else 304 #define sdp_server_handle_client_req(p_ccb, p_msg) 305 #endif 306 307 /* Functions provided by sdp_discovery.c 308 */ 309 #if SDP_CLIENT_ENABLED == TRUE 310 extern void sdp_disc_connected (tCONN_CB *p_ccb); 311 extern void sdp_disc_server_rsp (tCONN_CB *p_ccb, BT_HDR *p_msg); 312 #else 313 #define sdp_disc_connected(p_ccb) 314 #define sdp_disc_server_rsp(p_ccb, p_msg) 315 #endif 316 317 #endif ///SDP_INCLUDED == TRUE 318 319 #endif 320