btm_int.h 54 KB

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