btm_acl.c 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2000-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. ** Name: btm_acl.c
  21. **
  22. ** Description: This file contains functions that handle ACL connections.
  23. ** This includes operations such as hold and sniff modes,
  24. ** supported packet types.
  25. **
  26. ** This module contains both internal and external (API)
  27. ** functions. External (API) functions are distinguishable
  28. ** by their names beginning with uppercase BTM.
  29. **
  30. **
  31. ******************************************************************************/
  32. #include <stdlib.h>
  33. #include <string.h>
  34. //#include <stdio.h>
  35. #include <stddef.h>
  36. #include "stack/bt_types.h"
  37. #include "common/bt_target.h"
  38. #include "device/controller.h"
  39. #include "stack/hcimsgs.h"
  40. #include "stack/btu.h"
  41. #include "stack/btm_api.h"
  42. #include "btm_int.h"
  43. #include "l2c_int.h"
  44. #include "stack/hcidefs.h"
  45. //#include "bt_utils.h"
  46. #include "osi/list.h"
  47. static void btm_read_remote_features (UINT16 handle);
  48. static void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number);
  49. static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages);
  50. #define BTM_DEV_REPLY_TIMEOUT 3 /* 3 second timeout waiting for responses */
  51. /*******************************************************************************
  52. **
  53. ** Function btm_acl_init
  54. **
  55. ** Description This function is called at BTM startup to initialize
  56. **
  57. ** Returns void
  58. **
  59. *******************************************************************************/
  60. void btm_acl_init (void)
  61. {
  62. BTM_TRACE_DEBUG ("btm_acl_init\n");
  63. #if 0 /* cleared in btm_init; put back in if called from anywhere else! */
  64. memset (&btm_cb.acl_db, 0, sizeof (btm_cb.acl_db));
  65. memset (btm_cb.btm_scn, 0, BTM_MAX_SCN); /* Initialize the SCN usage to FALSE */
  66. btm_cb.btm_def_link_policy = 0;
  67. btm_cb.p_bl_changed_cb = NULL;
  68. #endif
  69. btm_cb.p_acl_db_list = list_new(osi_free_func);
  70. btm_cb.p_pm_mode_db_list = list_new(osi_free_func);
  71. /* Initialize nonzero defaults */
  72. btm_cb.btm_def_link_super_tout = HCI_DEFAULT_INACT_TOUT;
  73. btm_cb.acl_disc_reason = 0xff ;
  74. }
  75. /*******************************************************************************
  76. **
  77. ** Function btm_bda_to_acl
  78. **
  79. ** Description This function returns the FIRST acl_db entry for the passed BDA.
  80. **
  81. ** Parameters bda : BD address of the remote device
  82. ** transport : Physical transport used for ACL connection (BR/EDR or LE)
  83. **
  84. ** Returns Returns pointer to the ACL DB for the requested BDA if found.
  85. ** NULL if not found.
  86. **
  87. *******************************************************************************/
  88. BOOLEAN btm_get_acl_db(void *p_acl_db_node, void *context)
  89. {
  90. tACL_CONN *p_acl_db =(tACL_CONN *)p_acl_db_node;
  91. BOOLEAN ret = TRUE;
  92. tACL_DB_PARAM *p_param = (tACL_DB_PARAM *)context;
  93. switch(p_param->type) {
  94. case ACL_DB_BDA:
  95. {
  96. UINT8 *p_bda = (UINT8 *)p_param->p_data1;
  97. #if BLE_INCLUDED == TRUE
  98. tBT_TRANSPORT transport = (tBT_TRANSPORT)(*((UINT8 *)p_param->p_data2));
  99. #endif
  100. if (p_acl_db->in_use
  101. && !memcmp(p_bda, p_acl_db->remote_addr, BD_ADDR_LEN)
  102. #if BLE_INCLUDED == TRUE
  103. && transport == p_acl_db->transport
  104. #endif
  105. ) {
  106. ret = FALSE;
  107. }
  108. break;
  109. }
  110. case ACL_DB_HANDLE:
  111. {
  112. UINT16 handle = (UINT16) *((UINT16 *)p_param->p_data1);
  113. if (p_acl_db->in_use && handle == p_acl_db->hci_handle) {
  114. ret = FALSE;
  115. }
  116. break;
  117. }
  118. default:
  119. break;
  120. }
  121. return ret;
  122. }
  123. tACL_CONN *btm_bda_to_acl (BD_ADDR bda, tBT_TRANSPORT transport)
  124. {
  125. tACL_CONN *p_acl_db = NULL;
  126. list_node_t *p_node = NULL;
  127. tACL_DB_PARAM acl_params;
  128. acl_params.type = ACL_DB_BDA;
  129. acl_params.p_data1 = (void *)bda;
  130. acl_params.p_data2 = (void *)&transport;
  131. p_node = list_foreach(btm_cb.p_acl_db_list, btm_get_acl_db, (void *)&acl_params);
  132. if (p_node) {
  133. p_acl_db = list_node(p_node);
  134. }
  135. return (p_acl_db);
  136. }
  137. /*******************************************************************************
  138. **
  139. ** Function btm_handle_to_acl
  140. **
  141. ** Description This function returns the FIRST acl_db entry for the passed hci_handle.
  142. **
  143. ** Returns Returns pointer to the ACL DB for the requested BDA if found.
  144. ** NULL if not found.
  145. **
  146. *******************************************************************************/
  147. tACL_CONN *btm_handle_to_acl (UINT16 hci_handle)
  148. {
  149. tACL_CONN *p_acl_db = NULL;
  150. tACL_DB_PARAM acl_params;
  151. list_node_t *p_node = NULL;
  152. BTM_TRACE_DEBUG ("btm_handle_to_acl_index: %d\n", hci_handle);
  153. acl_params.type = ACL_DB_HANDLE;
  154. acl_params.p_data1 = (void *)&hci_handle;
  155. acl_params.p_data2 = NULL;
  156. p_node = list_foreach(btm_cb.p_acl_db_list, btm_get_acl_db, (void *)&acl_params);
  157. if (p_node) {
  158. p_acl_db = list_node(p_node);
  159. }
  160. return (p_acl_db);
  161. }
  162. #if BLE_PRIVACY_SPT == TRUE
  163. /*******************************************************************************
  164. **
  165. ** Function btm_ble_get_acl_remote_addr
  166. **
  167. ** Description This function reads the active remote address used for the
  168. ** connection.
  169. **
  170. ** Returns success return TRUE, otherwise FALSE.
  171. **
  172. *******************************************************************************/
  173. BOOLEAN btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_addr,
  174. tBLE_ADDR_TYPE *p_addr_type)
  175. {
  176. #if BLE_INCLUDED == TRUE
  177. BOOLEAN st = TRUE;
  178. if (p_dev_rec == NULL) {
  179. BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address\n");
  180. return FALSE;
  181. }
  182. switch (p_dev_rec->ble.active_addr_type) {
  183. case BTM_BLE_ADDR_PSEUDO:
  184. memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
  185. * p_addr_type = p_dev_rec->ble.ble_addr_type;
  186. break;
  187. case BTM_BLE_ADDR_RRA:
  188. memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN);
  189. * p_addr_type = BLE_ADDR_RANDOM;
  190. break;
  191. case BTM_BLE_ADDR_STATIC:
  192. memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN);
  193. * p_addr_type = p_dev_rec->ble.static_addr_type;
  194. break;
  195. default:
  196. BTM_TRACE_ERROR("Unknown active address: %d\n", p_dev_rec->ble.active_addr_type);
  197. st = FALSE;
  198. break;
  199. }
  200. return st;
  201. #else
  202. UNUSED(p_dev_rec);
  203. UNUSED(conn_addr);
  204. UNUSED(p_addr_type);
  205. return FALSE;
  206. #endif
  207. }
  208. #endif
  209. /*******************************************************************************
  210. **
  211. ** Function btm_acl_created
  212. **
  213. ** Description This function is called by L2CAP when an ACL connection
  214. ** is created.
  215. **
  216. ** Returns void
  217. **
  218. *******************************************************************************/
  219. void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, UINT8 bdn[BTM_MAX_REM_BD_NAME_LEN],
  220. UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport)
  221. {
  222. tBTM_SEC_DEV_REC *p_dev_rec = NULL;
  223. tACL_CONN *p;
  224. BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d\n",
  225. hci_handle, link_role, transport);
  226. /* Ensure we don't have duplicates */
  227. p = btm_bda_to_acl(bda, transport);
  228. if (p != (tACL_CONN *)NULL) {
  229. p->hci_handle = hci_handle;
  230. p->link_role = link_role;
  231. #if BLE_INCLUDED == TRUE
  232. p->transport = transport;
  233. #endif
  234. BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
  235. bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
  236. BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy);
  237. return;
  238. }
  239. /* Allocate acl_db entry */
  240. if (list_length(btm_cb.p_acl_db_list) >= MAX_L2CAP_LINKS) {
  241. return;
  242. }
  243. else {
  244. p = (tACL_CONN *)osi_malloc(sizeof(tACL_CONN));
  245. if (p && list_append(btm_cb.p_acl_db_list, p)) {
  246. memset(p, 0, sizeof(tACL_CONN));
  247. p->in_use = TRUE;
  248. p->hci_handle = hci_handle;
  249. p->link_role = link_role;
  250. p->link_up_issued = FALSE;
  251. memcpy (p->remote_addr, bda, BD_ADDR_LEN);
  252. /* Set the default version of the peer device to version4.0 before exchange the version with it.
  253. If the peer device act as a master and don't exchange the version with us, then it can only use the
  254. legacy connect instead of secure connection in the pairing step. */
  255. p->lmp_version = HCI_PROTO_VERSION_4_0;
  256. #if BLE_INCLUDED == TRUE
  257. p->transport = transport;
  258. #if BLE_PRIVACY_SPT == TRUE
  259. if (transport == BT_TRANSPORT_LE) {
  260. btm_ble_refresh_local_resolvable_private_addr(bda,
  261. btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr);
  262. }
  263. #else
  264. p->conn_addr_type = BLE_ADDR_PUBLIC;
  265. memcpy(p->conn_addr, &controller_get_interface()->get_address()->address, BD_ADDR_LEN);
  266. BTM_TRACE_DEBUG ("conn_addr: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
  267. p->conn_addr[0], p->conn_addr[1], p->conn_addr[2], p->conn_addr[3], p->conn_addr[4], p->conn_addr[5]);
  268. #endif
  269. #endif
  270. p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
  271. p->p_pm_mode_db = btm_pm_sm_alloc();
  272. #if BTM_PM_DEBUG == TRUE
  273. BTM_TRACE_DEBUG( "btm_pm_sm_alloc handle:%d st:%d", hci_handle, p->p_pm_mode_db->state);
  274. #endif // BTM_PM_DEBUG
  275. #if (CLASSIC_BT_INCLUDED == TRUE)
  276. btm_sec_update_legacy_auth_state(p, BTM_ACL_LEGACY_AUTH_NONE);
  277. #endif
  278. if (dc) {
  279. memcpy (p->remote_dc, dc, DEV_CLASS_LEN);
  280. }
  281. if (bdn) {
  282. memcpy (p->remote_name, bdn, BTM_MAX_REM_BD_NAME_LEN);
  283. }
  284. /* if BR/EDR do something more */
  285. if (transport == BT_TRANSPORT_BR_EDR) {
  286. btsnd_hcic_read_rmt_clk_offset (p->hci_handle);
  287. btsnd_hcic_rmt_ver_req (p->hci_handle);
  288. }
  289. p_dev_rec = btm_find_dev_by_handle (hci_handle);
  290. #if (BLE_INCLUDED == TRUE)
  291. if (p_dev_rec ) {
  292. BTM_TRACE_DEBUG ("device_type=0x%x\n", p_dev_rec->device_type);
  293. }
  294. #endif
  295. if (p_dev_rec && !(transport == BT_TRANSPORT_LE)) {
  296. if (!p_dev_rec->remote_secure_connection_previous_state) {
  297. /* If remote features already known, copy them and continue connection setup */
  298. if ((p_dev_rec->num_read_pages) &&
  299. (p_dev_rec->num_read_pages <= (HCI_EXT_FEATURES_PAGE_MAX + 1))) {
  300. memcpy (p->peer_lmp_features, p_dev_rec->features,
  301. (HCI_FEATURE_BYTES_PER_PAGE * p_dev_rec->num_read_pages));
  302. p->num_read_pages = p_dev_rec->num_read_pages;
  303. #if (CLASSIC_BT_INCLUDED == TRUE)
  304. const UINT8 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
  305. #endif ///CLASSIC_BT_INCLUDED == TRUE
  306. /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */
  307. #if (SMP_INCLUDED == TRUE)
  308. btm_sec_set_peer_sec_caps(p, p_dev_rec);
  309. #endif ///SMP_INCLUDED == TRUE
  310. #if (CLASSIC_BT_INCLUDED == TRUE)
  311. BTM_TRACE_API("%s: pend:%d\n", __FUNCTION__, req_pend);
  312. if (req_pend) {
  313. /* Request for remaining Security Features (if any) */
  314. l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
  315. }
  316. #endif ///CLASSIC_BT_INCLUDED == TRUE
  317. btm_establish_continue (p);
  318. return;
  319. }
  320. } else {
  321. /* If remote features indicated secure connection (SC) mode, check the remote feautres again*/
  322. /* this is to prevent from BIAS attack where attacker can downgrade SC mode*/
  323. btm_read_remote_features (p->hci_handle);
  324. }
  325. }
  326. #if (BLE_INCLUDED == TRUE)
  327. /* If here, features are not known yet */
  328. if (p_dev_rec && transport == BT_TRANSPORT_LE) {
  329. #if BLE_PRIVACY_SPT == TRUE
  330. btm_ble_get_acl_remote_addr (p_dev_rec, p->active_remote_addr,
  331. &p->active_remote_addr_type);
  332. #endif
  333. if (link_role == HCI_ROLE_MASTER) {
  334. btsnd_hcic_ble_read_remote_feat(p->hci_handle);
  335. } else if (HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(controller_get_interface()->get_features_ble()->as_array)
  336. && link_role == HCI_ROLE_SLAVE) {
  337. btsnd_hcic_rmt_ver_req (p->hci_handle);
  338. } else {
  339. btm_establish_continue(p);
  340. }
  341. } else
  342. #endif
  343. {
  344. btm_read_remote_features (p->hci_handle);
  345. }
  346. /* read page 1 - on rmt feature event for buffer reasons */
  347. return;
  348. }
  349. }
  350. }
  351. /*******************************************************************************
  352. **
  353. ** Function btm_acl_report_role_change
  354. **
  355. ** Description This function is called when the local device is deemed
  356. ** to be down. It notifies L2CAP of the failure.
  357. **
  358. ** Returns void
  359. **
  360. *******************************************************************************/
  361. void btm_acl_report_role_change (UINT8 hci_status, BD_ADDR bda)
  362. {
  363. tBTM_ROLE_SWITCH_CMPL ref_data;
  364. BTM_TRACE_DEBUG ("btm_acl_report_role_change\n");
  365. if (btm_cb.devcb.p_switch_role_cb
  366. && (bda && (0 == memcmp(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, bda, BD_ADDR_LEN)))) {
  367. memcpy (&ref_data, &btm_cb.devcb.switch_role_ref_data, sizeof(tBTM_ROLE_SWITCH_CMPL));
  368. ref_data.hci_status = hci_status;
  369. (*btm_cb.devcb.p_switch_role_cb)(&ref_data);
  370. memset (&btm_cb.devcb.switch_role_ref_data, 0, sizeof(tBTM_ROLE_SWITCH_CMPL));
  371. btm_cb.devcb.p_switch_role_cb = NULL;
  372. }
  373. }
  374. /*******************************************************************************
  375. **
  376. ** Function btm_acl_removed
  377. **
  378. ** Description This function is called by L2CAP when an ACL connection
  379. ** is removed. Since only L2CAP creates ACL links, we use
  380. ** the L2CAP link index as our index into the control blocks.
  381. **
  382. ** Returns void
  383. **
  384. *******************************************************************************/
  385. void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport)
  386. {
  387. tACL_CONN *p;
  388. tBTM_BL_EVENT_DATA evt_data;
  389. #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
  390. tBTM_SEC_DEV_REC *p_dev_rec = NULL;
  391. #endif
  392. BTM_TRACE_DEBUG ("btm_acl_removed\n");
  393. p = btm_bda_to_acl(bda, transport);
  394. if (p != (tACL_CONN *)NULL) {
  395. p->in_use = FALSE;
  396. /* if the disconnected channel has a pending role switch, clear it now */
  397. btm_acl_report_role_change(HCI_ERR_NO_CONNECTION, bda);
  398. /* Only notify if link up has had a chance to be issued */
  399. if (p->link_up_issued) {
  400. p->link_up_issued = FALSE;
  401. /* If anyone cares, tell him database changed */
  402. if (btm_cb.p_bl_changed_cb) {
  403. evt_data.event = BTM_BL_DISCN_EVT;
  404. evt_data.discn.p_bda = bda;
  405. #if BLE_INCLUDED == TRUE
  406. evt_data.discn.handle = p->hci_handle;
  407. evt_data.discn.transport = p->transport;
  408. #endif
  409. (*btm_cb.p_bl_changed_cb)(&evt_data);
  410. }
  411. btm_acl_update_busy_level (BTM_BLI_ACL_DOWN_EVT);
  412. }
  413. #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
  414. BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d\n",
  415. p->hci_handle,
  416. p->transport,
  417. btm_cb.ble_ctr_cb.inq_var.connectable_mode,
  418. p->link_role);
  419. p_dev_rec = btm_find_dev(bda);
  420. if ( p_dev_rec) {
  421. BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x\n", p_dev_rec->sec_flags);
  422. if (p->transport == BT_TRANSPORT_LE) {
  423. BTM_TRACE_DEBUG("LE link down\n");
  424. p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
  425. if ( (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0) {
  426. BTM_TRACE_DEBUG("Not Bonded\n");
  427. p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED);
  428. } else {
  429. BTM_TRACE_DEBUG("Bonded\n");
  430. }
  431. } else {
  432. BTM_TRACE_DEBUG("Bletooth link down\n");
  433. p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED
  434. | BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
  435. }
  436. BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x\n", p_dev_rec->sec_flags);
  437. } else {
  438. BTM_TRACE_ERROR("Device not found\n");
  439. }
  440. #endif
  441. list_remove(btm_cb.p_pm_mode_db_list, p->p_pm_mode_db);
  442. /* Clear the ACL connection data */
  443. memset(p, 0, sizeof(tACL_CONN));
  444. if (list_remove(btm_cb.p_acl_db_list, p)) {
  445. p = NULL;
  446. }
  447. }
  448. }
  449. /*******************************************************************************
  450. **
  451. ** Function btm_acl_device_down
  452. **
  453. ** Description This function is called when the local device is deemed
  454. ** to be down. It notifies L2CAP of the failure.
  455. **
  456. ** Returns void
  457. **
  458. *******************************************************************************/
  459. void btm_acl_device_down (void)
  460. {
  461. tACL_CONN *p = NULL;
  462. BTM_TRACE_DEBUG ("btm_acl_device_down\n");
  463. for (list_node_t *p_node = list_begin(btm_cb.p_acl_db_list); p_node; p_node = list_next(p_node)) {
  464. p = list_node(p_node);
  465. if (p && p->in_use) {
  466. BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE \n", p->hci_handle );
  467. l2c_link_hci_disc_comp (p->hci_handle, HCI_ERR_HW_FAILURE);
  468. }
  469. }
  470. }
  471. /*******************************************************************************
  472. **
  473. ** Function btm_acl_update_busy_level
  474. **
  475. ** Description This function is called to update the busy level of the system
  476. ** .
  477. **
  478. ** Returns void
  479. **
  480. *******************************************************************************/
  481. void btm_acl_update_busy_level (tBTM_BLI_EVENT event)
  482. {
  483. tBTM_BL_UPDATE_DATA evt;
  484. UINT8 busy_level;
  485. BTM_TRACE_DEBUG ("btm_acl_update_busy_level\n");
  486. BOOLEAN old_inquiry_state = btm_cb.is_inquiry;
  487. switch (event) {
  488. case BTM_BLI_ACL_UP_EVT:
  489. BTM_TRACE_DEBUG ("BTM_BLI_ACL_UP_EVT\n");
  490. break;
  491. case BTM_BLI_ACL_DOWN_EVT:
  492. BTM_TRACE_DEBUG ("BTM_BLI_ACL_DOWN_EVT\n");
  493. break;
  494. case BTM_BLI_PAGE_EVT:
  495. BTM_TRACE_DEBUG ("BTM_BLI_PAGE_EVT\n");
  496. btm_cb.is_paging = TRUE;
  497. evt.busy_level_flags = BTM_BL_PAGING_STARTED;
  498. break;
  499. case BTM_BLI_PAGE_DONE_EVT:
  500. BTM_TRACE_DEBUG ("BTM_BLI_PAGE_DONE_EVT\n");
  501. btm_cb.is_paging = FALSE;
  502. evt.busy_level_flags = BTM_BL_PAGING_COMPLETE;
  503. break;
  504. case BTM_BLI_INQ_EVT:
  505. BTM_TRACE_DEBUG ("BTM_BLI_INQ_EVT\n");
  506. btm_cb.is_inquiry = TRUE;
  507. evt.busy_level_flags = BTM_BL_INQUIRY_STARTED;
  508. break;
  509. case BTM_BLI_INQ_CANCEL_EVT:
  510. BTM_TRACE_DEBUG ("BTM_BLI_INQ_CANCEL_EVT\n");
  511. btm_cb.is_inquiry = FALSE;
  512. evt.busy_level_flags = BTM_BL_INQUIRY_CANCELLED;
  513. break;
  514. case BTM_BLI_INQ_DONE_EVT:
  515. BTM_TRACE_DEBUG ("BTM_BLI_INQ_DONE_EVT\n");
  516. btm_cb.is_inquiry = FALSE;
  517. evt.busy_level_flags = BTM_BL_INQUIRY_COMPLETE;
  518. break;
  519. }
  520. if (btm_cb.is_paging || btm_cb.is_inquiry) {
  521. busy_level = 10;
  522. } else {
  523. busy_level = BTM_GetNumAclLinks();
  524. }
  525. if ((busy_level != btm_cb.busy_level) || (old_inquiry_state != btm_cb.is_inquiry)) {
  526. evt.event = BTM_BL_UPDATE_EVT;
  527. evt.busy_level = busy_level;
  528. btm_cb.busy_level = busy_level;
  529. if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_UPDATE_MASK)) {
  530. (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
  531. }
  532. }
  533. }
  534. /*******************************************************************************
  535. **
  536. ** Function BTM_GetRole
  537. **
  538. ** Description This function is called to get the role of the local device
  539. ** for the ACL connection with the specified remote device
  540. **
  541. ** Returns BTM_SUCCESS if connection exists.
  542. ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
  543. **
  544. *******************************************************************************/
  545. tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, UINT8 *p_role)
  546. {
  547. tACL_CONN *p;
  548. BTM_TRACE_DEBUG ("BTM_GetRole\n");
  549. if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) {
  550. *p_role = BTM_ROLE_UNDEFINED;
  551. return (BTM_UNKNOWN_ADDR);
  552. }
  553. /* Get the current role */
  554. *p_role = p->link_role;
  555. return (BTM_SUCCESS);
  556. }
  557. /*******************************************************************************
  558. **
  559. ** Function BTM_SwitchRole
  560. **
  561. ** Description This function is called to switch role between master and
  562. ** slave. If role is already set it will do nothing. If the
  563. ** command was initiated, the callback function is called upon
  564. ** completion.
  565. **
  566. ** Returns BTM_SUCCESS if already in specified role.
  567. ** BTM_CMD_STARTED if command issued to controller.
  568. ** BTM_NO_RESOURCES if couldn't allocate memory to issue command
  569. ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
  570. ** BTM_MODE_UNSUPPORTED if local device does not support role switching
  571. ** BTM_BUSY if the previous command is not completed
  572. **
  573. *******************************************************************************/
  574. tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, UINT8 new_role, tBTM_CMPL_CB *p_cb)
  575. {
  576. tACL_CONN *p;
  577. tBTM_SEC_DEV_REC *p_dev_rec = NULL;
  578. #if BTM_SCO_INCLUDED == TRUE
  579. BOOLEAN is_sco_active;
  580. #endif
  581. tBTM_STATUS status;
  582. tBTM_PM_MODE pwr_mode;
  583. tBTM_PM_PWR_MD settings;
  584. #if (BT_USE_TRACES == TRUE)
  585. BD_ADDR_PTR p_bda;
  586. #endif
  587. BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x\n",
  588. remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2],
  589. remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]);
  590. /* Make sure the local device supports switching */
  591. if (!controller_get_interface()->supports_master_slave_role_switch()) {
  592. return (BTM_MODE_UNSUPPORTED);
  593. }
  594. if (btm_cb.devcb.p_switch_role_cb && p_cb) {
  595. #if (BT_USE_TRACES == TRUE)
  596. p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
  597. BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x\n",
  598. p_bda[0], p_bda[1], p_bda[2],
  599. p_bda[3], p_bda[4], p_bda[5]);
  600. #endif
  601. return (BTM_BUSY);
  602. }
  603. if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) {
  604. return (BTM_UNKNOWN_ADDR);
  605. }
  606. /* Finished if already in desired role */
  607. if (p->link_role == new_role) {
  608. return (BTM_SUCCESS);
  609. }
  610. #if BTM_SCO_INCLUDED == TRUE
  611. /* Check if there is any SCO Active on this BD Address */
  612. is_sco_active = btm_is_sco_active_by_bdaddr(remote_bd_addr);
  613. if (is_sco_active == TRUE) {
  614. return (BTM_NO_RESOURCES);
  615. }
  616. #endif
  617. /* Ignore role switch request if the previous request was not completed */
  618. if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE) {
  619. BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d\n",
  620. p->switch_role_state);
  621. return (BTM_BUSY);
  622. }
  623. if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS) {
  624. return (status);
  625. }
  626. /* Wake up the link if in sniff or park before attempting switch */
  627. if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF) {
  628. memset( (void *)&settings, 0, sizeof(settings));
  629. settings.mode = BTM_PM_MD_ACTIVE;
  630. status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings);
  631. if (status != BTM_CMD_STARTED) {
  632. return (BTM_WRONG_MODE);
  633. }
  634. p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
  635. }
  636. /* some devices do not support switch while encryption is on */
  637. else {
  638. p_dev_rec = btm_find_dev (remote_bd_addr);
  639. if ((p_dev_rec != NULL)
  640. && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
  641. && !BTM_EPR_AVAILABLE(p)) {
  642. /* bypass turning off encryption if change link key is already doing it */
  643. if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF) {
  644. if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE)) {
  645. return (BTM_NO_RESOURCES);
  646. } else {
  647. p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
  648. }
  649. }
  650. p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
  651. } else {
  652. if (!btsnd_hcic_switch_role (remote_bd_addr, new_role)) {
  653. return (BTM_NO_RESOURCES);
  654. }
  655. p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
  656. #if BTM_DISC_DURING_RS == TRUE
  657. if (p_dev_rec) {
  658. p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
  659. }
  660. #endif
  661. }
  662. }
  663. /* Initialize return structure in case request fails */
  664. if (p_cb) {
  665. memcpy (btm_cb.devcb.switch_role_ref_data.remote_bd_addr, remote_bd_addr,
  666. BD_ADDR_LEN);
  667. btm_cb.devcb.switch_role_ref_data.role = new_role;
  668. /* initialized to an error code */
  669. btm_cb.devcb.switch_role_ref_data.hci_status = HCI_ERR_UNSUPPORTED_VALUE;
  670. btm_cb.devcb.p_switch_role_cb = p_cb;
  671. }
  672. return (BTM_CMD_STARTED);
  673. }
  674. /*******************************************************************************
  675. **
  676. ** Function btm_acl_encrypt_change
  677. **
  678. ** Description This function is when encryption of the connection is
  679. ** completed by the LM. Checks to see if a role switch or
  680. ** change of link key was active and initiates or continues
  681. ** process if needed.
  682. **
  683. ** Returns void
  684. **
  685. *******************************************************************************/
  686. void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
  687. {
  688. tACL_CONN *p;
  689. tBTM_SEC_DEV_REC *p_dev_rec;
  690. tBTM_BL_ROLE_CHG_DATA evt;
  691. BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d\n",
  692. handle, status, encr_enable);
  693. p = btm_handle_to_acl(handle);
  694. if (p == NULL) {
  695. return;
  696. }
  697. /* Process Role Switch if active */
  698. if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF) {
  699. /* if encryption turn off failed we still will try to switch role */
  700. if (encr_enable) {
  701. p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
  702. p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
  703. } else {
  704. p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING;
  705. p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC;
  706. }
  707. if (!btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role)) {
  708. p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
  709. p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
  710. btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
  711. }
  712. #if BTM_DISC_DURING_RS == TRUE
  713. else {
  714. if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL) {
  715. p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
  716. }
  717. }
  718. #endif
  719. }
  720. /* Finished enabling Encryption after role switch */
  721. else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON) {
  722. p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
  723. p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
  724. btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
  725. /* if role change event is registered, report it now */
  726. if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) {
  727. evt.event = BTM_BL_ROLE_CHG_EVT;
  728. evt.new_role = btm_cb.devcb.switch_role_ref_data.role;
  729. evt.p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
  730. evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status;
  731. (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
  732. BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d\n",
  733. evt.new_role, evt.hci_status, p->switch_role_state);
  734. }
  735. #if BTM_DISC_DURING_RS == TRUE
  736. /* If a disconnect is pending, issue it now that role switch has completed */
  737. if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL) {
  738. if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) {
  739. BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!\n");
  740. btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
  741. }
  742. BTM_TRACE_WARNING("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d\n",
  743. (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
  744. p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
  745. }
  746. #endif
  747. }
  748. #if (CLASSIC_BT_INCLUDED == TRUE)
  749. /* If authentication is done through legacy authentication and esp32 has
  750. * not authenticated peer deivce yet, do not proceed for encrytion and
  751. * first authenticate it. */
  752. else if ((BTM_BothEndsSupportSecureConnections(p->remote_addr) == 0) &&
  753. ((p->legacy_auth_state & BTM_ACL_LEGACY_AUTH_SELF) == 0)) {
  754. if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL) {
  755. if (btm_sec_legacy_authentication_mutual(p_dev_rec)) {
  756. btm_sec_update_legacy_auth_state(btm_bda_to_acl(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR), BTM_ACL_LEGACY_AUTH_SELF);
  757. } else {
  758. BTM_TRACE_ERROR("%s failed, Resources not available for Authentication procedure", __FUNCTION__);
  759. }
  760. }
  761. }
  762. #endif
  763. }
  764. /*******************************************************************************
  765. **
  766. ** Function BTM_SetLinkPolicy
  767. **
  768. ** Description Create and send HCI "Write Policy Set" command
  769. **
  770. ** Returns status of the operation
  771. **
  772. *******************************************************************************/
  773. tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, UINT16 *settings)
  774. {
  775. tACL_CONN *p;
  776. UINT8 *localFeatures = BTM_ReadLocalFeatures();
  777. BTM_TRACE_DEBUG ("BTM_SetLinkPolicy\n");
  778. /* BTM_TRACE_API ("BTM_SetLinkPolicy: requested settings: 0x%04x", *settings ); */
  779. /* First, check if hold mode is supported */
  780. if (*settings != HCI_DISABLE_ALL_LM_MODES) {
  781. if ( (*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)) ) {
  782. *settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH);
  783. BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)\n", *settings );
  784. }
  785. if ( (*settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)) ) {
  786. *settings &= (~HCI_ENABLE_HOLD_MODE);
  787. BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)\n", *settings );
  788. }
  789. if ( (*settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)) ) {
  790. *settings &= (~HCI_ENABLE_SNIFF_MODE);
  791. BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)\n", *settings );
  792. }
  793. if ( (*settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)) ) {
  794. *settings &= (~HCI_ENABLE_PARK_MODE);
  795. BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)\n", *settings );
  796. }
  797. }
  798. if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL) {
  799. return (btsnd_hcic_write_policy_set (p->hci_handle, *settings) ? BTM_CMD_STARTED : BTM_NO_RESOURCES);
  800. }
  801. /* If here, no BD Addr found */
  802. return (BTM_UNKNOWN_ADDR);
  803. }
  804. /*******************************************************************************
  805. **
  806. ** Function BTM_SetDefaultLinkPolicy
  807. **
  808. ** Description Set the default value for HCI "Write Policy Set" command
  809. ** to use when an ACL link is created.
  810. **
  811. ** Returns void
  812. **
  813. *******************************************************************************/
  814. void BTM_SetDefaultLinkPolicy (UINT16 settings)
  815. {
  816. UINT8 *localFeatures = BTM_ReadLocalFeatures();
  817. BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x\n", settings);
  818. if ((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures))) {
  819. settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
  820. BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)\n", settings);
  821. }
  822. if ((settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures))) {
  823. settings &= ~HCI_ENABLE_HOLD_MODE;
  824. BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)\n", settings);
  825. }
  826. if ((settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures))) {
  827. settings &= ~HCI_ENABLE_SNIFF_MODE;
  828. BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)\n", settings);
  829. }
  830. if ((settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures))) {
  831. settings &= ~HCI_ENABLE_PARK_MODE;
  832. BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)\n", settings);
  833. }
  834. BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x\n", settings);
  835. btm_cb.btm_def_link_policy = settings;
  836. /* Set the default Link Policy of the controller */
  837. btsnd_hcic_write_def_policy_set(settings);
  838. }
  839. /*******************************************************************************
  840. **
  841. ** Function btm_read_remote_version_complete
  842. **
  843. ** Description This function is called when the command complete message
  844. ** is received from the HCI for the remote version info.
  845. **
  846. ** Returns void
  847. **
  848. *******************************************************************************/
  849. void btm_read_remote_version_complete (UINT8 *p)
  850. {
  851. tACL_CONN *p_acl_cb = NULL;
  852. UINT8 status;
  853. UINT16 handle;
  854. BTM_TRACE_DEBUG ("btm_read_remote_version_complete\n");
  855. STREAM_TO_UINT8 (status, p);
  856. STREAM_TO_UINT16 (handle, p);
  857. /* Look up the connection by handle and copy features */
  858. p_acl_cb = btm_handle_to_acl(handle);
  859. if (p_acl_cb) {
  860. if (status == HCI_SUCCESS) {
  861. STREAM_TO_UINT8 (p_acl_cb->lmp_version, p);
  862. STREAM_TO_UINT16 (p_acl_cb->manufacturer, p);
  863. STREAM_TO_UINT16 (p_acl_cb->lmp_subversion, p);
  864. }
  865. #if BLE_INCLUDED == TRUE
  866. if (p_acl_cb->transport == BT_TRANSPORT_LE) {
  867. if(p_acl_cb->link_role == HCI_ROLE_MASTER) {
  868. if (HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl_cb->peer_le_features)) {
  869. uint16_t data_length = controller_get_interface()->get_ble_default_data_packet_length();
  870. uint16_t data_txtime = controller_get_interface()->get_ble_default_data_packet_txtime();
  871. if (data_length != p_acl_cb->data_length_params.tx_len) {
  872. p_acl_cb->data_len_updating = true;
  873. btsnd_hcic_ble_set_data_length(p_acl_cb->hci_handle, data_length, data_txtime);
  874. }
  875. }
  876. l2cble_notify_le_connection (p_acl_cb->remote_addr);
  877. } else {
  878. //slave role, read remote feature
  879. btsnd_hcic_ble_read_remote_feat(p_acl_cb->hci_handle);
  880. }
  881. }
  882. #endif
  883. }
  884. }
  885. /*******************************************************************************
  886. **
  887. ** Function btm_process_remote_ext_features
  888. **
  889. ** Description Local function called to process all extended features pages
  890. ** read from a remote device.
  891. **
  892. ** Returns void
  893. **
  894. *******************************************************************************/
  895. void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages)
  896. {
  897. UINT16 handle = p_acl_cb->hci_handle;
  898. tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle);
  899. UINT8 page_idx;
  900. BTM_TRACE_DEBUG ("btm_process_remote_ext_features\n");
  901. /* Make sure we have the record to save remote features information */
  902. if (p_dev_rec == NULL) {
  903. /* Get a new device; might be doing dedicated bonding */
  904. p_dev_rec = btm_find_or_alloc_dev (p_acl_cb->remote_addr);
  905. }
  906. p_acl_cb->num_read_pages = num_read_pages;
  907. p_dev_rec->num_read_pages = num_read_pages;
  908. /* Move the pages to placeholder */
  909. for (page_idx = 0; page_idx < num_read_pages; page_idx++) {
  910. if (page_idx > HCI_EXT_FEATURES_PAGE_MAX) {
  911. BTM_TRACE_ERROR("%s: page=%d unexpected\n", __FUNCTION__, page_idx);
  912. break;
  913. }
  914. memcpy (p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx],
  915. HCI_FEATURE_BYTES_PER_PAGE);
  916. }
  917. const UINT8 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
  918. #if (SMP_INCLUDED == TRUE)
  919. /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */
  920. btm_sec_set_peer_sec_caps(p_acl_cb, p_dev_rec);
  921. #endif ///SMP_INCLUDED == TRUE
  922. BTM_TRACE_API("%s: pend:%d\n", __FUNCTION__, req_pend);
  923. if (req_pend) {
  924. #if (CLASSIC_BT_INCLUDED == TRUE)
  925. /* Request for remaining Security Features (if any) */
  926. l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
  927. #endif ///CLASSIC_BT_INCLUDED == TRUE
  928. }
  929. }
  930. /*******************************************************************************
  931. **
  932. ** Function btm_read_remote_features
  933. **
  934. ** Description Local function called to send a read remote supported features/
  935. ** remote extended features page[0].
  936. **
  937. ** Returns void
  938. **
  939. *******************************************************************************/
  940. void btm_read_remote_features (UINT16 handle)
  941. {
  942. tACL_CONN *p_acl_cb;
  943. BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d\n", handle);
  944. p_acl_cb = btm_handle_to_acl(handle);
  945. if (p_acl_cb == NULL) {
  946. BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid\n", handle);
  947. return;
  948. }
  949. p_acl_cb->num_read_pages = 0;
  950. memset (p_acl_cb->peer_lmp_features, 0, sizeof(p_acl_cb->peer_lmp_features));
  951. /* first send read remote supported features HCI command */
  952. /* because we don't know whether the remote support extended feature command */
  953. btsnd_hcic_rmt_features_req (handle);
  954. }
  955. /*******************************************************************************
  956. **
  957. ** Function btm_read_remote_ext_features
  958. **
  959. ** Description Local function called to send a read remote extended features
  960. **
  961. ** Returns void
  962. **
  963. *******************************************************************************/
  964. void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number)
  965. {
  966. BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d\n", handle, page_number);
  967. btsnd_hcic_rmt_ext_features(handle, page_number);
  968. }
  969. /*******************************************************************************
  970. **
  971. ** Function btm_read_remote_features_complete
  972. **
  973. ** Description This function is called when the remote supported features
  974. ** complete event is received from the HCI.
  975. **
  976. ** Returns void
  977. **
  978. *******************************************************************************/
  979. void btm_read_remote_features_complete (UINT8 *p)
  980. {
  981. tACL_CONN *p_acl_cb;
  982. UINT8 status;
  983. UINT16 handle;
  984. BTM_TRACE_DEBUG ("btm_read_remote_features_complete\n");
  985. STREAM_TO_UINT8 (status, p);
  986. if (status != HCI_SUCCESS) {
  987. BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)\n", status);
  988. return;
  989. }
  990. STREAM_TO_UINT16 (handle, p);
  991. p_acl_cb = btm_handle_to_acl(handle);
  992. if (p_acl_cb == NULL) {
  993. BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid\n", handle);
  994. return;
  995. }
  996. /* Copy the received features page */
  997. STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], p,
  998. HCI_FEATURE_BYTES_PER_PAGE);
  999. if ((HCI_LMP_EXTENDED_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) &&
  1000. (controller_get_interface()->supports_reading_remote_extended_features())) {
  1001. /* if the remote controller has extended features and local controller supports
  1002. ** HCI_Read_Remote_Extended_Features command then start reading these feature starting
  1003. ** with extended features page 1 */
  1004. BTM_TRACE_DEBUG ("Start reading remote extended features\n");
  1005. btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1);
  1006. return;
  1007. }
  1008. /* Remote controller has no extended features. Process remote controller supported features
  1009. (features page HCI_EXT_FEATURES_PAGE_0). */
  1010. btm_process_remote_ext_features (p_acl_cb, 1);
  1011. /* Continue with HCI connection establishment */
  1012. btm_establish_continue (p_acl_cb);
  1013. }
  1014. /*******************************************************************************
  1015. **
  1016. ** Function btm_read_remote_ext_features_complete
  1017. **
  1018. ** Description This function is called when the remote extended features
  1019. ** complete event is received from the HCI.
  1020. **
  1021. ** Returns void
  1022. **
  1023. *******************************************************************************/
  1024. void btm_read_remote_ext_features_complete (UINT8 *p)
  1025. {
  1026. tACL_CONN *p_acl_cb;
  1027. UINT8 page_num, max_page;
  1028. UINT16 handle;
  1029. BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete\n");
  1030. ++p;
  1031. STREAM_TO_UINT16 (handle, p);
  1032. STREAM_TO_UINT8 (page_num, p);
  1033. STREAM_TO_UINT8 (max_page, p);
  1034. /* Validate parameters */
  1035. p_acl_cb = btm_handle_to_acl(handle);
  1036. if (p_acl_cb == NULL) {
  1037. BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid\n", handle);
  1038. return;
  1039. }
  1040. if (max_page > HCI_EXT_FEATURES_PAGE_MAX) {
  1041. BTM_TRACE_ERROR("btm_read_remote_ext_features_complete page=%d unknown", max_page);
  1042. }
  1043. /* Copy the received features page */
  1044. STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[page_num], p, HCI_FEATURE_BYTES_PER_PAGE);
  1045. /* If there is the next remote features page and
  1046. * we have space to keep this page data - read this page */
  1047. if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX)) {
  1048. page_num++;
  1049. BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)\n", page_num);
  1050. btm_read_remote_ext_features (handle, page_num);
  1051. return;
  1052. }
  1053. /* Reading of remote feature pages is complete */
  1054. BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)\n", page_num);
  1055. /* Process the pages */
  1056. btm_process_remote_ext_features (p_acl_cb, (UINT8) (page_num + 1));
  1057. /* Continue with HCI connection establishment */
  1058. btm_establish_continue (p_acl_cb);
  1059. }
  1060. /*******************************************************************************
  1061. **
  1062. ** Function btm_read_remote_ext_features_failed
  1063. **
  1064. ** Description This function is called when the remote extended features
  1065. ** complete event returns a failed status.
  1066. **
  1067. ** Returns void
  1068. **
  1069. *******************************************************************************/
  1070. void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle)
  1071. {
  1072. tACL_CONN *p_acl_cb;
  1073. BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d\n",
  1074. status, handle);
  1075. p_acl_cb = btm_handle_to_acl(handle);
  1076. if (p_acl_cb == NULL) {
  1077. BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid\n", handle);
  1078. return;
  1079. }
  1080. /* Process supported features only */
  1081. btm_process_remote_ext_features (p_acl_cb, 1);
  1082. /* Continue HCI connection establishment */
  1083. btm_establish_continue (p_acl_cb);
  1084. }
  1085. /*******************************************************************************
  1086. **
  1087. ** Function btm_establish_continue
  1088. **
  1089. ** Description This function is called when the command complete message
  1090. ** is received from the HCI for the read local link policy request.
  1091. **
  1092. ** Returns void
  1093. **
  1094. *******************************************************************************/
  1095. void btm_establish_continue (tACL_CONN *p_acl_cb)
  1096. {
  1097. tBTM_BL_EVENT_DATA evt_data;
  1098. BTM_TRACE_DEBUG ("btm_establish_continue\n");
  1099. #if (!defined(BTM_BYPASS_EXTRA_ACL_SETUP) || BTM_BYPASS_EXTRA_ACL_SETUP == FALSE)
  1100. #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
  1101. if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR)
  1102. #endif
  1103. {
  1104. /* For now there are a some devices that do not like sending */
  1105. /* commands events and data at the same time. */
  1106. /* Set the packet types to the default allowed by the device */
  1107. btm_set_packet_types (p_acl_cb, btm_cb.btm_acl_pkt_types_supported);
  1108. if (btm_cb.btm_def_link_policy) {
  1109. BTM_SetLinkPolicy (p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy);
  1110. }
  1111. }
  1112. #endif
  1113. p_acl_cb->link_up_issued = TRUE;
  1114. /* If anyone cares, tell him database changed */
  1115. if (btm_cb.p_bl_changed_cb) {
  1116. evt_data.event = BTM_BL_CONN_EVT;
  1117. evt_data.conn.p_bda = p_acl_cb->remote_addr;
  1118. evt_data.conn.p_bdn = p_acl_cb->remote_name;
  1119. evt_data.conn.p_dc = p_acl_cb->remote_dc;
  1120. evt_data.conn.p_features = p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0];
  1121. evt_data.conn.sc_downgrade = p_acl_cb->sc_downgrade;
  1122. #if BLE_INCLUDED == TRUE
  1123. evt_data.conn.handle = p_acl_cb->hci_handle;
  1124. evt_data.conn.transport = p_acl_cb->transport;
  1125. #endif
  1126. (*btm_cb.p_bl_changed_cb)(&evt_data);
  1127. }
  1128. btm_acl_update_busy_level (BTM_BLI_ACL_UP_EVT);
  1129. }
  1130. /*******************************************************************************
  1131. **
  1132. ** Function BTM_SetDefaultLinkSuperTout
  1133. **
  1134. ** Description Set the default value for HCI "Write Link Supervision Timeout"
  1135. ** command to use when an ACL link is created.
  1136. **
  1137. ** Returns void
  1138. **
  1139. *******************************************************************************/
  1140. void BTM_SetDefaultLinkSuperTout (UINT16 timeout)
  1141. {
  1142. BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout\n");
  1143. btm_cb.btm_def_link_super_tout = timeout;
  1144. }
  1145. /*******************************************************************************
  1146. **
  1147. ** Function BTM_GetLinkSuperTout
  1148. **
  1149. ** Description Read the link supervision timeout value of the connection
  1150. **
  1151. ** Returns status of the operation
  1152. **
  1153. *******************************************************************************/
  1154. tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, UINT16 *p_timeout)
  1155. {
  1156. tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
  1157. BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout\n");
  1158. if (p != (tACL_CONN *)NULL) {
  1159. *p_timeout = p->link_super_tout;
  1160. return (BTM_SUCCESS);
  1161. }
  1162. /* If here, no BD Addr found */
  1163. return (BTM_UNKNOWN_ADDR);
  1164. }
  1165. /*******************************************************************************
  1166. **
  1167. ** Function BTM_SetLinkSuperTout
  1168. **
  1169. ** Description Create and send HCI "Write Link Supervision Timeout" command
  1170. **
  1171. ** Returns status of the operation
  1172. **
  1173. *******************************************************************************/
  1174. tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, UINT16 timeout)
  1175. {
  1176. tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
  1177. BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout\n");
  1178. if (p != (tACL_CONN *)NULL) {
  1179. p->link_super_tout = timeout;
  1180. /* Only send if current role is Master; 2.0 spec requires this */
  1181. if (p->link_role == BTM_ROLE_MASTER) {
  1182. if (!btsnd_hcic_write_link_super_tout (LOCAL_BR_EDR_CONTROLLER_ID,
  1183. p->hci_handle, timeout)) {
  1184. return (BTM_NO_RESOURCES);
  1185. }
  1186. return (BTM_CMD_STARTED);
  1187. } else {
  1188. return (BTM_SUCCESS);
  1189. }
  1190. }
  1191. /* If here, no BD Addr found */
  1192. return (BTM_UNKNOWN_ADDR);
  1193. }
  1194. /*******************************************************************************
  1195. **
  1196. ** Function BTM_IsAclConnectionUp
  1197. **
  1198. ** Description This function is called to check if an ACL connection exists
  1199. ** to a specific remote BD Address.
  1200. **
  1201. ** Returns TRUE if connection is up, else FALSE.
  1202. **
  1203. *******************************************************************************/
  1204. BOOLEAN BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport)
  1205. {
  1206. tACL_CONN *p;
  1207. BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
  1208. remote_bda[0], remote_bda[1], remote_bda[2],
  1209. remote_bda[3], remote_bda[4], remote_bda[5]);
  1210. p = btm_bda_to_acl(remote_bda, transport);
  1211. if (p != (tACL_CONN *)NULL) {
  1212. return (TRUE);
  1213. }
  1214. /* If here, no BD Addr found */
  1215. return (FALSE);
  1216. }
  1217. /*******************************************************************************
  1218. **
  1219. ** Function BTM_GetNumAclLinks
  1220. **
  1221. ** Description This function is called to count the number of
  1222. ** ACL links that are active.
  1223. **
  1224. ** Returns UINT16 Number of active ACL links
  1225. **
  1226. *******************************************************************************/
  1227. UINT16 BTM_GetNumAclLinks (void)
  1228. {
  1229. uint16_t num_acl = 0;
  1230. num_acl = list_length(btm_cb.p_acl_db_list);
  1231. return num_acl;
  1232. }
  1233. /*******************************************************************************
  1234. **
  1235. ** Function btm_get_acl_disc_reason_code
  1236. **
  1237. ** Description This function is called to get the disconnection reason code
  1238. ** returned by the HCI at disconnection complete event.
  1239. **
  1240. ** Returns TRUE if connection is up, else FALSE.
  1241. **
  1242. *******************************************************************************/
  1243. UINT16 btm_get_acl_disc_reason_code (void)
  1244. {
  1245. UINT8 res = btm_cb.acl_disc_reason;
  1246. BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code\n");
  1247. return (res);
  1248. }
  1249. /*******************************************************************************
  1250. **
  1251. ** Function BTM_GetHCIConnHandle
  1252. **
  1253. ** Description This function is called to get the handle for an ACL connection
  1254. ** to a specific remote BD Address.
  1255. **
  1256. ** Returns the handle of the connection, or 0xFFFF if none.
  1257. **
  1258. *******************************************************************************/
  1259. UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport)
  1260. {
  1261. tACL_CONN *p;
  1262. BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle\n");
  1263. p = btm_bda_to_acl(remote_bda, transport);
  1264. if (p != (tACL_CONN *)NULL) {
  1265. return (p->hci_handle);
  1266. }
  1267. /* If here, no BD Addr found */
  1268. return (0xFFFF);
  1269. }
  1270. /*******************************************************************************
  1271. **
  1272. ** Function btm_process_clk_off_comp_evt
  1273. **
  1274. ** Description This function is called when clock offset command completes.
  1275. **
  1276. ** Input Parms hci_handle - connection handle associated with the change
  1277. ** clock offset
  1278. **
  1279. ** Returns void
  1280. **
  1281. *******************************************************************************/
  1282. void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset)
  1283. {
  1284. tACL_CONN *p_acl_cb = NULL;
  1285. BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt\n");
  1286. /* Look up the connection by handle and set the current mode */
  1287. p_acl_cb = btm_handle_to_acl(hci_handle);
  1288. if (p_acl_cb) {
  1289. p_acl_cb->clock_offset = clock_offset;
  1290. }
  1291. }
  1292. /*******************************************************************************
  1293. **
  1294. ** Function btm_acl_role_changed
  1295. **
  1296. ** Description This function is called whan a link's master/slave role change
  1297. ** event or command status event (with error) is received.
  1298. ** It updates the link control block, and calls
  1299. ** the registered callback with status and role (if registered).
  1300. **
  1301. ** Returns void
  1302. **
  1303. *******************************************************************************/
  1304. void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)
  1305. {
  1306. UINT8 *p_bda = (bd_addr) ? bd_addr :
  1307. btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
  1308. tACL_CONN *p = btm_bda_to_acl(p_bda, BT_TRANSPORT_BR_EDR);
  1309. tBTM_ROLE_SWITCH_CMPL *p_data = &btm_cb.devcb.switch_role_ref_data;
  1310. tBTM_SEC_DEV_REC *p_dev_rec;
  1311. tBTM_BL_ROLE_CHG_DATA evt;
  1312. BTM_TRACE_DEBUG ("btm_acl_role_changed\n");
  1313. /* Ignore any stray events */
  1314. if (p == NULL) {
  1315. /* it could be a failure */
  1316. if (hci_status != HCI_SUCCESS) {
  1317. btm_acl_report_role_change(hci_status, bd_addr);
  1318. }
  1319. return;
  1320. }
  1321. p_data->hci_status = hci_status;
  1322. if (hci_status == HCI_SUCCESS) {
  1323. p_data->role = new_role;
  1324. memcpy(p_data->remote_bd_addr, p_bda, BD_ADDR_LEN);
  1325. /* Update cached value */
  1326. p->link_role = new_role;
  1327. /* Reload LSTO: link supervision timeout is reset in the LM after a role switch */
  1328. if (new_role == BTM_ROLE_MASTER) {
  1329. BTM_SetLinkSuperTout (p->remote_addr, p->link_super_tout);
  1330. }
  1331. } else {
  1332. /* so the BTM_BL_ROLE_CHG_EVT uses the old role */
  1333. new_role = p->link_role;
  1334. }
  1335. /* Check if any SCO req is pending for role change */
  1336. btm_sco_chk_pend_rolechange (p->hci_handle);
  1337. /* if switching state is switching we need to turn encryption on */
  1338. /* if idle, we did not change encryption */
  1339. if (p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING) {
  1340. if (btsnd_hcic_set_conn_encrypt (p->hci_handle, TRUE)) {
  1341. p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON;
  1342. p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
  1343. return;
  1344. }
  1345. }
  1346. /* Set the switch_role_state to IDLE since the reply received from HCI */
  1347. /* regardless of its result either success or failed. */
  1348. if (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS) {
  1349. p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
  1350. p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
  1351. }
  1352. /* if role switch complete is needed, report it now */
  1353. btm_acl_report_role_change(hci_status, bd_addr);
  1354. /* if role change event is registered, report it now */
  1355. if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) {
  1356. evt.event = BTM_BL_ROLE_CHG_EVT;
  1357. evt.new_role = new_role;
  1358. evt.p_bda = p_bda;
  1359. evt.hci_status = hci_status;
  1360. (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
  1361. }
  1362. BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d\n",
  1363. p_data->role, p_data->hci_status, p->switch_role_state);
  1364. #if BTM_DISC_DURING_RS == TRUE
  1365. /* If a disconnect is pending, issue it now that role switch has completed */
  1366. if ((p_dev_rec = btm_find_dev (p_bda)) != NULL) {
  1367. if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) {
  1368. BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!\n");
  1369. btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
  1370. }
  1371. BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d\n",
  1372. (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
  1373. p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
  1374. }
  1375. #endif
  1376. }
  1377. /*******************************************************************************
  1378. **
  1379. ** Function BTM_AllocateSCN
  1380. **
  1381. ** Description Look through the Server Channel Numbers for a free one.
  1382. **
  1383. ** Returns Allocated SCN number or 0 if none.
  1384. **
  1385. *******************************************************************************/
  1386. #if (CLASSIC_BT_INCLUDED == TRUE)
  1387. UINT8 BTM_AllocateSCN(void)
  1388. {
  1389. UINT8 x;
  1390. BTM_TRACE_DEBUG ("BTM_AllocateSCN\n");
  1391. for (x = 1; x < BTM_MAX_SCN; x++) {
  1392. if (!btm_cb.btm_scn[x - 1]) {
  1393. btm_cb.btm_scn[x - 1] = TRUE;
  1394. return x;
  1395. }
  1396. }
  1397. return (0); /* No free ports */
  1398. }
  1399. #endif ///CLASSIC_BT_INCLUDED == TRUE
  1400. /*******************************************************************************
  1401. **
  1402. ** Function BTM_TryAllocateSCN
  1403. **
  1404. ** Description Try to allocate a fixed server channel
  1405. **
  1406. ** Returns Returns TRUE if server channel was available
  1407. **
  1408. *******************************************************************************/
  1409. #if (CLASSIC_BT_INCLUDED == TRUE)
  1410. BOOLEAN BTM_TryAllocateSCN(UINT8 scn)
  1411. {
  1412. if (scn >= BTM_MAX_SCN) {
  1413. return FALSE;
  1414. }
  1415. /* check if this port is available */
  1416. if (!btm_cb.btm_scn[scn - 1]) {
  1417. btm_cb.btm_scn[scn - 1] = TRUE;
  1418. return TRUE;
  1419. }
  1420. return (FALSE); /* Port was busy */
  1421. }
  1422. /*******************************************************************************
  1423. **
  1424. ** Function BTM_FreeSCN
  1425. **
  1426. ** Description Free the specified SCN.
  1427. **
  1428. ** Returns TRUE or FALSE
  1429. **
  1430. *******************************************************************************/
  1431. BOOLEAN BTM_FreeSCN(UINT8 scn)
  1432. {
  1433. BTM_TRACE_DEBUG ("BTM_FreeSCN \n");
  1434. if (scn <= BTM_MAX_SCN) {
  1435. btm_cb.btm_scn[scn - 1] = FALSE;
  1436. return (TRUE);
  1437. } else {
  1438. return (FALSE); /* Illegal SCN passed in */
  1439. }
  1440. return (FALSE);
  1441. }
  1442. #endif ///CLASSIC_BT_INCLUDED == TRUE
  1443. /*******************************************************************************
  1444. **
  1445. ** Function btm_set_packet_types
  1446. **
  1447. ** Description This function sets the packet types used for a specific
  1448. ** ACL connection. It is called internally by btm_acl_created
  1449. ** or by an application/profile by BTM_SetPacketTypes.
  1450. **
  1451. ** Returns status of the operation
  1452. **
  1453. *******************************************************************************/
  1454. tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types)
  1455. {
  1456. UINT16 temp_pkt_types;
  1457. BTM_TRACE_DEBUG ("btm_set_packet_types\n");
  1458. /* Save in the ACL control blocks, types that we support */
  1459. temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK &
  1460. btm_cb.btm_acl_pkt_types_supported);
  1461. /* OR in any exception packet types if at least 2.0 version of spec */
  1462. temp_pkt_types |= ((pkt_types & BTM_ACL_EXCEPTION_PKTS_MASK) |
  1463. (btm_cb.btm_acl_pkt_types_supported & BTM_ACL_EXCEPTION_PKTS_MASK));
  1464. /* Exclude packet types not supported by the peer */
  1465. btm_acl_chk_peer_pkt_type_support (p, &temp_pkt_types);
  1466. BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x\n", temp_pkt_types);
  1467. if (!btsnd_hcic_change_conn_type (p->hci_handle, temp_pkt_types)) {
  1468. return (BTM_NO_RESOURCES);
  1469. }
  1470. p->pkt_types_mask = temp_pkt_types;
  1471. return (BTM_CMD_STARTED);
  1472. }
  1473. /*******************************************************************************
  1474. **
  1475. ** Function btm_get_max_packet_size
  1476. **
  1477. ** Returns Returns maximum packet size that can be used for current
  1478. ** connection, 0 if connection is not established
  1479. **
  1480. *******************************************************************************/
  1481. UINT16 btm_get_max_packet_size (BD_ADDR addr)
  1482. {
  1483. tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
  1484. UINT16 pkt_types = 0;
  1485. UINT16 pkt_size = 0;
  1486. BTM_TRACE_DEBUG ("btm_get_max_packet_size\n");
  1487. if (p != NULL) {
  1488. pkt_types = p->pkt_types_mask;
  1489. } else {
  1490. /* Special case for when info for the local device is requested */
  1491. if (memcmp (controller_get_interface()->get_address(), addr, BD_ADDR_LEN) == 0) {
  1492. pkt_types = btm_cb.btm_acl_pkt_types_supported;
  1493. }
  1494. }
  1495. if (pkt_types) {
  1496. if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH5)) {
  1497. pkt_size = HCI_EDR3_DH5_PACKET_SIZE;
  1498. } else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH5)) {
  1499. pkt_size = HCI_EDR2_DH5_PACKET_SIZE;
  1500. } else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH3)) {
  1501. pkt_size = HCI_EDR3_DH3_PACKET_SIZE;
  1502. } else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH5) {
  1503. pkt_size = HCI_DH5_PACKET_SIZE;
  1504. } else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH3)) {
  1505. pkt_size = HCI_EDR2_DH3_PACKET_SIZE;
  1506. } else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM5) {
  1507. pkt_size = HCI_DM5_PACKET_SIZE;
  1508. } else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH3) {
  1509. pkt_size = HCI_DH3_PACKET_SIZE;
  1510. } else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM3) {
  1511. pkt_size = HCI_DM3_PACKET_SIZE;
  1512. } else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH1)) {
  1513. pkt_size = HCI_EDR3_DH1_PACKET_SIZE;
  1514. } else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH1)) {
  1515. pkt_size = HCI_EDR2_DH1_PACKET_SIZE;
  1516. } else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH1) {
  1517. pkt_size = HCI_DH1_PACKET_SIZE;
  1518. } else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM1) {
  1519. pkt_size = HCI_DM1_PACKET_SIZE;
  1520. }
  1521. }
  1522. return (pkt_size);
  1523. }
  1524. /*******************************************************************************
  1525. **
  1526. ** Function BTM_ReadRemoteVersion
  1527. **
  1528. ** Returns If connected report peer device info
  1529. **
  1530. *******************************************************************************/
  1531. tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, UINT8 *lmp_version,
  1532. UINT16 *manufacturer, UINT16 *lmp_sub_version)
  1533. {
  1534. tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
  1535. BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion\n");
  1536. if (p == NULL) {
  1537. return (BTM_UNKNOWN_ADDR);
  1538. }
  1539. if (lmp_version) {
  1540. *lmp_version = p->lmp_version;
  1541. }
  1542. if (manufacturer) {
  1543. *manufacturer = p->manufacturer;
  1544. }
  1545. if (lmp_sub_version) {
  1546. *lmp_sub_version = p->lmp_subversion;
  1547. }
  1548. return (BTM_SUCCESS);
  1549. }
  1550. /*******************************************************************************
  1551. **
  1552. ** Function BTM_ReadRemoteFeatures
  1553. **
  1554. ** Returns pointer to the remote supported features mask (8 bytes)
  1555. **
  1556. *******************************************************************************/
  1557. UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr)
  1558. {
  1559. tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
  1560. BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures\n");
  1561. if (p == NULL) {
  1562. return (NULL);
  1563. }
  1564. return (p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
  1565. }
  1566. /*******************************************************************************
  1567. **
  1568. ** Function BTM_ReadRemoteExtendedFeatures
  1569. **
  1570. ** Returns pointer to the remote extended features mask (8 bytes)
  1571. ** or NULL if bad page
  1572. **
  1573. *******************************************************************************/
  1574. UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number)
  1575. {
  1576. tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
  1577. BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures\n");
  1578. if (p == NULL) {
  1579. return (NULL);
  1580. }
  1581. if (page_number > HCI_EXT_FEATURES_PAGE_MAX) {
  1582. BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown\n", page_number);
  1583. return NULL;
  1584. }
  1585. return (p->peer_lmp_features[page_number]);
  1586. }
  1587. /*******************************************************************************
  1588. **
  1589. ** Function BTM_ReadNumberRemoteFeaturesPages
  1590. **
  1591. ** Returns number of features pages read from the remote device.
  1592. **
  1593. *******************************************************************************/
  1594. UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr)
  1595. {
  1596. tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
  1597. BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages\n");
  1598. if (p == NULL) {
  1599. return (0);
  1600. }
  1601. return (p->num_read_pages);
  1602. }
  1603. /*******************************************************************************
  1604. **
  1605. ** Function BTM_ReadAllRemoteFeatures
  1606. **
  1607. ** Returns pointer to all features of the remote (24 bytes).
  1608. **
  1609. *******************************************************************************/
  1610. UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr)
  1611. {
  1612. tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
  1613. BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures\n");
  1614. if (p == NULL) {
  1615. return (NULL);
  1616. }
  1617. return (p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
  1618. }
  1619. /*******************************************************************************
  1620. **
  1621. ** Function BTM_RegBusyLevelNotif
  1622. **
  1623. ** Description This function is called to register a callback to receive
  1624. ** busy level change events.
  1625. **
  1626. ** Returns BTM_SUCCESS if successfully registered, otherwise error
  1627. **
  1628. *******************************************************************************/
  1629. tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, UINT8 *p_level,
  1630. tBTM_BL_EVENT_MASK evt_mask)
  1631. {
  1632. BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif\n");
  1633. if (p_level) {
  1634. *p_level = btm_cb.busy_level;
  1635. }
  1636. btm_cb.bl_evt_mask = evt_mask;
  1637. if (!p_cb) {
  1638. btm_cb.p_bl_changed_cb = NULL;
  1639. } else if (btm_cb.p_bl_changed_cb) {
  1640. return (BTM_BUSY);
  1641. } else {
  1642. btm_cb.p_bl_changed_cb = p_cb;
  1643. }
  1644. return (BTM_SUCCESS);
  1645. }
  1646. /*******************************************************************************
  1647. **
  1648. ** Function BTM_SetQoS
  1649. **
  1650. ** Description This function is called to setup QoS
  1651. **
  1652. ** Returns status of the operation
  1653. **
  1654. *******************************************************************************/
  1655. tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb)
  1656. {
  1657. tACL_CONN *p = NULL;
  1658. BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x\n",
  1659. bd[0], bd[1], bd[2],
  1660. bd[3], bd[4], bd[5]);
  1661. /* If someone already waiting on the version, do not allow another */
  1662. if (btm_cb.devcb.p_qossu_cmpl_cb) {
  1663. return (BTM_BUSY);
  1664. }
  1665. if ( (p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR)) != NULL) {
  1666. btu_start_timer (&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_QOS, BTM_DEV_REPLY_TIMEOUT);
  1667. btm_cb.devcb.p_qossu_cmpl_cb = p_cb;
  1668. if (!btsnd_hcic_qos_setup (p->hci_handle, p_flow->qos_flags, p_flow->service_type,
  1669. p_flow->token_rate, p_flow->peak_bandwidth,
  1670. p_flow->latency, p_flow->delay_variation)) {
  1671. btm_cb.devcb.p_qossu_cmpl_cb = NULL;
  1672. btu_stop_timer(&btm_cb.devcb.qossu_timer);
  1673. return (BTM_NO_RESOURCES);
  1674. } else {
  1675. return (BTM_CMD_STARTED);
  1676. }
  1677. }
  1678. /* If here, no BD Addr found */
  1679. return (BTM_UNKNOWN_ADDR);
  1680. }
  1681. /*******************************************************************************
  1682. **
  1683. ** Function btm_qos_setup_complete
  1684. **
  1685. ** Description This function is called when the command complete message
  1686. ** is received from the HCI for the qos setup request.
  1687. **
  1688. ** Returns void
  1689. **
  1690. *******************************************************************************/
  1691. void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
  1692. {
  1693. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qossu_cmpl_cb;
  1694. tBTM_QOS_SETUP_CMPL qossu;
  1695. BTM_TRACE_DEBUG ("btm_qos_setup_complete\n");
  1696. btu_stop_timer (&btm_cb.devcb.qossu_timer);
  1697. btm_cb.devcb.p_qossu_cmpl_cb = NULL;
  1698. if (p_cb) {
  1699. memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL));
  1700. qossu.status = status;
  1701. qossu.handle = handle;
  1702. tACL_CONN *p = btm_handle_to_acl(handle);
  1703. if (p != NULL) {
  1704. memcpy (qossu.rem_bda, p->remote_addr, BD_ADDR_LEN);
  1705. }
  1706. if (p_flow != NULL) {
  1707. qossu.flow.qos_flags = p_flow->qos_flags;
  1708. qossu.flow.service_type = p_flow->service_type;
  1709. qossu.flow.token_rate = p_flow->token_rate;
  1710. qossu.flow.peak_bandwidth = p_flow->peak_bandwidth;
  1711. qossu.flow.latency = p_flow->latency;
  1712. qossu.flow.delay_variation = p_flow->delay_variation;
  1713. }
  1714. BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x\n",
  1715. qossu.flow.delay_variation);
  1716. (*p_cb)(&qossu);
  1717. }
  1718. }
  1719. /*******************************************************************************
  1720. **
  1721. ** Function btm_qos_setup_timeout
  1722. **
  1723. ** Description This function processes a timeout.
  1724. ** Currently, we just report an error log
  1725. **
  1726. ** Returns void
  1727. **
  1728. *******************************************************************************/
  1729. void btm_qos_setup_timeout (void *p_tle)
  1730. {
  1731. BTM_TRACE_DEBUG ("%s\n", __func__);
  1732. btm_qos_setup_complete (HCI_ERR_HOST_TIMEOUT, 0, NULL);
  1733. }
  1734. /*******************************************************************************
  1735. **
  1736. ** Function BTM_ReadRSSI
  1737. **
  1738. ** Description This function is called to read the link policy settings.
  1739. ** The address of link policy results are returned in the callback.
  1740. ** (tBTM_RSSI_RESULTS)
  1741. **
  1742. ** Returns BTM_CMD_STARTED if successfully initiated or error code
  1743. **
  1744. *******************************************************************************/
  1745. tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb)
  1746. {
  1747. tACL_CONN *p;
  1748. BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
  1749. remote_bda[0], remote_bda[1], remote_bda[2],
  1750. remote_bda[3], remote_bda[4], remote_bda[5]);
  1751. tBTM_RSSI_RESULTS result;
  1752. /* If someone already waiting on the version, do not allow another */
  1753. if (btm_cb.devcb.p_rssi_cmpl_cb) {
  1754. result.status = BTM_BUSY;
  1755. (*p_cb)(&result);
  1756. return (BTM_BUSY);
  1757. }
  1758. p = btm_bda_to_acl(remote_bda, transport);
  1759. if (p != (tACL_CONN *)NULL) {
  1760. btu_start_timer (&btm_cb.devcb.rssi_timer, BTU_TTYPE_BTM_ACL,
  1761. BTM_DEV_REPLY_TIMEOUT);
  1762. btm_cb.devcb.p_rssi_cmpl_cb = p_cb;
  1763. if (!btsnd_hcic_read_rssi (p->hci_handle)) {
  1764. btm_cb.devcb.p_rssi_cmpl_cb = NULL;
  1765. btu_stop_timer (&btm_cb.devcb.rssi_timer);
  1766. result.status = BTM_NO_RESOURCES;
  1767. (*p_cb)(&result);
  1768. return (BTM_NO_RESOURCES);
  1769. } else {
  1770. return (BTM_CMD_STARTED);
  1771. }
  1772. }
  1773. /* If here, no BD Addr found */
  1774. return (BTM_UNKNOWN_ADDR);
  1775. }
  1776. /*******************************************************************************
  1777. **
  1778. ** Function BTM_ReadLinkQuality
  1779. **
  1780. ** Description This function is called to read the link qulaity.
  1781. ** The value of the link quality is returned in the callback.
  1782. ** (tBTM_LINK_QUALITY_RESULTS)
  1783. **
  1784. ** Returns BTM_CMD_STARTED if successfully initiated or error code
  1785. **
  1786. *******************************************************************************/
  1787. tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
  1788. {
  1789. tACL_CONN *p;
  1790. BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
  1791. remote_bda[0], remote_bda[1], remote_bda[2],
  1792. remote_bda[3], remote_bda[4], remote_bda[5]);
  1793. /* If someone already waiting on the version, do not allow another */
  1794. if (btm_cb.devcb.p_lnk_qual_cmpl_cb) {
  1795. return (BTM_BUSY);
  1796. }
  1797. p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
  1798. if (p != (tACL_CONN *)NULL) {
  1799. btu_start_timer (&btm_cb.devcb.lnk_quality_timer, BTU_TTYPE_BTM_ACL,
  1800. BTM_DEV_REPLY_TIMEOUT);
  1801. btm_cb.devcb.p_lnk_qual_cmpl_cb = p_cb;
  1802. if (!btsnd_hcic_get_link_quality (p->hci_handle)) {
  1803. btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
  1804. btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
  1805. return (BTM_NO_RESOURCES);
  1806. } else {
  1807. return (BTM_CMD_STARTED);
  1808. }
  1809. }
  1810. /* If here, no BD Addr found */
  1811. return (BTM_UNKNOWN_ADDR);
  1812. }
  1813. /*******************************************************************************
  1814. **
  1815. ** Function BTM_ReadTxPower
  1816. **
  1817. ** Description This function is called to read the current
  1818. ** TX power of the connection. The tx power level results
  1819. ** are returned in the callback.
  1820. ** (tBTM_RSSI_RESULTS)
  1821. **
  1822. ** Returns BTM_CMD_STARTED if successfully initiated or error code
  1823. **
  1824. *******************************************************************************/
  1825. tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb)
  1826. {
  1827. tACL_CONN *p;
  1828. BOOLEAN ret;
  1829. #define BTM_READ_RSSI_TYPE_CUR 0x00
  1830. #define BTM_READ_RSSI_TYPE_MAX 0X01
  1831. BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
  1832. remote_bda[0], remote_bda[1], remote_bda[2],
  1833. remote_bda[3], remote_bda[4], remote_bda[5]);
  1834. /* If someone already waiting on the version, do not allow another */
  1835. if (btm_cb.devcb.p_tx_power_cmpl_cb) {
  1836. return (BTM_BUSY);
  1837. }
  1838. p = btm_bda_to_acl(remote_bda, transport);
  1839. if (p != (tACL_CONN *)NULL) {
  1840. btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL,
  1841. BTM_DEV_REPLY_TIMEOUT);
  1842. btm_cb.devcb.p_tx_power_cmpl_cb = p_cb;
  1843. #if BLE_INCLUDED == TRUE
  1844. if (p->transport == BT_TRANSPORT_LE) {
  1845. memcpy(btm_cb.devcb.read_tx_pwr_addr, remote_bda, BD_ADDR_LEN);
  1846. ret = btsnd_hcic_ble_read_adv_chnl_tx_power();
  1847. } else
  1848. #endif
  1849. {
  1850. ret = btsnd_hcic_read_tx_power (p->hci_handle, BTM_READ_RSSI_TYPE_CUR);
  1851. }
  1852. if (!ret) {
  1853. btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
  1854. btu_stop_timer (&btm_cb.devcb.tx_power_timer);
  1855. return (BTM_NO_RESOURCES);
  1856. } else {
  1857. return (BTM_CMD_STARTED);
  1858. }
  1859. }
  1860. /* If here, no BD Addr found */
  1861. return (BTM_UNKNOWN_ADDR);
  1862. }
  1863. #if (BLE_INCLUDED == TRUE)
  1864. tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb)
  1865. {
  1866. BOOLEAN ret;
  1867. tBTM_TX_POWER_RESULTS result;
  1868. /* If someone already waiting on the version, do not allow another */
  1869. if (btm_cb.devcb.p_tx_power_cmpl_cb) {
  1870. result.status = BTM_BUSY;
  1871. (*p_cb)(&result);
  1872. return (BTM_BUSY);
  1873. }
  1874. btm_cb.devcb.p_tx_power_cmpl_cb = p_cb;
  1875. btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL,
  1876. BTM_DEV_REPLY_TIMEOUT);
  1877. ret = btsnd_hcic_ble_read_adv_chnl_tx_power();
  1878. if(!ret) {
  1879. btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
  1880. btu_stop_timer (&btm_cb.devcb.tx_power_timer);
  1881. result.status = BTM_NO_RESOURCES;
  1882. (*p_cb)(&result);
  1883. return (BTM_NO_RESOURCES);
  1884. } else {
  1885. return BTM_CMD_STARTED;
  1886. }
  1887. }
  1888. void BTM_BleGetWhiteListSize(uint16_t *length)
  1889. {
  1890. tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
  1891. if (p_cb->white_list_avail_size == 0) {
  1892. BTM_TRACE_WARNING("%s Whitelist full.", __func__);
  1893. }
  1894. *length = p_cb->white_list_avail_size;
  1895. return;
  1896. }
  1897. #endif ///BLE_INCLUDED == TRUE
  1898. /*******************************************************************************
  1899. **
  1900. ** Function btm_read_tx_power_complete
  1901. **
  1902. ** Description This function is called when the command complete message
  1903. ** is received from the HCI for the read tx power request.
  1904. **
  1905. ** Returns void
  1906. **
  1907. *******************************************************************************/
  1908. void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble)
  1909. {
  1910. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb;
  1911. tBTM_TX_POWER_RESULTS results;
  1912. UINT16 handle;
  1913. tACL_CONN *p_acl_cb = NULL;
  1914. BTM_TRACE_DEBUG ("btm_read_tx_power_complete\n");
  1915. btu_stop_timer (&btm_cb.devcb.tx_power_timer);
  1916. /* If there was a callback registered for read rssi, call it */
  1917. btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
  1918. if (p_cb) {
  1919. STREAM_TO_UINT8 (results.hci_status, p);
  1920. if (results.hci_status == HCI_SUCCESS) {
  1921. results.status = BTM_SUCCESS;
  1922. if (!is_ble) {
  1923. STREAM_TO_UINT16 (handle, p);
  1924. STREAM_TO_UINT8 (results.tx_power, p);
  1925. /* Search through the list of active channels for the correct BD Addr */
  1926. p_acl_cb = btm_handle_to_acl(handle);
  1927. if (p_acl_cb) {
  1928. memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
  1929. }
  1930. }
  1931. #if BLE_INCLUDED == TRUE
  1932. else {
  1933. STREAM_TO_UINT8 (results.tx_power, p);
  1934. memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN);
  1935. }
  1936. #endif
  1937. BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x\n",
  1938. results.tx_power, results.hci_status);
  1939. } else {
  1940. results.status = BTM_ERR_PROCESSING;
  1941. }
  1942. (*p_cb)(&results);
  1943. }
  1944. }
  1945. /*******************************************************************************
  1946. **
  1947. ** Function btm_read_rssi_complete
  1948. **
  1949. ** Description This function is called when the command complete message
  1950. ** is received from the HCI for the read rssi request.
  1951. **
  1952. ** Returns void
  1953. **
  1954. *******************************************************************************/
  1955. void btm_read_rssi_complete (UINT8 *p)
  1956. {
  1957. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
  1958. tBTM_RSSI_RESULTS results;
  1959. UINT16 handle;
  1960. tACL_CONN *p_acl_cb = NULL;
  1961. BTM_TRACE_DEBUG ("btm_read_rssi_complete\n");
  1962. btu_stop_timer (&btm_cb.devcb.rssi_timer);
  1963. /* If there was a callback registered for read rssi, call it */
  1964. btm_cb.devcb.p_rssi_cmpl_cb = NULL;
  1965. if (p_cb) {
  1966. STREAM_TO_UINT8 (results.hci_status, p);
  1967. if (results.hci_status == HCI_SUCCESS) {
  1968. results.status = BTM_SUCCESS;
  1969. STREAM_TO_UINT16 (handle, p);
  1970. STREAM_TO_UINT8 (results.rssi, p);
  1971. BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x\n",
  1972. results.rssi, results.hci_status);
  1973. /* Search through the list of active channels for the correct BD Addr */
  1974. p_acl_cb = btm_handle_to_acl(handle);
  1975. if (p_acl_cb) {
  1976. memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
  1977. }
  1978. } else {
  1979. results.status = BTM_ERR_PROCESSING;
  1980. }
  1981. (*p_cb)(&results);
  1982. }
  1983. }
  1984. /*******************************************************************************
  1985. **
  1986. ** Function btm_read_link_quality_complete
  1987. **
  1988. ** Description This function is called when the command complete message
  1989. ** is received from the HCI for the read link quality.
  1990. **
  1991. ** Returns void
  1992. **
  1993. *******************************************************************************/
  1994. void btm_read_link_quality_complete (UINT8 *p)
  1995. {
  1996. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_lnk_qual_cmpl_cb;
  1997. tBTM_LINK_QUALITY_RESULTS results;
  1998. UINT16 handle;
  1999. tACL_CONN *p_acl_cb = NULL;
  2000. BTM_TRACE_DEBUG ("btm_read_link_quality_complete\n");
  2001. btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
  2002. /* If there was a callback registered for read rssi, call it */
  2003. btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
  2004. if (p_cb) {
  2005. STREAM_TO_UINT8 (results.hci_status, p);
  2006. if (results.hci_status == HCI_SUCCESS) {
  2007. results.status = BTM_SUCCESS;
  2008. STREAM_TO_UINT16 (handle, p);
  2009. STREAM_TO_UINT8 (results.link_quality, p);
  2010. BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x\n",
  2011. results.link_quality, results.hci_status);
  2012. /* Search through the list of active channels for the correct BD Addr */
  2013. p_acl_cb = btm_handle_to_acl(handle);
  2014. if (p_acl_cb) {
  2015. memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
  2016. }
  2017. } else {
  2018. results.status = BTM_ERR_PROCESSING;
  2019. }
  2020. (*p_cb)(&results);
  2021. }
  2022. }
  2023. /*******************************************************************************
  2024. **
  2025. ** Function btm_remove_acl
  2026. **
  2027. ** Description This function is called to disconnect an ACL connection
  2028. **
  2029. ** Returns BTM_SUCCESS if successfully initiated, otherwise BTM_NO_RESOURCES.
  2030. **
  2031. *******************************************************************************/
  2032. tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport)
  2033. {
  2034. UINT16 hci_handle = BTM_GetHCIConnHandle(bd_addr, transport);
  2035. tBTM_STATUS status = BTM_SUCCESS;
  2036. BTM_TRACE_DEBUG ("btm_remove_acl\n");
  2037. #if BTM_DISC_DURING_RS == TRUE
  2038. tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
  2039. /* Role Switch is pending, postpone until completed */
  2040. if (p_dev_rec && (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING)) {
  2041. p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING;
  2042. } else /* otherwise can disconnect right away */
  2043. #endif
  2044. {
  2045. if (hci_handle != 0xFFFF && p_dev_rec &&
  2046. p_dev_rec->sec_state != BTM_SEC_STATE_DISCONNECTING) {
  2047. if (!btsnd_hcic_disconnect (hci_handle, HCI_ERR_PEER_USER)) {
  2048. status = BTM_NO_RESOURCES;
  2049. }
  2050. } else {
  2051. status = BTM_UNKNOWN_ADDR;
  2052. }
  2053. }
  2054. return status;
  2055. }
  2056. /*******************************************************************************
  2057. **
  2058. ** Function BTM_SetTraceLevel
  2059. **
  2060. ** Description This function sets the trace level for BTM. If called with
  2061. ** a value of 0xFF, it simply returns the current trace level.
  2062. **
  2063. ** Returns The new or current trace level
  2064. **
  2065. *******************************************************************************/
  2066. UINT8 BTM_SetTraceLevel (UINT8 new_level)
  2067. {
  2068. BTM_TRACE_DEBUG ("BTM_SetTraceLevel\n");
  2069. if (new_level != 0xFF) {
  2070. btm_cb.trace_level = new_level;
  2071. }
  2072. return (btm_cb.trace_level);
  2073. }
  2074. /*******************************************************************************
  2075. **
  2076. ** Function btm_cont_rswitch
  2077. **
  2078. ** Description This function is called to continue processing an active
  2079. ** role switch. It first disables encryption if enabled and
  2080. ** EPR is not supported
  2081. **
  2082. ** Returns void
  2083. **
  2084. *******************************************************************************/
  2085. void btm_cont_rswitch (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec,
  2086. UINT8 hci_status)
  2087. {
  2088. BOOLEAN sw_ok = TRUE;
  2089. BTM_TRACE_DEBUG ("btm_cont_rswitch\n");
  2090. /* Check to see if encryption needs to be turned off if pending
  2091. change of link key or role switch */
  2092. if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
  2093. /* Must turn off Encryption first if necessary */
  2094. /* Some devices do not support switch or change of link key while encryption is on */
  2095. if (p_dev_rec != NULL && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
  2096. && !BTM_EPR_AVAILABLE(p)) {
  2097. if (btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE)) {
  2098. p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
  2099. if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
  2100. p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
  2101. }
  2102. } else {
  2103. /* Error occurred; set states back to Idle */
  2104. if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
  2105. sw_ok = FALSE;
  2106. }
  2107. }
  2108. } else /* Encryption not used or EPR supported, continue with switch
  2109. and/or change of link key */
  2110. {
  2111. if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
  2112. p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
  2113. #if BTM_DISC_DURING_RS == TRUE
  2114. if (p_dev_rec) {
  2115. p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
  2116. }
  2117. #endif
  2118. sw_ok = btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role);
  2119. }
  2120. }
  2121. if (!sw_ok) {
  2122. p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
  2123. btm_acl_report_role_change(hci_status, p->remote_addr);
  2124. }
  2125. }
  2126. }
  2127. /*******************************************************************************
  2128. **
  2129. ** Function btm_acl_resubmit_page
  2130. **
  2131. ** Description send pending page request
  2132. **
  2133. *******************************************************************************/
  2134. void btm_acl_resubmit_page (void)
  2135. {
  2136. #if (SMP_INCLUDED == TRUE)
  2137. tBTM_SEC_DEV_REC *p_dev_rec;
  2138. BT_HDR *p_buf;
  2139. UINT8 *pp;
  2140. BD_ADDR bda;
  2141. BTM_TRACE_DEBUG ("btm_acl_resubmit_page\n");
  2142. /* If there were other page request schedule can start the next one */
  2143. if ((p_buf = (BT_HDR *)fixed_queue_dequeue(btm_cb.page_queue, 0)) != NULL) {
  2144. /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr
  2145. * for both create_conn and rmt_name */
  2146. pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3;
  2147. STREAM_TO_BDADDR (bda, pp);
  2148. p_dev_rec = btm_find_or_alloc_dev (bda);
  2149. memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
  2150. memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);
  2151. btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p_buf);
  2152. } else {
  2153. btm_cb.paging = FALSE;
  2154. }
  2155. #endif ///SMP_INCLUDED == TRUE
  2156. }
  2157. /*******************************************************************************
  2158. **
  2159. ** Function btm_acl_reset_paging
  2160. **
  2161. ** Description set paging to FALSE and free the page queue - called at hci_reset
  2162. **
  2163. *******************************************************************************/
  2164. void btm_acl_reset_paging (void)
  2165. {
  2166. BT_HDR *p;
  2167. BTM_TRACE_DEBUG ("btm_acl_reset_paging\n");
  2168. /* If we sent reset we are definitely not paging any more */
  2169. while ((p = (BT_HDR *)fixed_queue_dequeue(btm_cb.page_queue, 0)) != NULL) {
  2170. osi_free (p);
  2171. }
  2172. btm_cb.paging = FALSE;
  2173. }
  2174. /*******************************************************************************
  2175. **
  2176. ** Function btm_acl_paging
  2177. **
  2178. ** Description send a paging command or queue it in btm_cb
  2179. **
  2180. *******************************************************************************/
  2181. #if (SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE)
  2182. void btm_acl_paging (BT_HDR *p, BD_ADDR bda)
  2183. {
  2184. tBTM_SEC_DEV_REC *p_dev_rec;
  2185. BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x\n",
  2186. btm_cb.discing, btm_cb.paging,
  2187. (bda[0] << 16) + (bda[1] << 8) + bda[2], (bda[3] << 16) + (bda[4] << 8) + bda[5]);
  2188. if (btm_cb.discing) {
  2189. btm_cb.paging = TRUE;
  2190. fixed_queue_enqueue(btm_cb.page_queue, p, FIXED_QUEUE_MAX_TIMEOUT);
  2191. } else {
  2192. if (!BTM_ACL_IS_CONNECTED (bda)) {
  2193. BTM_TRACE_DEBUG ("connecting_bda: %06x%06x\n",
  2194. (btm_cb.connecting_bda[0] << 16) + (btm_cb.connecting_bda[1] << 8) +
  2195. btm_cb.connecting_bda[2],
  2196. (btm_cb.connecting_bda[3] << 16) + (btm_cb.connecting_bda[4] << 8) +
  2197. btm_cb.connecting_bda[5]);
  2198. if (btm_cb.paging &&
  2199. memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) {
  2200. fixed_queue_enqueue(btm_cb.page_queue, p, FIXED_QUEUE_MAX_TIMEOUT);
  2201. } else {
  2202. p_dev_rec = btm_find_or_alloc_dev (bda);
  2203. memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
  2204. memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);
  2205. btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
  2206. }
  2207. btm_cb.paging = TRUE;
  2208. } else { /* ACL is already up */
  2209. btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
  2210. }
  2211. }
  2212. }
  2213. #endif ///SMP_INCLUDED == TRUE
  2214. /*******************************************************************************
  2215. **
  2216. ** Function btm_acl_notif_conn_collision
  2217. **
  2218. ** Description Send connection collision event to upper layer if registered
  2219. **
  2220. ** Returns TRUE if sent out to upper layer,
  2221. ** FALSE if no one needs the notification.
  2222. **
  2223. *******************************************************************************/
  2224. BOOLEAN btm_acl_notif_conn_collision (BD_ADDR bda)
  2225. {
  2226. tBTM_BL_EVENT_DATA evt_data;
  2227. /* Report possible collision to the upper layer. */
  2228. if (btm_cb.p_bl_changed_cb) {
  2229. BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
  2230. bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
  2231. evt_data.event = BTM_BL_COLLISION_EVT;
  2232. evt_data.conn.p_bda = bda;
  2233. #if BLE_INCLUDED == TRUE
  2234. evt_data.conn.transport = BT_TRANSPORT_BR_EDR;
  2235. evt_data.conn.handle = BTM_INVALID_HCI_HANDLE;
  2236. #endif
  2237. (*btm_cb.p_bl_changed_cb)(&evt_data);
  2238. return TRUE;
  2239. } else {
  2240. return FALSE;
  2241. }
  2242. }
  2243. /*******************************************************************************
  2244. **
  2245. ** Function btm_acl_chk_peer_pkt_type_support
  2246. **
  2247. ** Description Check if peer supports requested packets
  2248. **
  2249. *******************************************************************************/
  2250. void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, UINT16 *p_pkt_type)
  2251. {
  2252. /* 3 and 5 slot packets? */
  2253. if (!HCI_3_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
  2254. *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3);
  2255. }
  2256. if (!HCI_5_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
  2257. *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5);
  2258. }
  2259. /* 2 and 3 MPS support? */
  2260. if (!HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
  2261. /* Not supported. Add 'not_supported' mask for all 2MPS packet types */
  2262. *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
  2263. BTM_ACL_PKT_TYPES_MASK_NO_2_DH5);
  2264. }
  2265. if (!HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
  2266. /* Not supported. Add 'not_supported' mask for all 3MPS packet types */
  2267. *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 +
  2268. BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
  2269. }
  2270. /* EDR 3 and 5 slot support? */
  2271. if (HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])
  2272. || HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
  2273. if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
  2274. /* Not supported. Add 'not_supported' mask for all 3-slot EDR packet types */
  2275. {
  2276. *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3);
  2277. }
  2278. if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
  2279. /* Not supported. Add 'not_supported' mask for all 5-slot EDR packet types */
  2280. {
  2281. *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
  2282. }
  2283. }
  2284. }
  2285. /*******************************************************************************
  2286. **
  2287. ** Function btm_acl_free
  2288. **
  2289. ** Description Free acl specific lists from btm control block
  2290. **
  2291. *******************************************************************************/
  2292. void btm_acl_free(void)
  2293. {
  2294. list_free(btm_cb.p_acl_db_list);
  2295. list_free(btm_cb.p_pm_mode_db_list);
  2296. }