btm_int.h 52 KB

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