btm_int.h 51 KB

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