btm_int.h 52 KB

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