btm_acl.c 92 KB

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