btm_int.h 54 KB

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