btm_int.h 53 KB

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