sdpint.h 12 KB

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