btm_int.h 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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 the main Bluetooth Manager (BTM) internal
  21. * definitions.
  22. *
  23. ******************************************************************************/
  24. #ifndef BTM_INT_H
  25. #define BTM_INT_H
  26. #include "common/bt_defs.h"
  27. #include "common/bt_target.h"
  28. #include "stack/hcidefs.h"
  29. #include "stack/rfcdefs.h"
  30. #include "stack/btm_api.h"
  31. #include "osi/fixed_queue.h"
  32. #if (BLE_INCLUDED == TRUE)
  33. #include "btm_ble_int.h"
  34. #endif
  35. #if (SMP_INCLUDED == TRUE)
  36. #include "stack/smp_api.h"
  37. #endif
  38. #if BTM_MAX_LOC_BD_NAME_LEN > 0
  39. typedef char tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1];
  40. #endif
  41. #define BTM_ACL_IS_CONNECTED(bda) (btm_bda_to_acl (bda, BT_TRANSPORT_BR_EDR) != NULL)
  42. /* Definitions for Server Channel Number (SCN) management
  43. */
  44. #define BTM_MAX_SCN PORT_MAX_RFC_PORTS
  45. /* Define masks for supported and exception 2.0 ACL packet types
  46. */
  47. #define BTM_ACL_SUPPORTED_PKTS_MASK (HCI_PKT_TYPES_MASK_DM1 | \
  48. HCI_PKT_TYPES_MASK_DH1 | \
  49. HCI_PKT_TYPES_MASK_DM3 | \
  50. HCI_PKT_TYPES_MASK_DH3 | \
  51. HCI_PKT_TYPES_MASK_DM5 | \
  52. HCI_PKT_TYPES_MASK_DH5)
  53. #define BTM_ACL_EXCEPTION_PKTS_MASK (HCI_PKT_TYPES_MASK_NO_2_DH1 | \
  54. HCI_PKT_TYPES_MASK_NO_3_DH1 | \
  55. HCI_PKT_TYPES_MASK_NO_2_DH3 | \
  56. HCI_PKT_TYPES_MASK_NO_3_DH3 | \
  57. HCI_PKT_TYPES_MASK_NO_2_DH5 | \
  58. HCI_PKT_TYPES_MASK_NO_3_DH5)
  59. #define BTM_EPR_AVAILABLE(p) ((HCI_ATOMIC_ENCRYPT_SUPPORTED((p)->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]) && \
  60. HCI_ATOMIC_ENCRYPT_SUPPORTED(controller_get_interface()->get_features_classic(0)->as_array)) \
  61. ? TRUE : FALSE)
  62. #define BTM_IS_BRCM_CONTROLLER() (controller_get_interface()->get_bt_version()->manufacturer == LMP_COMPID_BROADCOM)
  63. /* Define the ACL Management control structure
  64. */
  65. typedef struct {
  66. UINT16 hci_handle;
  67. UINT16 pkt_types_mask;
  68. UINT16 clock_offset;
  69. BD_ADDR remote_addr;
  70. DEV_CLASS remote_dc;
  71. BD_NAME remote_name;
  72. UINT16 manufacturer;
  73. UINT16 lmp_subversion;
  74. UINT16 link_super_tout;
  75. BD_FEATURES peer_lmp_features[HCI_EXT_FEATURES_PAGE_MAX + 1]; /* Peer LMP Extended features mask table for the device */
  76. UINT8 num_read_pages;
  77. UINT8 lmp_version;
  78. BOOLEAN in_use;
  79. UINT8 link_role;
  80. BOOLEAN link_up_issued; /* True if busy_level link up has been issued */
  81. #define BTM_ACL_SWKEY_STATE_IDLE 0
  82. #define BTM_ACL_SWKEY_STATE_MODE_CHANGE 1
  83. #define BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF 2
  84. #define BTM_ACL_SWKEY_STATE_SWITCHING 3
  85. #define BTM_ACL_SWKEY_STATE_ENCRYPTION_ON 4
  86. #define BTM_ACL_SWKEY_STATE_IN_PROGRESS 5
  87. UINT8 switch_role_state;
  88. #define BTM_ACL_ENCRYPT_STATE_IDLE 0
  89. #define BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF 1 /* encryption turning off */
  90. #define BTM_ACL_ENCRYPT_STATE_TEMP_FUNC 2 /* temporarily off for change link key or role switch */
  91. #define BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON 3 /* encryption turning on */
  92. UINT8 encrypt_state; /* overall BTM encryption state */
  93. #if BLE_INCLUDED == TRUE
  94. tBT_TRANSPORT transport;
  95. BD_ADDR conn_addr; /* local device address used for this connection */
  96. UINT8 conn_addr_type; /* local device address type for this connection */
  97. BD_ADDR active_remote_addr; /* remote address used on this connection */
  98. UINT8 active_remote_addr_type; /* local device address type for this connection */
  99. BD_FEATURES peer_le_features; /* Peer LE Used features mask for the device */
  100. tBTM_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback;
  101. tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS data_length_params;
  102. #endif
  103. } tACL_CONN;
  104. /*****************************************************
  105. ** TIMER Definitions
  106. ******************************************************/
  107. #define TT_DEV_RESET 1
  108. #define TT_DEV_RLN 2
  109. #define TT_DEV_RLNKP 4 /* Read Link Policy Settings */
  110. /* Define the Device Management control structure
  111. */
  112. typedef struct {
  113. tBTM_DEV_STATUS_CB *p_dev_status_cb; /* Device status change callback */
  114. tBTM_VS_EVT_CB *p_vend_spec_cb[BTM_MAX_VSE_CALLBACKS]; /* Register for vendor specific events */
  115. tBTM_CMPL_CB *p_stored_link_key_cmpl_cb; /* Read/Write/Delete stored link key */
  116. TIMER_LIST_ENT reset_timer;
  117. tBTM_CMPL_CB *p_reset_cmpl_cb;
  118. TIMER_LIST_ENT rln_timer;
  119. tBTM_CMPL_CB *p_rln_cmpl_cb; /* Callback function to be called when */
  120. /* read local name function complete */
  121. TIMER_LIST_ENT rssi_timer;
  122. tBTM_CMPL_CB *p_rssi_cmpl_cb; /* Callback function to be called when */
  123. /* read rssi function completes */
  124. TIMER_LIST_ENT lnk_quality_timer;
  125. tBTM_CMPL_CB *p_lnk_qual_cmpl_cb;/* Callback function to be called when */
  126. /* read link quality function completes */
  127. TIMER_LIST_ENT txpwer_timer;
  128. tBTM_CMPL_CB *p_txpwer_cmpl_cb; /* Callback function to be called when */
  129. /* read inq tx power function completes */
  130. TIMER_LIST_ENT qossu_timer;
  131. tBTM_CMPL_CB *p_qossu_cmpl_cb; /* Callback function to be called when */
  132. /* qos setup function completes */
  133. tBTM_ROLE_SWITCH_CMPL switch_role_ref_data;
  134. tBTM_CMPL_CB *p_switch_role_cb; /* Callback function to be called when */
  135. /* requested switch role is completed */
  136. TIMER_LIST_ENT tx_power_timer;
  137. tBTM_CMPL_CB *p_tx_power_cmpl_cb;/* Callback function to be called */
  138. DEV_CLASS dev_class; /* Local device class */
  139. #if BLE_INCLUDED == TRUE
  140. tBTM_CMPL_CB *p_le_test_cmd_cmpl_cb; /* Callback function to be called when
  141. LE test mode command has been sent successfully */
  142. BD_ADDR read_tx_pwr_addr; /* read TX power target address */
  143. #define BTM_LE_SUPPORT_STATE_SIZE 8
  144. UINT8 le_supported_states[BTM_LE_SUPPORT_STATE_SIZE];
  145. tBTM_BLE_LOCAL_ID_KEYS id_keys; /* local BLE ID keys */
  146. BT_OCTET16 ble_encryption_key_value; /* BLE encryption key */
  147. #if BTM_BLE_CONFORMANCE_TESTING == TRUE
  148. BOOLEAN no_disc_if_pair_fail;
  149. BOOLEAN enable_test_mac_val;
  150. BT_OCTET8 test_mac;
  151. BOOLEAN enable_test_local_sign_cntr;
  152. UINT32 test_local_sign_cntr;
  153. #endif
  154. #endif /* BLE_INCLUDED */
  155. tBTM_IO_CAP loc_io_caps; /* IO capability of the local device */
  156. tBTM_AUTH_REQ loc_auth_req; /* the auth_req flag */
  157. BOOLEAN secure_connections_only; /* Rejects service level 0 connections if */
  158. /* itself or peer device doesn't support */
  159. /* secure connections */
  160. } tBTM_DEVCB;
  161. /* Define the structures and constants used for inquiry
  162. */
  163. /* Definitions of limits for inquiries */
  164. #define BTM_PER_INQ_MIN_MAX_PERIOD HCI_PER_INQ_MIN_MAX_PERIOD
  165. #define BTM_PER_INQ_MAX_MAX_PERIOD HCI_PER_INQ_MAX_MAX_PERIOD
  166. #define BTM_PER_INQ_MIN_MIN_PERIOD HCI_PER_INQ_MIN_MIN_PERIOD
  167. #define BTM_PER_INQ_MAX_MIN_PERIOD HCI_PER_INQ_MAX_MIN_PERIOD
  168. #define BTM_MAX_INQUIRY_LENGTH HCI_MAX_INQUIRY_LENGTH
  169. #define BTM_MIN_INQUIRY_LEN 0x01
  170. #define BTM_MIN_INQ_TX_POWER -70
  171. #define BTM_MAX_INQ_TX_POWER 20
  172. typedef struct {
  173. UINT32 inq_count; /* Used for determining if a response has already been */
  174. /* received for the current inquiry operation. (We do not */
  175. /* want to flood the caller with multiple responses from */
  176. /* the same device. */
  177. BD_ADDR bd_addr;
  178. } tINQ_BDADDR;
  179. typedef struct {
  180. UINT32 time_of_resp;
  181. UINT32 inq_count; /* "timestamps" the entry with a particular inquiry count */
  182. /* Used for determining if a response has already been */
  183. /* received for the current inquiry operation. (We do not */
  184. /* want to flood the caller with multiple responses from */
  185. /* the same device. */
  186. tBTM_INQ_INFO inq_info;
  187. BOOLEAN in_use;
  188. #if (BLE_INCLUDED == TRUE)
  189. BOOLEAN scan_rsp;
  190. #endif
  191. } tINQ_DB_ENT;
  192. enum {
  193. INQ_NONE,
  194. INQ_LE_OBSERVE,
  195. INQ_GENERAL
  196. };
  197. typedef UINT8 tBTM_INQ_TYPE;
  198. typedef struct {
  199. tBTM_CMPL_CB *p_remname_cmpl_cb;
  200. #define BTM_EXT_RMT_NAME_TIMEOUT 40
  201. TIMER_LIST_ENT rmt_name_timer_ent;
  202. UINT16 discoverable_mode;
  203. UINT16 connectable_mode;
  204. UINT16 page_scan_window;
  205. UINT16 page_scan_period;
  206. UINT16 inq_scan_window;
  207. UINT16 inq_scan_period;
  208. UINT16 inq_scan_type;
  209. UINT16 page_scan_type; /* current page scan type */
  210. tBTM_INQ_TYPE scan_type;
  211. BD_ADDR remname_bda; /* Name of bd addr for active remote name request */
  212. #define BTM_RMT_NAME_INACTIVE 0
  213. #define BTM_RMT_NAME_EXT 0x1 /* Initiated through API */
  214. #define BTM_RMT_NAME_SEC 0x2 /* Initiated internally by security manager */
  215. #define BTM_RMT_NAME_INQ 0x4 /* Remote name initiated internally by inquiry */
  216. BOOLEAN remname_active; /* State of a remote name request by external API */
  217. tBTM_CMPL_CB *p_inq_cmpl_cb;
  218. tBTM_INQ_RESULTS_CB *p_inq_results_cb;
  219. tBTM_CMPL_CB *p_inq_ble_cmpl_cb; /*completion callback exclusively for LE Observe*/
  220. tBTM_INQ_RESULTS_CB *p_inq_ble_results_cb;/*results callback exclusively for LE observe*/
  221. tBTM_CMPL_CB *p_inqfilter_cmpl_cb; /* Called (if not NULL) after inquiry filter completed */
  222. UINT32 inq_counter; /* Counter incremented each time an inquiry completes */
  223. /* Used for determining whether or not duplicate devices */
  224. /* have responded to the same inquiry */
  225. TIMER_LIST_ENT inq_timer_ent;
  226. tINQ_BDADDR *p_bd_db; /* Pointer to memory that holds bdaddrs */
  227. UINT16 num_bd_entries; /* Number of entries in database */
  228. UINT16 max_bd_entries; /* Maximum number of entries that can be stored */
  229. tINQ_DB_ENT inq_db[BTM_INQ_DB_SIZE];
  230. tBTM_INQ_PARMS inqparms; /* Contains the parameters for the current inquiry */
  231. tBTM_INQUIRY_CMPL inq_cmpl_info; /* Status and number of responses from the last inquiry */
  232. UINT16 per_min_delay; /* Current periodic minimum delay */
  233. UINT16 per_max_delay; /* Current periodic maximum delay */
  234. BOOLEAN inqfilt_active;
  235. UINT8 pending_filt_complete_event; /* to take care of btm_event_filter_complete corresponding to */
  236. /* inquiry that has been cancelled*/
  237. UINT8 inqfilt_type; /* Contains the inquiry filter type (BD ADDR, COD, or Clear) */
  238. #define BTM_INQ_INACTIVE_STATE 0
  239. #define BTM_INQ_CLR_FILT_STATE 1 /* Currently clearing the inquiry filter preceeding the inquiry request */
  240. /* (bypassed if filtering is not used) */
  241. #define BTM_INQ_SET_FILT_STATE 2 /* Sets the new filter (or turns off filtering) in this state */
  242. #define BTM_INQ_ACTIVE_STATE 3 /* Actual inquiry or periodic inquiry is in progress */
  243. #define BTM_INQ_REMNAME_STATE 4 /* Remote name requests are active */
  244. UINT8 state; /* Current state that the inquiry process is in */
  245. UINT8 inq_active; /* Bit Mask indicating type of inquiry is active */
  246. BOOLEAN no_inc_ssp; /* TRUE, to stop inquiry on incoming SSP */
  247. #if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
  248. btm_inq_state next_state; /*interleaving state to determine next mode to be inquired*/
  249. #endif
  250. } tBTM_INQUIRY_VAR_ST;
  251. /* The MSB of the clock offset field indicates that the offset is valid if TRUE */
  252. #define BTM_CLOCK_OFFSET_VALID 0x8000
  253. /* Define the structures needed by security management
  254. */
  255. #define BTM_SEC_INVALID_HANDLE 0xFFFF
  256. typedef UINT8 *BTM_BD_NAME_PTR; /* Pointer to Device name */
  257. /* Security callback is called by this unit when security
  258. ** procedures are completed. Parameters are
  259. ** BD Address of remote
  260. ** Result of the operation
  261. */
  262. typedef tBTM_SEC_CBACK tBTM_SEC_CALLBACK;
  263. #define BTM_DATA_HANDLE_MASK 0x0FFF
  264. #define BTMD_GET_HANDLE(u16) (UINT16)((u16) & BTM_DATA_HANDLE_MASK)
  265. typedef void (tBTM_SCO_IND_CBACK) (UINT16 sco_inx) ;
  266. /* MACROs to convert from SCO packet types mask to ESCO and back */
  267. #define BTM_SCO_PKT_TYPE_MASK ( HCI_PKT_TYPES_MASK_HV1 \
  268. | HCI_PKT_TYPES_MASK_HV2 \
  269. | HCI_PKT_TYPES_MASK_HV3)
  270. /* Mask defining only the SCO types of an esco packet type */
  271. #define BTM_ESCO_PKT_TYPE_MASK ( HCI_ESCO_PKT_TYPES_MASK_HV1 \
  272. | HCI_ESCO_PKT_TYPES_MASK_HV2 \
  273. | HCI_ESCO_PKT_TYPES_MASK_HV3)
  274. #define BTM_SCO_2_ESCO(scotype) ((UINT16)(((scotype) & BTM_SCO_PKT_TYPE_MASK) >> 5))
  275. #define BTM_ESCO_2_SCO(escotype) ((UINT16)(((escotype) & BTM_ESCO_PKT_TYPE_MASK) << 5))
  276. /* Define masks for supported and exception 2.0 SCO packet types
  277. */
  278. #define BTM_SCO_SUPPORTED_PKTS_MASK (HCI_ESCO_PKT_TYPES_MASK_HV1 | \
  279. HCI_ESCO_PKT_TYPES_MASK_HV2 | \
  280. HCI_ESCO_PKT_TYPES_MASK_HV3 | \
  281. HCI_ESCO_PKT_TYPES_MASK_EV3 | \
  282. HCI_ESCO_PKT_TYPES_MASK_EV4 | \
  283. HCI_ESCO_PKT_TYPES_MASK_EV5)
  284. #define BTM_SCO_EXCEPTION_PKTS_MASK (HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 | \
  285. HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 | \
  286. HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 | \
  287. HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5)
  288. #define BTM_SCO_ROUTE_UNKNOWN 0xff
  289. /* Define the structure that contains (e)SCO data */
  290. typedef struct {
  291. tBTM_ESCO_CBACK *p_esco_cback; /* Callback for eSCO events */
  292. tBTM_ESCO_PARAMS setup;
  293. tBTM_ESCO_DATA data; /* Connection complete information */
  294. UINT8 hci_status;
  295. } tBTM_ESCO_INFO;
  296. /* Define the structure used for SCO Management
  297. */
  298. typedef struct {
  299. tBTM_ESCO_INFO esco; /* Current settings */
  300. #if BTM_SCO_HCI_INCLUDED == TRUE
  301. #define BTM_SCO_XMIT_QUEUE_THRS 20
  302. fixed_queue_t *xmit_data_q; /* SCO data transmitting queue */
  303. INT16 sent_not_acked;
  304. #endif
  305. tBTM_SCO_CB *p_conn_cb; /* Callback for when connected */
  306. tBTM_SCO_CB *p_disc_cb; /* Callback for when disconnect */
  307. UINT16 state; /* The state of the SCO link */
  308. UINT16 hci_handle; /* HCI Handle */
  309. BOOLEAN is_orig; /* TRUE if the originator */
  310. BOOLEAN rem_bd_known; /* TRUE if remote BD addr known */
  311. } tSCO_CONN;
  312. /* SCO Management control block */
  313. typedef struct {
  314. tBTM_SCO_IND_CBACK *app_sco_ind_cb;
  315. #if BTM_SCO_HCI_INCLUDED == TRUE
  316. tBTM_SCO_DATA_CB *p_data_cb; /* Callback for SCO data over HCI */
  317. UINT32 xmit_window_size; /* Total SCO window in bytes */
  318. UINT16 num_lm_sco_bufs;
  319. #endif
  320. tSCO_CONN sco_db[BTM_MAX_SCO_LINKS];
  321. tBTM_ESCO_PARAMS def_esco_parms;
  322. BD_ADDR xfer_addr;
  323. UINT16 sco_disc_reason;
  324. BOOLEAN esco_supported; /* TRUE if 1.2 cntlr AND supports eSCO links */
  325. tBTM_SCO_TYPE desired_sco_mode;
  326. tBTM_SCO_TYPE xfer_sco_type;
  327. tBTM_SCO_PCM_PARAM sco_pcm_param;
  328. tBTM_SCO_CODEC_TYPE codec_in_use; /* None, CVSD, MSBC, etc. */
  329. #if BTM_SCO_HCI_INCLUDED == TRUE
  330. tBTM_SCO_ROUTE_TYPE sco_path;
  331. #endif
  332. } tSCO_CB;
  333. #if BTM_SCO_INCLUDED == TRUE
  334. void btm_set_sco_ind_cback( tBTM_SCO_IND_CBACK *sco_ind_cb );
  335. void btm_accept_sco_link(UINT16 sco_inx, tBTM_ESCO_PARAMS *p_setup,
  336. tBTM_SCO_CB *p_conn_cb, tBTM_SCO_CB *p_disc_cb);
  337. void btm_reject_sco_link(UINT16 sco_inx );
  338. void btm_sco_chk_pend_rolechange (UINT16 hci_handle);
  339. #else
  340. #define btm_accept_sco_link(sco_inx, p_setup, p_conn_cb, p_disc_cb)
  341. #define btm_reject_sco_link(sco_inx)
  342. #define btm_set_sco_ind_cback(sco_ind_cb)
  343. #define btm_sco_chk_pend_rolechange(hci_handle)
  344. #endif /* BTM_SCO_INCLUDED */
  345. /*
  346. ** Define structure for Security Service Record.
  347. ** A record exists for each service registered with the Security Manager
  348. */
  349. #define BTM_SEC_OUT_FLAGS (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT | BTM_SEC_OUT_AUTHORIZE)
  350. #define BTM_SEC_IN_FLAGS (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHORIZE)
  351. #define BTM_SEC_OUT_LEVEL4_FLAGS (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT | \
  352. BTM_SEC_OUT_MITM | BTM_SEC_MODE4_LEVEL4)
  353. #define BTM_SEC_IN_LEVEL4_FLAGS (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | \
  354. BTM_SEC_IN_MITM | BTM_SEC_MODE4_LEVEL4)
  355. typedef struct {
  356. UINT32 mx_proto_id; /* Service runs over this multiplexer protocol */
  357. UINT32 orig_mx_chan_id; /* Channel on the multiplexer protocol */
  358. UINT32 term_mx_chan_id; /* Channel on the multiplexer protocol */
  359. UINT16 psm; /* L2CAP PSM value */
  360. UINT16 security_flags; /* Bitmap of required security features */
  361. UINT8 service_id; /* Passed in authorization callback */
  362. #if (L2CAP_UCD_INCLUDED == TRUE)
  363. UINT16 ucd_security_flags; /* Bitmap of required security features for UCD */
  364. #endif
  365. #if BTM_SEC_SERVICE_NAME_LEN > 0
  366. UINT8 orig_service_name[BTM_SEC_SERVICE_NAME_LEN + 1];
  367. UINT8 term_service_name[BTM_SEC_SERVICE_NAME_LEN + 1];
  368. #endif
  369. } tBTM_SEC_SERV_REC;
  370. #if BLE_INCLUDED == TRUE
  371. /* LE Security information of device in Slave Role */
  372. typedef struct {
  373. BT_OCTET16 irk; /* peer diverified identity root */
  374. BT_OCTET16 pltk; /* peer long term key */
  375. BT_OCTET16 pcsrk; /* peer SRK peer device used to secured sign local data */
  376. BT_OCTET16 lltk; /* local long term key */
  377. BT_OCTET16 lcsrk; /* local SRK peer device used to secured sign local data */
  378. BT_OCTET8 rand; /* random vector for LTK generation */
  379. UINT16 ediv; /* LTK diversifier of this slave device */
  380. UINT16 div; /* local DIV to generate local LTK=d1(ER,DIV,0) and CSRK=d1(ER,DIV,1) */
  381. UINT8 sec_level; /* local pairing security level */
  382. UINT8 key_size; /* key size of the LTK delivered to peer device */
  383. UINT8 srk_sec_level; /* security property of peer SRK for this device */
  384. UINT8 local_csrk_sec_level; /* security property of local CSRK for this device */
  385. UINT32 counter; /* peer sign counter for verifying rcv signed cmd */
  386. UINT32 local_counter; /* local sign counter for sending signed write cmd*/
  387. } tBTM_SEC_BLE_KEYS;
  388. typedef struct {
  389. BD_ADDR pseudo_addr; /* LE pseudo address of the device if different from device address */
  390. tBLE_ADDR_TYPE ble_addr_type; /* LE device type: public or random address */
  391. tBLE_ADDR_TYPE static_addr_type; /* static address type */
  392. BD_ADDR static_addr; /* static address */
  393. #define BTM_WHITE_LIST_BIT 0x01
  394. #define BTM_RESOLVING_LIST_BIT 0x02
  395. UINT8 in_controller_list; /* in controller resolving list or not */
  396. UINT8 resolving_list_index;
  397. #if BLE_PRIVACY_SPT == TRUE
  398. BD_ADDR cur_rand_addr; /* current random address */
  399. #define BTM_BLE_ADDR_PSEUDO 0 /* address index device record */
  400. #define BTM_BLE_ADDR_RRA 1 /* cur_rand_addr */
  401. #define BTM_BLE_ADDR_STATIC 2 /* static_addr */
  402. UINT8 active_addr_type;
  403. #endif
  404. #if SMP_INCLUDED == TRUE
  405. tBTM_LE_KEY_TYPE key_type; /* bit mask of valid key types in record */
  406. tBTM_SEC_BLE_KEYS keys; /* LE device security info in slave rode */
  407. #if (SMP_SLAVE_CON_PARAMS_UPD_ENABLE == TRUE)
  408. bool skip_update_conn_param; /* skip update connection paraams or not*/
  409. #endif
  410. UINT16 auth_mode; /* Authentication mode */
  411. #endif
  412. #if (BLE_PRIVACY_SPT == TRUE)
  413. tBLE_ADDR_TYPE current_addr_type; /* current adv addr type*/
  414. BD_ADDR current_addr; /* current adv addr*/
  415. bool current_addr_valid; /* current addr info is valid or not*/
  416. #endif
  417. } tBTM_SEC_BLE;
  418. #endif /* BLE_INCLUDED */
  419. /* Peering bond type */
  420. enum {
  421. BOND_TYPE_UNKNOWN,
  422. BOND_TYPE_PERSISTENT,
  423. BOND_TYPE_TEMPORARY
  424. };
  425. typedef UINT8 tBTM_BOND_TYPE;
  426. /*
  427. ** Define structure for Security Device Record.
  428. ** A record exists for each device authenticated with this device
  429. */
  430. typedef struct {
  431. tBTM_SEC_SERV_REC *p_cur_service;
  432. tBTM_SEC_CALLBACK *p_callback;
  433. void *p_ref_data;
  434. UINT32 timestamp; /* Timestamp of the last connection */
  435. UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; /* Bitwise OR of trusted services */
  436. UINT16 hci_handle; /* Handle to connection when exists */
  437. UINT16 clock_offset; /* Latest known clock offset */
  438. BD_ADDR bd_addr; /* BD_ADDR of the device */
  439. DEV_CLASS dev_class; /* DEV_CLASS of the device */
  440. LINK_KEY link_key; /* Device link key */
  441. UINT8 pin_code_length; /* Length of the pin_code used for paring */
  442. #define BTM_SEC_AUTHORIZED BTM_SEC_FLAG_AUTHORIZED /* 0x01 */
  443. #define BTM_SEC_AUTHENTICATED BTM_SEC_FLAG_AUTHENTICATED /* 0x02 */
  444. #define BTM_SEC_ENCRYPTED BTM_SEC_FLAG_ENCRYPTED /* 0x04 */
  445. #define BTM_SEC_NAME_KNOWN 0x08
  446. #define BTM_SEC_LINK_KEY_KNOWN BTM_SEC_FLAG_LKEY_KNOWN /* 0x10 */
  447. #define BTM_SEC_LINK_KEY_AUTHED BTM_SEC_FLAG_LKEY_AUTHED /* 0x20 */
  448. #define BTM_SEC_ROLE_SWITCHED 0x40
  449. #define BTM_SEC_IN_USE 0x80
  450. /* LE link security flag */
  451. #define BTM_SEC_LE_AUTHENTICATED 0x0200 /* LE link is encrypted after pairing with MITM */
  452. #define BTM_SEC_LE_ENCRYPTED 0x0400 /* LE link is encrypted */
  453. #define BTM_SEC_LE_NAME_KNOWN 0x0800 /* not used */
  454. #define BTM_SEC_LE_LINK_KEY_KNOWN 0x1000 /* bonded with peer (peer LTK and/or SRK is saved) */
  455. #define BTM_SEC_LE_LINK_KEY_AUTHED 0x2000 /* pairing is done with MITM */
  456. #define BTM_SEC_16_DIGIT_PIN_AUTHED 0x4000 /* pairing is done with 16 digit pin */
  457. UINT16 sec_flags; /* Current device security state */
  458. tBTM_BD_NAME sec_bd_name; /* User friendly name of the device. (may be truncated to save space in dev_rec table) */
  459. BD_FEATURES features[HCI_EXT_FEATURES_PAGE_MAX + 1]; /* Features supported by the device */
  460. UINT8 num_read_pages;
  461. #define BTM_SEC_STATE_IDLE 0
  462. #define BTM_SEC_STATE_AUTHENTICATING 1
  463. #define BTM_SEC_STATE_ENCRYPTING 2
  464. #define BTM_SEC_STATE_GETTING_NAME 3
  465. #define BTM_SEC_STATE_AUTHORIZING 4
  466. #define BTM_SEC_STATE_SWITCHING_ROLE 5
  467. #define BTM_SEC_STATE_DISCONNECTING 6 /* disconnecting BR/EDR */
  468. #define BTM_SEC_STATE_DELAY_FOR_ENC 7 /* delay to check for encryption to work around */
  469. /* controller problems */
  470. #define BTM_SEC_STATE_DISCONNECTING_BLE 8 /* disconnecting BLE */
  471. #define BTM_SEC_STATE_DISCONNECTING_BOTH 9 /* disconnecting BR/EDR and BLE */
  472. UINT8 sec_state; /* Operating state */
  473. BOOLEAN is_originator; /* TRUE if device is originating connection */
  474. #if (L2CAP_UCD_INCLUDED == TRUE)
  475. BOOLEAN is_ucd; /* TRUE if device is sending or receiving UCD */
  476. /* if incoming security failed, received UCD will be discarded */
  477. #endif
  478. BOOLEAN role_master; /* TRUE if current mode is master */
  479. UINT16 security_required; /* Security required for connection */
  480. BOOLEAN link_key_not_sent; /* link key notification has not been sent waiting for name */
  481. UINT8 link_key_type; /* Type of key used in pairing */
  482. BOOLEAN link_key_changed; /* Changed link key during current connection */
  483. #define BTM_MAX_PRE_SM4_LKEY_TYPE BTM_LKEY_TYPE_REMOTE_UNIT /* the link key type used by legacy pairing */
  484. #define BTM_SM4_UNKNOWN 0x00
  485. #define BTM_SM4_KNOWN 0x10
  486. #define BTM_SM4_TRUE 0x11
  487. #define BTM_SM4_REQ_PEND 0x08 /* set this bit when getting remote features */
  488. #define BTM_SM4_UPGRADE 0x04 /* set this bit when upgrading link key */
  489. #define BTM_SM4_RETRY 0x02 /* set this bit to retry on HCI_ERR_KEY_MISSING or HCI_ERR_LMP_ERR_TRANS_COLLISION */
  490. #define BTM_SM4_DD_ACP 0x20 /* set this bit to indicate peer initiated dedicated bonding */
  491. #define BTM_SM4_CONN_PEND 0x40 /* set this bit to indicate accepting acl conn; to be cleared on btm_acl_created */
  492. UINT8 sm4; /* BTM_SM4_TRUE, if the peer supports SM4 */
  493. tBTM_IO_CAP rmt_io_caps; /* IO capability of the peer device */
  494. tBTM_AUTH_REQ rmt_auth_req; /* the auth_req flag as in the IO caps rsp evt */
  495. BOOLEAN remote_supports_secure_connections;
  496. BOOLEAN remote_features_needed; /* set to true if the local device is in */
  497. /* "Secure Connections Only" mode and it receives */
  498. /* HCI_IO_CAPABILITY_REQUEST_EVT from the peer before */
  499. /* it knows peer's support for Secure Connections */
  500. UINT16 ble_hci_handle; /* use in DUMO connection */
  501. UINT8 enc_key_size; /* current link encryption key size */
  502. tBT_DEVICE_TYPE device_type;
  503. BOOLEAN new_encryption_key_is_p256; /* Set to TRUE when the newly generated LK
  504. ** is generated from P-256.
  505. ** Link encrypted with such LK can be used
  506. ** for SM over BR/EDR.
  507. */
  508. BOOLEAN no_smp_on_br; /* if set to TRUE then SMP on BR/EDR doesn't */
  509. /* work, i.e. link keys crosspairing */
  510. /* SC BR/EDR->SC LE doesn't happen */
  511. tBTM_BOND_TYPE bond_type; /* peering bond type */
  512. #if BLE_INCLUDED == TRUE
  513. tBTM_SEC_BLE ble;
  514. tBTM_LE_CONN_PRAMS conn_params;
  515. #endif
  516. // btla-specific ++
  517. #if BTM_DISC_DURING_RS == TRUE
  518. #define BTM_SEC_RS_NOT_PENDING 0 /* Role Switch not in progress */
  519. #define BTM_SEC_RS_PENDING 1 /* Role Switch in progress */
  520. #define BTM_SEC_DISC_PENDING 2 /* Disconnect is pending */
  521. UINT8 rs_disc_pending;
  522. #endif
  523. // btla-specific --
  524. #define BTM_SEC_NO_LAST_SERVICE_ID 0
  525. UINT8 last_author_service_id; /* ID of last serviced authorized: Reset after each l2cap connection */
  526. BOOLEAN enc_init_by_we;
  527. } tBTM_SEC_DEV_REC;
  528. #define BTM_SEC_IS_SM4(sm) ((BOOLEAN)(BTM_SM4_TRUE == ((sm)&BTM_SM4_TRUE)))
  529. #define BTM_SEC_IS_SM4_LEGACY(sm) ((BOOLEAN)(BTM_SM4_KNOWN == ((sm)&BTM_SM4_TRUE)))
  530. #define BTM_SEC_IS_SM4_UNKNOWN(sm) ((BOOLEAN)(BTM_SM4_UNKNOWN == ((sm)&BTM_SM4_TRUE)))
  531. #define BTM_SEC_LE_MASK (BTM_SEC_LE_AUTHENTICATED|BTM_SEC_LE_ENCRYPTED|BTM_SEC_LE_LINK_KEY_KNOWN|BTM_SEC_LE_LINK_KEY_AUTHED)
  532. /*
  533. ** Define device configuration structure
  534. */
  535. typedef struct {
  536. #if BTM_MAX_LOC_BD_NAME_LEN > 0
  537. tBTM_LOC_BD_NAME bd_name; /* local Bluetooth device name */
  538. #endif
  539. BOOLEAN pin_type; /* TRUE if PIN type is fixed */
  540. UINT8 pin_code_len; /* Bonding information */
  541. PIN_CODE pin_code; /* PIN CODE if pin type is fixed */
  542. BOOLEAN connectable; /* If TRUE page scan should be enabled */
  543. UINT8 def_inq_scan_mode; /* ??? limited/general/none */
  544. } tBTM_CFG;
  545. enum {
  546. BTM_PM_ST_ACTIVE = BTM_PM_STS_ACTIVE,
  547. BTM_PM_ST_HOLD = BTM_PM_STS_HOLD,
  548. BTM_PM_ST_SNIFF = BTM_PM_STS_SNIFF,
  549. BTM_PM_ST_PARK = BTM_PM_STS_PARK,
  550. BTM_PM_ST_PENDING = BTM_PM_STS_PENDING
  551. };
  552. typedef UINT8 tBTM_PM_STATE;
  553. enum {
  554. BTM_PM_SET_MODE_EVT, /* Set power mode API is called. */
  555. BTM_PM_UPDATE_EVT,
  556. BTM_PM_RD_MODE_EVT /* Read power mode API is called. */
  557. };
  558. typedef UINT8 tBTM_PM_EVENT;
  559. typedef struct {
  560. UINT16 event;
  561. UINT16 len;
  562. UINT8 link_ind;
  563. } tBTM_PM_MSG_DATA;
  564. typedef struct {
  565. UINT8 hci_status;
  566. UINT8 mode;
  567. UINT16 interval;
  568. } tBTM_PM_MD_CHG_DATA;
  569. typedef struct {
  570. UINT8 pm_id; /* the entity that calls SetPowerMode API */
  571. tBTM_PM_PWR_MD *p_pmd;
  572. } tBTM_PM_SET_MD_DATA;
  573. typedef struct {
  574. void *p_data;
  575. UINT8 link_ind;
  576. } tBTM_PM_SM_DATA;
  577. typedef struct {
  578. tBTM_PM_PWR_MD req_mode[BTM_MAX_PM_RECORDS + 1]; /* the desired mode and parameters of the connection*/
  579. tBTM_PM_PWR_MD set_mode; /* the mode and parameters sent down to the host controller. */
  580. UINT16 interval; /* the interval from last mode change event. */
  581. #if (BTM_SSR_INCLUDED == TRUE)
  582. UINT16 max_lat; /* stored SSR maximum latency */
  583. UINT16 min_rmt_to;/* stored SSR minimum remote timeout */
  584. UINT16 min_loc_to;/* stored SSR minimum local timeout */
  585. #endif
  586. tBTM_PM_STATE state; /* contains the current mode of the connection */
  587. BOOLEAN chg_ind; /* a request change indication */
  588. } tBTM_PM_MCB;
  589. #define BTM_PM_REC_NOT_USED 0
  590. typedef struct {
  591. tBTM_PM_STATUS_CBACK *cback;/* to notify the registered party of mode change event */
  592. UINT8 mask; /* registered request mask. 0, if this entry is not used */
  593. } tBTM_PM_RCB;
  594. enum {
  595. BTM_BLI_ACL_UP_EVT,
  596. BTM_BLI_ACL_DOWN_EVT,
  597. BTM_BLI_PAGE_EVT,
  598. BTM_BLI_PAGE_DONE_EVT,
  599. BTM_BLI_INQ_EVT,
  600. BTM_BLI_INQ_CANCEL_EVT,
  601. BTM_BLI_INQ_DONE_EVT
  602. };
  603. typedef UINT8 tBTM_BLI_EVENT;
  604. /* Pairing State */
  605. enum {
  606. BTM_PAIR_STATE_IDLE, /* Idle */
  607. BTM_PAIR_STATE_GET_REM_NAME, /* Getting the remote name (to check for SM4) */
  608. BTM_PAIR_STATE_WAIT_PIN_REQ, /* Started authentication, waiting for PIN req (PIN is pre-fetched) */
  609. BTM_PAIR_STATE_WAIT_LOCAL_PIN, /* Waiting for local PIN code */
  610. BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM, /* Waiting user 'yes' to numeric confirmation */
  611. BTM_PAIR_STATE_KEY_ENTRY, /* Key entry state (we are a keyboard) */
  612. BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP, /* Waiting for local response to peer OOB data */
  613. BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS, /* Waiting for local IO capabilities and OOB data */
  614. BTM_PAIR_STATE_INCOMING_SSP, /* Incoming SSP (got peer IO caps when idle) */
  615. BTM_PAIR_STATE_WAIT_AUTH_COMPLETE, /* All done, waiting authentication cpmplete */
  616. BTM_PAIR_STATE_WAIT_DISCONNECT /* Waiting to disconnect the ACL */
  617. };
  618. typedef UINT8 tBTM_PAIRING_STATE;
  619. #define BTM_PAIR_FLAGS_WE_STARTED_DD 0x01 /* We want to do dedicated bonding */
  620. #define BTM_PAIR_FLAGS_PEER_STARTED_DD 0x02 /* Peer initiated dedicated bonding */
  621. #define BTM_PAIR_FLAGS_DISC_WHEN_DONE 0x04 /* Disconnect when done */
  622. #define BTM_PAIR_FLAGS_PIN_REQD 0x08 /* set this bit when pin_callback is called */
  623. #define BTM_PAIR_FLAGS_PRE_FETCH_PIN 0x10 /* set this bit when pre-fetch pin */
  624. #define BTM_PAIR_FLAGS_REJECTED_CONNECT 0x20 /* set this bit when rejected incoming connection */
  625. #define BTM_PAIR_FLAGS_WE_CANCEL_DD 0x40 /* set this bit when cancelling a bonding procedure */
  626. #define BTM_PAIR_FLAGS_LE_ACTIVE 0x80 /* use this bit when SMP pairing is active */
  627. typedef struct {
  628. BOOLEAN is_mux;
  629. BD_ADDR bd_addr;
  630. UINT16 psm;
  631. BOOLEAN is_orig;
  632. tBTM_SEC_CALLBACK *p_callback;
  633. void *p_ref_data;
  634. UINT32 mx_proto_id;
  635. UINT32 mx_chan_id;
  636. tBT_TRANSPORT transport;
  637. } tBTM_SEC_QUEUE_ENTRY;
  638. #if (L2CAP_UCD_INCLUDED == TRUE)
  639. #define CONN_ORIENT_TERM 0x00 /* incoming connection oriented */
  640. #define CONN_ORIENT_ORIG 0x01 /* outgoing connection oriented */
  641. #define CONNLESS_TERM 0x02 /* incoming connectionless */
  642. #define CONNLESS_ORIG 0x03 /* outgoing connectionless */
  643. #define CONNECTION_TYPE_ORIG_MASK 0x01 /* mask for direction */
  644. #define CONNECTION_TYPE_CONNLESS_MASK 0x02 /* mask for connectionless or not */
  645. typedef UINT8 CONNECTION_TYPE;
  646. #else
  647. #define CONN_ORIENT_TERM FALSE
  648. #define CONN_ORIENT_ORIG TRUE
  649. typedef BOOLEAN CONNECTION_TYPE;
  650. #endif /* (L2CAP_UCD_INCLUDED == TRUE) */
  651. /* Define a structure to hold all the BTM data
  652. */
  653. #define BTM_STATE_BUFFER_SIZE 5 /* size of state buffer */
  654. typedef struct {
  655. tBTM_CFG cfg; /* Device configuration */
  656. /****************************************************
  657. ** ACL Management
  658. ****************************************************/
  659. tACL_CONN acl_db[MAX_L2CAP_LINKS];
  660. #if (CLASSIC_BT_INCLUDED == TRUE)
  661. UINT8 btm_scn[BTM_MAX_SCN]; /* current SCNs: TRUE if SCN is in use */
  662. #endif ///CLASSIC_BT_INCLUDED == TRUE
  663. UINT16 btm_def_link_policy;
  664. UINT16 btm_def_link_super_tout;
  665. tBTM_BL_EVENT_MASK bl_evt_mask;
  666. tBTM_BL_CHANGE_CB *p_bl_changed_cb; /* Callback for when Busy Level changed */
  667. /****************************************************
  668. ** Power Management
  669. ****************************************************/
  670. tBTM_PM_MCB pm_mode_db[MAX_L2CAP_LINKS]; /* per ACL link */
  671. tBTM_PM_RCB pm_reg_db[BTM_MAX_PM_RECORDS + 1]; /* per application/module */
  672. UINT8 pm_pend_link; /* the index of acl_db, which has a pending PM cmd */
  673. UINT8 pm_pend_id; /* the id pf the module, which has a pending PM cmd */
  674. /*****************************************************
  675. ** Device control
  676. *****************************************************/
  677. tBTM_DEVCB devcb;
  678. /*****************************************************
  679. ** BLE Device controllers
  680. *****************************************************/
  681. #if (BLE_INCLUDED == TRUE)
  682. tBTM_BLE_CB ble_ctr_cb;
  683. UINT16 enc_handle;
  684. BT_OCTET8 enc_rand; /* received rand value from LTK request*/
  685. UINT16 ediv; /* received ediv value from LTK request */
  686. UINT8 key_size;
  687. tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
  688. #endif
  689. /* Packet types supported by the local device */
  690. UINT16 btm_acl_pkt_types_supported;
  691. UINT16 btm_sco_pkt_types_supported;
  692. /*****************************************************
  693. ** Inquiry
  694. *****************************************************/
  695. tBTM_INQUIRY_VAR_ST btm_inq_vars;
  696. /*****************************************************
  697. ** SCO Management
  698. *****************************************************/
  699. #if BTM_SCO_INCLUDED == TRUE
  700. tSCO_CB sco_cb;
  701. #endif
  702. /*****************************************************
  703. ** Security Management
  704. *****************************************************/
  705. tBTM_APPL_INFO api;
  706. #define BTM_SEC_MAX_RMT_NAME_CALLBACKS 2
  707. tBTM_RMT_NAME_CALLBACK *p_rmt_name_callback[BTM_SEC_MAX_RMT_NAME_CALLBACKS];
  708. #if (SMP_INCLUDED == TRUE)
  709. tBTM_SEC_DEV_REC *p_collided_dev_rec;
  710. #endif ///SMP_INCLUDED == TRUE
  711. TIMER_LIST_ENT sec_collision_tle;
  712. UINT32 collision_start_time;
  713. UINT32 max_collision_delay;
  714. UINT32 dev_rec_count; /* Counter used for device record timestamp */
  715. UINT8 security_mode;
  716. BOOLEAN pairing_disabled;
  717. BOOLEAN connect_only_paired;
  718. BOOLEAN security_mode_changed; /* mode changed during bonding */
  719. BOOLEAN sec_req_pending; /* TRUE if a request is pending */
  720. #if (CLASSIC_BT_INCLUDED == TRUE)
  721. BOOLEAN pin_type_changed; /* pin type changed during bonding */
  722. #endif ///CLASSIC_BT_INCLUDED == TRUE
  723. #if (SMP_INCLUDED == TRUE)
  724. #if (CLASSIC_BT_INCLUDED == TRUE)
  725. // btla-specific ++
  726. #ifdef PORCHE_PAIRING_CONFLICT
  727. UINT8 pin_code_len_saved; /* for legacy devices */
  728. #endif
  729. // btla-specific --
  730. UINT8 pin_code_len; /* for legacy devices */
  731. PIN_CODE pin_code; /* for legacy devices */
  732. UINT8 disc_reason; /* for legacy devices */
  733. UINT16 disc_handle; /* for legacy devices */
  734. #endif ///CLASSIC_BT_INCLUDED == TRUE
  735. tBTM_PAIRING_STATE pairing_state; /* The current pairing state */
  736. UINT8 pairing_flags; /* The current pairing flags */
  737. BD_ADDR pairing_bda; /* The device currently pairing */
  738. TIMER_LIST_ENT pairing_tle; /* Timer for pairing process */
  739. #endif ///SMP_INCLUDED == TRUE
  740. #if SMP_INCLUDED == TRUE || CLASSIC_BT_INCLUDED == TRUE
  741. tBTM_SEC_SERV_REC sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS];
  742. #endif // SMP_INCLUDED == TRUE || BT_CLASSIC_ENABLED == TRUE
  743. tBTM_SEC_DEV_REC sec_dev_rec[BTM_SEC_MAX_DEVICE_RECORDS];
  744. tBTM_SEC_SERV_REC *p_out_serv;
  745. tBTM_MKEY_CALLBACK *mkey_cback;
  746. BD_ADDR connecting_bda;
  747. DEV_CLASS connecting_dc;
  748. UINT8 acl_disc_reason;
  749. UINT8 trace_level;
  750. UINT8 busy_level; /* the current busy level */
  751. BOOLEAN is_paging; /* TRUE, if paging is in progess */
  752. BOOLEAN is_inquiry; /* TRUE, if inquiry is in progess */
  753. fixed_queue_t *page_queue;
  754. BOOLEAN paging;
  755. BOOLEAN discing;
  756. fixed_queue_t *sec_pending_q; /* pending sequrity requests in tBTM_SEC_QUEUE_ENTRY format */
  757. #if (!defined(BT_TRACE_VERBOSE) || (BT_TRACE_VERBOSE == FALSE))
  758. char state_temp_buffer[BTM_STATE_BUFFER_SIZE];
  759. #endif
  760. } tBTM_CB;
  761. typedef struct{
  762. //connection parameters update callback
  763. tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb;
  764. }tBTM_CallbackFunc;
  765. extern tBTM_CallbackFunc conn_param_update_cb;
  766. /* security action for L2CAP COC channels */
  767. #define BTM_SEC_OK 1
  768. #define BTM_SEC_ENCRYPT 2 /* encrypt the link with current key */
  769. #define BTM_SEC_ENCRYPT_NO_MITM 3 /* unauthenticated encryption or better */
  770. #define BTM_SEC_ENCRYPT_MITM 4 /* authenticated encryption */
  771. #define BTM_SEC_ENC_PENDING 5 /* wait for link encryption pending */
  772. typedef UINT8 tBTM_SEC_ACTION;
  773. /*
  774. #ifdef __cplusplus
  775. extern "C"
  776. {
  777. #endif
  778. */
  779. #if BTM_DYNAMIC_MEMORY == FALSE
  780. extern tBTM_CB btm_cb;
  781. #else
  782. extern tBTM_CB *btm_cb_ptr;
  783. #define btm_cb (*btm_cb_ptr)
  784. #endif
  785. /* Internal functions provided by btm_main.c
  786. ********************************************
  787. */
  788. void btm_init (void);
  789. void btm_free (void);
  790. /* Internal functions provided by btm_inq.c
  791. *******************************************
  792. */
  793. tBTM_STATUS btm_initiate_rem_name (BD_ADDR remote_bda,
  794. tBTM_INQ_INFO *p_cur,
  795. UINT8 origin, UINT32 timeout,
  796. tBTM_CMPL_CB *p_cb);
  797. void btm_process_remote_name (BD_ADDR bda, BD_NAME name, UINT16 evt_len,
  798. UINT8 hci_status);
  799. void btm_inq_rmt_name_failed(void);
  800. /* Inquiry related functions */
  801. void btm_clr_inq_db (BD_ADDR p_bda);
  802. void btm_inq_db_init (void);
  803. void btm_process_inq_results (UINT8 *p, UINT8 inq_res_mode);
  804. void btm_process_inq_complete (UINT8 status, UINT8 mode);
  805. void btm_process_cancel_complete(UINT8 status, UINT8 mode);
  806. void btm_event_filter_complete (UINT8 *p);
  807. void btm_inq_stop_on_ssp(void);
  808. void btm_inq_clear_ssp(void);
  809. tINQ_DB_ENT *btm_inq_db_find (BD_ADDR p_bda);
  810. BOOLEAN btm_inq_find_bdaddr (BD_ADDR p_bda);
  811. BOOLEAN btm_lookup_eir(BD_ADDR_PTR p_rem_addr);
  812. /* Internal functions provided by btm_acl.c
  813. ********************************************
  814. */
  815. void btm_acl_init (void);
  816. void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
  817. UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport);
  818. void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport);
  819. void btm_acl_device_down (void);
  820. void btm_acl_update_busy_level (tBTM_BLI_EVENT event);
  821. void btm_cont_rswitch (tACL_CONN *p,
  822. tBTM_SEC_DEV_REC *p_dev_rec,
  823. UINT8 hci_status);
  824. UINT8 btm_handle_to_acl_index (UINT16 hci_handle);
  825. tACL_CONN *btm_handle_to_acl (UINT16 hci_handle);
  826. void btm_read_link_policy_complete (UINT8 *p);
  827. void btm_read_rssi_complete (UINT8 *p);
  828. void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble);
  829. void btm_read_link_quality_complete (UINT8 *p);
  830. tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types);
  831. void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset);
  832. void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role);
  833. void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable);
  834. UINT16 btm_get_acl_disc_reason_code (void);
  835. tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport);
  836. void btm_read_remote_features_complete (UINT8 *p);
  837. void btm_read_remote_ext_features_complete (UINT8 *p);
  838. void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle);
  839. void btm_read_remote_version_complete (UINT8 *p);
  840. void btm_establish_continue (tACL_CONN *p_acl_cb);
  841. // btla-specific ++
  842. void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, UINT16 *p_pkt_type);
  843. // btla-specific --
  844. /* Read maximum data packet that can be sent over current connection */
  845. UINT16 btm_get_max_packet_size (BD_ADDR addr);
  846. tACL_CONN *btm_bda_to_acl (BD_ADDR bda, tBT_TRANSPORT transport);
  847. BOOLEAN btm_acl_notif_conn_collision (BD_ADDR bda);
  848. void btm_pm_reset(void);
  849. void btm_pm_sm_alloc(UINT8 ind);
  850. void btm_pm_proc_cmd_status(UINT8 status);
  851. void btm_pm_proc_mode_change (UINT8 hci_status, UINT16 hci_handle, UINT8 mode,
  852. UINT16 interval);
  853. void btm_pm_proc_ssr_evt (UINT8 *p, UINT16 evt_len);
  854. #if BTM_SCO_INCLUDED == TRUE
  855. void btm_sco_chk_pend_unpark (UINT8 hci_status, UINT16 hci_handle);
  856. #if (BTM_SCO_HCI_INCLUDED == TRUE )
  857. void btm_sco_process_num_bufs (UINT16 num_lm_sco_bufs);
  858. void btm_sco_process_num_completed_pkts (UINT8 *p);
  859. #endif /* (BTM_SCO_HCI_INCLUDED == TRUE ) */
  860. #else
  861. #define btm_sco_chk_pend_unpark(hci_status, hci_handle)
  862. #endif /* BTM_SCO_INCLUDED */
  863. void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow);
  864. /* Internal functions provided by btm_sco.c
  865. ********************************************
  866. */
  867. void btm_sco_init (void);
  868. void btm_sco_connected (UINT8 hci_status, BD_ADDR bda, UINT16 hci_handle,
  869. tBTM_ESCO_DATA *p_esco_data);
  870. void btm_esco_proc_conn_chg (UINT8 status, UINT16 handle, UINT8 tx_interval,
  871. UINT8 retrans_window, UINT16 rx_pkt_len,
  872. UINT16 tx_pkt_len);
  873. void btm_sco_conn_req (BD_ADDR bda, DEV_CLASS dev_class, UINT8 link_type);
  874. void btm_sco_removed (UINT16 hci_handle, UINT8 reason);
  875. void btm_sco_acl_removed (BD_ADDR bda);
  876. void btm_route_sco_data (BT_HDR *p_msg);
  877. BOOLEAN btm_is_sco_active (UINT16 handle);
  878. void btm_remove_sco_links (BD_ADDR bda);
  879. BOOLEAN btm_is_sco_active_by_bdaddr (BD_ADDR remote_bda);
  880. tBTM_SCO_TYPE btm_read_def_esco_mode (tBTM_ESCO_PARAMS *p_parms);
  881. UINT16 btm_find_scb_by_handle (UINT16 handle);
  882. void btm_sco_flush_sco_data(UINT16 sco_inx);
  883. /* Internal functions provided by btm_devctl.c
  884. **********************************************
  885. */
  886. void btm_dev_init (void);
  887. void btm_dev_timeout (TIMER_LIST_ENT *p_tle);
  888. void btm_read_local_name_complete (UINT8 *p, UINT16 evt_len);
  889. #if (BLE_INCLUDED == TRUE)
  890. void btm_ble_add_2_white_list_complete(UINT8 status);
  891. void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len);
  892. void btm_ble_clear_white_list_complete(UINT8 *p, UINT16 evt_len);
  893. BOOLEAN btm_ble_addr_resolvable(BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec);
  894. tBTM_STATUS btm_ble_read_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec);
  895. BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec);
  896. void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec);
  897. #endif /* BLE_INCLUDED */
  898. /* Vendor Specific Command complete evt handler */
  899. void btm_vsc_complete (UINT8 *p, UINT16 cc_opcode, UINT16 evt_len,
  900. tBTM_CMPL_CB *p_vsc_cplt_cback);
  901. void btm_inq_db_reset (void);
  902. void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len);
  903. void btm_delete_stored_link_key_complete (UINT8 *p);
  904. void btm_report_device_status (tBTM_DEV_STATUS status);
  905. /* Internal functions provided by btm_dev.c
  906. **********************************************
  907. */
  908. BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr);
  909. tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr);
  910. void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec, tBT_TRANSPORT transport);
  911. tBTM_SEC_DEV_REC *btm_find_dev (BD_ADDR bd_addr);
  912. tBTM_SEC_DEV_REC *btm_find_or_alloc_dev (BD_ADDR bd_addr);
  913. tBTM_SEC_DEV_REC *btm_find_dev_by_handle (UINT16 handle);
  914. tBTM_BOND_TYPE btm_get_bond_type_dev(BD_ADDR bd_addr);
  915. BOOLEAN btm_set_bond_type_dev(BD_ADDR bd_addr,
  916. tBTM_BOND_TYPE bond_type);
  917. /* Internal functions provided by btm_sec.c
  918. **********************************************
  919. */
  920. BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr);
  921. tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm,
  922. UINT16 handle, CONNECTION_TYPE conn_type,
  923. tBTM_SEC_CALLBACK *p_callback, void *p_ref_data);
  924. tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator,
  925. UINT32 mx_proto_id, UINT32 mx_chan_id,
  926. tBTM_SEC_CALLBACK *p_callback, void *p_ref_data);
  927. void btm_sec_conn_req (UINT8 *bda, UINT8 *dc);
  928. void btm_create_conn_cancel_complete (UINT8 *p);
  929. void btm_read_linq_tx_power_complete (UINT8 *p);
  930. void btm_sec_init (UINT8 sec_mode);
  931. void btm_sec_dev_reset (void);
  932. void btm_sec_abort_access_req (BD_ADDR bd_addr);
  933. void btm_sec_auth_complete (UINT16 handle, UINT8 status);
  934. void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable);
  935. void btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode);
  936. tBTM_STATUS btm_sec_disconnect (UINT16 handle, UINT8 reason);
  937. void btm_sec_disconnected (UINT16 handle, UINT8 reason);
  938. void btm_sec_rmt_name_request_complete (UINT8 *bd_addr, UINT8 *bd_name, UINT8 status);
  939. void btm_sec_rmt_host_support_feat_evt (UINT8 *p);
  940. void btm_io_capabilities_req (UINT8 *p);
  941. void btm_io_capabilities_rsp (UINT8 *p);
  942. void btm_proc_sp_req_evt (tBTM_SP_EVT event, UINT8 *p);
  943. void btm_keypress_notif_evt (UINT8 *p);
  944. void btm_simple_pair_complete (UINT8 *p);
  945. void btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_type);
  946. void btm_sec_link_key_request (UINT8 *p_bda);
  947. void btm_sec_pin_code_request (UINT8 *p_bda);
  948. void btm_sec_update_clock_offset (UINT16 handle, UINT16 clock_offset);
  949. void btm_sec_dev_rec_cback_event (tBTM_SEC_DEV_REC *p_dev_rec, UINT8 res, BOOLEAN is_le_transport);
  950. void btm_sec_set_peer_sec_caps (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec);
  951. #if BLE_INCLUDED == TRUE
  952. void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec);
  953. BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC **p_rec);
  954. BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda);
  955. void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec);
  956. BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda);
  957. BOOLEAN btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseudo_addr);
  958. extern BOOLEAN btm_ble_start_sec_check(BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator,
  959. tBTM_SEC_CALLBACK *p_callback, void *p_ref_data);
  960. #endif /* BLE_INCLUDED */
  961. extern tBTM_SEC_SERV_REC *btm_sec_find_first_serv (CONNECTION_TYPE conn_type, UINT16 psm);
  962. tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda);
  963. #if BTM_OOB_INCLUDED == TRUE
  964. void btm_rem_oob_req (UINT8 *p);
  965. void btm_read_local_oob_complete (UINT8 *p);
  966. #else
  967. #define btm_rem_oob_req(p)
  968. #define btm_read_local_oob_complete(p)
  969. #endif
  970. void btm_acl_resubmit_page (void);
  971. void btm_acl_reset_paging (void);
  972. void btm_acl_paging (BT_HDR *p, BD_ADDR dest);
  973. UINT8 btm_sec_clr_service_by_psm (UINT16 psm);
  974. void btm_sec_clr_temp_auth_service (BD_ADDR bda);
  975. void btm_ble_lock_init(void);
  976. void btm_ble_sem_init(void);
  977. void btm_ble_sem_free(void);
  978. void btm_ble_lock_free(void);
  979. /*
  980. #ifdef __cplusplus
  981. }
  982. #endif
  983. */
  984. #endif