btm_int.h 50 KB

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