l2c_ble.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2009-2012 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. /******************************************************************************
  19. *
  20. * this file contains functions relating to BLE management.
  21. *
  22. ******************************************************************************/
  23. #include <string.h>
  24. #include "bt_target.h"
  25. //#include "bt_utils.h"
  26. #include "l2cdefs.h"
  27. #include "l2c_int.h"
  28. #include "btu.h"
  29. #include "btm_int.h"
  30. #include "hcimsgs.h"
  31. #include "controller.h"
  32. #if (BLE_INCLUDED == TRUE)
  33. static void l2cble_start_conn_update (tL2C_LCB *p_lcb);
  34. /*******************************************************************************
  35. **
  36. ** Function L2CA_CancelBleConnectReq
  37. **
  38. ** Description Cancel a pending connection attempt to a BLE device.
  39. **
  40. ** Parameters: BD Address of remote
  41. **
  42. ** Return value: TRUE if connection was cancelled
  43. **
  44. *******************************************************************************/
  45. BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda)
  46. {
  47. tL2C_LCB *p_lcb;
  48. /* There can be only one BLE connection request outstanding at a time */
  49. if (btm_ble_get_conn_st() == BLE_CONN_IDLE) {
  50. L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - no connection pending");
  51. return (FALSE);
  52. }
  53. if (memcmp (rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN)) {
  54. L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - different BDA Connecting: %08x%04x Cancel: %08x%04x",
  55. (l2cb.ble_connecting_bda[0] << 24) + (l2cb.ble_connecting_bda[1] << 16) + (l2cb.ble_connecting_bda[2] << 8) + l2cb.ble_connecting_bda[3],
  56. (l2cb.ble_connecting_bda[4] << 8) + l2cb.ble_connecting_bda[5],
  57. (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5]);
  58. return (FALSE);
  59. }
  60. if (btsnd_hcic_ble_create_conn_cancel()) {
  61. p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE);
  62. /* Do not remove lcb if an LE link is already up as a peripheral */
  63. if (p_lcb != NULL &&
  64. !(p_lcb->link_role == HCI_ROLE_SLAVE && BTM_ACL_IS_CONNECTED(rem_bda))) {
  65. p_lcb->disc_reason = L2CAP_CONN_CANCEL;
  66. l2cu_release_lcb (p_lcb);
  67. }
  68. /* update state to be cancel, wait for connection cancel complete */
  69. btm_ble_set_conn_st (BLE_CONN_CANCEL);
  70. return (TRUE);
  71. } else {
  72. return (FALSE);
  73. }
  74. }
  75. /*******************************************************************************
  76. **
  77. ** Function L2CA_UpdateBleConnParams
  78. **
  79. ** Description Update BLE connection parameters.
  80. **
  81. ** Parameters: BD Address of remote
  82. **
  83. ** Return value: TRUE if update started
  84. **
  85. *******************************************************************************/
  86. BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_int,
  87. UINT16 latency, UINT16 timeout)
  88. {
  89. tL2C_LCB *p_lcb;
  90. tACL_CONN *p_acl_cb = btm_bda_to_acl(rem_bda, BT_TRANSPORT_LE);
  91. /* See if we have a link control block for the remote device */
  92. p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE);
  93. /* If we don't have one, create one and accept the connection. */
  94. if (!p_lcb || !p_acl_cb) {
  95. L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - unknown BD_ADDR %08x%04x",
  96. (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
  97. (rem_bda[4] << 8) + rem_bda[5]);
  98. return (FALSE);
  99. }
  100. if (p_lcb->transport != BT_TRANSPORT_LE) {
  101. L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - BD_ADDR %08x%04x not LE",
  102. (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
  103. (rem_bda[4] << 8) + rem_bda[5]);
  104. return (FALSE);
  105. }
  106. p_lcb->min_interval = min_int;
  107. p_lcb->max_interval = max_int;
  108. p_lcb->latency = latency;
  109. p_lcb->timeout = timeout;
  110. p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
  111. l2cble_start_conn_update(p_lcb);
  112. return (TRUE);
  113. }
  114. /*******************************************************************************
  115. **
  116. ** Function L2CA_EnableUpdateBleConnParams
  117. **
  118. ** Description Enable or disable update based on the request from the peer
  119. **
  120. ** Parameters: BD Address of remote
  121. **
  122. ** Return value: TRUE if update started
  123. **
  124. *******************************************************************************/
  125. BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable)
  126. {
  127. tL2C_LCB *p_lcb;
  128. /* See if we have a link control block for the remote device */
  129. p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE);
  130. if (!p_lcb) {
  131. L2CAP_TRACE_WARNING ("L2CA_EnableUpdateBleConnParams - unknown BD_ADDR %08x%04x",
  132. (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
  133. (rem_bda[4] << 8) + rem_bda[5]);
  134. return (FALSE);
  135. }
  136. L2CAP_TRACE_API ("%s - BD_ADDR %08x%04x enable %d current upd state 0x%02x", __FUNCTION__,
  137. (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
  138. (rem_bda[4] << 8) + rem_bda[5], enable, p_lcb->conn_update_mask);
  139. if (p_lcb->transport != BT_TRANSPORT_LE) {
  140. L2CAP_TRACE_WARNING ("%s - BD_ADDR %08x%04x not LE (link role %d)", __FUNCTION__,
  141. (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
  142. (rem_bda[4] << 8) + rem_bda[5], p_lcb->link_role);
  143. return (FALSE);
  144. }
  145. if (enable) {
  146. p_lcb->conn_update_mask &= ~L2C_BLE_CONN_UPDATE_DISABLE;
  147. } else {
  148. p_lcb->conn_update_mask |= L2C_BLE_CONN_UPDATE_DISABLE;
  149. }
  150. l2cble_start_conn_update(p_lcb);
  151. return (TRUE);
  152. }
  153. /*******************************************************************************
  154. **
  155. ** Function L2CA_GetBleConnRole
  156. **
  157. ** Description This function returns the connection role.
  158. **
  159. ** Returns link role.
  160. **
  161. *******************************************************************************/
  162. UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr)
  163. {
  164. UINT8 role = HCI_ROLE_UNKNOWN;
  165. tL2C_LCB *p_lcb;
  166. if ((p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_LE)) != NULL) {
  167. role = p_lcb->link_role;
  168. }
  169. return role;
  170. }
  171. /*******************************************************************************
  172. **
  173. ** Function L2CA_GetDisconnectReason
  174. **
  175. ** Description This function returns the disconnect reason code.
  176. **
  177. ** Returns disconnect reason
  178. **
  179. *******************************************************************************/
  180. UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport)
  181. {
  182. tL2C_LCB *p_lcb;
  183. UINT16 reason = 0;
  184. if ((p_lcb = l2cu_find_lcb_by_bd_addr (remote_bda, transport)) != NULL) {
  185. reason = p_lcb->disc_reason;
  186. }
  187. L2CAP_TRACE_DEBUG ("L2CA_GetDisconnectReason=%d ", reason);
  188. return reason;
  189. }
  190. /*******************************************************************************
  191. **
  192. ** Function l2cble_notify_le_connection
  193. **
  194. ** Description This function notifiy the l2cap connection to the app layer
  195. **
  196. ** Returns none
  197. **
  198. *******************************************************************************/
  199. void l2cble_notify_le_connection (BD_ADDR bda)
  200. {
  201. tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE);
  202. tACL_CONN *p_acl = btm_bda_to_acl(bda, BT_TRANSPORT_LE) ;
  203. if (p_lcb != NULL && p_acl != NULL && p_lcb->link_state != LST_CONNECTED) {
  204. /* update link status */
  205. btm_establish_continue(p_acl);
  206. /* update l2cap link status and send callback */
  207. p_lcb->link_state = LST_CONNECTED;
  208. l2cu_process_fixed_chnl_resp (p_lcb);
  209. }
  210. }
  211. /*******************************************************************************
  212. **
  213. ** Function l2cble_scanner_conn_comp
  214. **
  215. ** Description This function is called when an HCI Connection Complete
  216. ** event is received while we are a scanner (so we are master).
  217. **
  218. ** Returns void
  219. **
  220. *******************************************************************************/
  221. void l2cble_scanner_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type,
  222. UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout)
  223. {
  224. tL2C_LCB *p_lcb;
  225. tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (bda);
  226. L2CAP_TRACE_DEBUG ("l2cble_scanner_conn_comp: HANDLE=%d addr_type=%d conn_interval=%d slave_latency=%d supervision_tout=%d",
  227. handle, type, conn_interval, conn_latency, conn_timeout);
  228. l2cb.is_ble_connecting = FALSE;
  229. /* See if we have a link control block for the remote device */
  230. p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE);
  231. /* If we don't have one, create one. this is auto connection complete. */
  232. if (!p_lcb) {
  233. p_lcb = l2cu_allocate_lcb (bda, FALSE, BT_TRANSPORT_LE);
  234. if (!p_lcb) {
  235. btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION);
  236. L2CAP_TRACE_ERROR ("l2cble_scanner_conn_comp - failed to allocate LCB");
  237. return;
  238. } else {
  239. if (!l2cu_initialize_fixed_ccb (p_lcb, L2CAP_ATT_CID, &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) {
  240. btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION);
  241. L2CAP_TRACE_WARNING ("l2cble_scanner_conn_comp - LCB but no CCB");
  242. return ;
  243. }
  244. }
  245. } else if (p_lcb->link_state != LST_CONNECTING) {
  246. L2CAP_TRACE_ERROR ("L2CAP got BLE scanner conn_comp in bad state: %d", p_lcb->link_state);
  247. return;
  248. }
  249. btu_stop_timer(&p_lcb->timer_entry);
  250. /* Save the handle */
  251. p_lcb->handle = handle;
  252. /* Connected OK. Change state to connected, we were scanning so we are master */
  253. p_lcb->link_role = HCI_ROLE_MASTER;
  254. p_lcb->transport = BT_TRANSPORT_LE;
  255. /* update link parameter, set slave link as non-spec default upon link up */
  256. p_lcb->min_interval = p_lcb->max_interval = conn_interval;
  257. p_lcb->timeout = conn_timeout;
  258. p_lcb->latency = conn_latency;
  259. p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM;
  260. /* If there are any preferred connection parameters, set them now */
  261. if ( (p_dev_rec->conn_params.min_conn_int >= BTM_BLE_CONN_INT_MIN ) &&
  262. (p_dev_rec->conn_params.min_conn_int <= BTM_BLE_CONN_INT_MAX ) &&
  263. (p_dev_rec->conn_params.max_conn_int >= BTM_BLE_CONN_INT_MIN ) &&
  264. (p_dev_rec->conn_params.max_conn_int <= BTM_BLE_CONN_INT_MAX ) &&
  265. (p_dev_rec->conn_params.slave_latency <= BTM_BLE_CONN_LATENCY_MAX ) &&
  266. (p_dev_rec->conn_params.supervision_tout >= BTM_BLE_CONN_SUP_TOUT_MIN) &&
  267. (p_dev_rec->conn_params.supervision_tout <= BTM_BLE_CONN_SUP_TOUT_MAX) &&
  268. ((conn_interval < p_dev_rec->conn_params.min_conn_int &&
  269. p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ||
  270. (conn_interval > p_dev_rec->conn_params.max_conn_int) ||
  271. (conn_latency > p_dev_rec->conn_params.slave_latency) ||
  272. (conn_timeout > p_dev_rec->conn_params.supervision_tout))) {
  273. L2CAP_TRACE_ERROR ("upd_ll_conn_params: HANDLE=%d min_conn_int=%d max_conn_int=%d slave_latency=%d supervision_tout=%d",
  274. handle, p_dev_rec->conn_params.min_conn_int, p_dev_rec->conn_params.max_conn_int,
  275. p_dev_rec->conn_params.slave_latency, p_dev_rec->conn_params.supervision_tout);
  276. p_lcb->min_interval = p_dev_rec->conn_params.min_conn_int;
  277. p_lcb->max_interval = p_dev_rec->conn_params.max_conn_int;
  278. p_lcb->timeout = p_dev_rec->conn_params.supervision_tout;
  279. p_lcb->latency = p_dev_rec->conn_params.slave_latency;
  280. btsnd_hcic_ble_upd_ll_conn_params (handle,
  281. p_dev_rec->conn_params.min_conn_int,
  282. p_dev_rec->conn_params.max_conn_int,
  283. p_dev_rec->conn_params.slave_latency,
  284. p_dev_rec->conn_params.supervision_tout,
  285. 0, 0);
  286. }
  287. /* Tell BTM Acl management about the link */
  288. btm_acl_created (bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, BT_TRANSPORT_LE);
  289. p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT;
  290. btm_ble_set_conn_st(BLE_CONN_IDLE);
  291. #if BLE_PRIVACY_SPT == TRUE
  292. btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, TRUE);
  293. #endif
  294. }
  295. /*******************************************************************************
  296. **
  297. ** Function l2cble_advertiser_conn_comp
  298. **
  299. ** Description This function is called when an HCI Connection Complete
  300. ** event is received while we are an advertiser (so we are slave).
  301. **
  302. ** Returns void
  303. **
  304. *******************************************************************************/
  305. void l2cble_advertiser_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type,
  306. UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout)
  307. {
  308. tL2C_LCB *p_lcb;
  309. tBTM_SEC_DEV_REC *p_dev_rec;
  310. UNUSED(type);
  311. UNUSED(conn_interval);
  312. UNUSED(conn_latency);
  313. UNUSED(conn_timeout);
  314. /* See if we have a link control block for the remote device */
  315. p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE);
  316. /* If we don't have one, create one and accept the connection. */
  317. if (!p_lcb) {
  318. p_lcb = l2cu_allocate_lcb (bda, FALSE, BT_TRANSPORT_LE);
  319. if (!p_lcb) {
  320. btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION);
  321. L2CAP_TRACE_ERROR ("l2cble_advertiser_conn_comp - failed to allocate LCB");
  322. return;
  323. } else {
  324. if (!l2cu_initialize_fixed_ccb (p_lcb, L2CAP_ATT_CID, &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) {
  325. btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION);
  326. L2CAP_TRACE_WARNING ("l2cble_scanner_conn_comp - LCB but no CCB");
  327. return ;
  328. }
  329. }
  330. }
  331. /* Save the handle */
  332. p_lcb->handle = handle;
  333. /* Connected OK. Change state to connected, we were advertising, so we are slave */
  334. p_lcb->link_role = HCI_ROLE_SLAVE;
  335. p_lcb->transport = BT_TRANSPORT_LE;
  336. /* update link parameter, set slave link as non-spec default upon link up */
  337. p_lcb->min_interval = p_lcb->max_interval = conn_interval;
  338. p_lcb->timeout = conn_timeout;
  339. p_lcb->latency = conn_latency;
  340. p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM;
  341. /* Tell BTM Acl management about the link */
  342. p_dev_rec = btm_find_or_alloc_dev (bda);
  343. btm_acl_created (bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, BT_TRANSPORT_LE);
  344. #if BLE_PRIVACY_SPT == TRUE
  345. btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
  346. #endif
  347. p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT;
  348. if (!HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(controller_get_interface()->get_features_ble()->as_array)) {
  349. p_lcb->link_state = LST_CONNECTED;
  350. l2cu_process_fixed_chnl_resp (p_lcb);
  351. }
  352. /* when adv and initiating are both active, cancel the direct connection */
  353. if (l2cb.is_ble_connecting && memcmp(bda, l2cb.ble_connecting_bda, BD_ADDR_LEN) == 0) {
  354. L2CA_CancelBleConnectReq(bda);
  355. }
  356. }
  357. /*******************************************************************************
  358. **
  359. ** Function l2cble_conn_comp
  360. **
  361. ** Description This function is called when an HCI Connection Complete
  362. ** event is received.
  363. **
  364. ** Returns void
  365. **
  366. *******************************************************************************/
  367. void l2cble_conn_comp(UINT16 handle, UINT8 role, BD_ADDR bda, tBLE_ADDR_TYPE type,
  368. UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout)
  369. {
  370. btm_ble_update_link_topology_mask(role, TRUE);
  371. if (role == HCI_ROLE_MASTER) {
  372. l2cble_scanner_conn_comp(handle, bda, type, conn_interval, conn_latency, conn_timeout);
  373. } else {
  374. l2cble_advertiser_conn_comp(handle, bda, type, conn_interval, conn_latency, conn_timeout);
  375. }
  376. }
  377. /*******************************************************************************
  378. **
  379. ** Function l2cble_start_conn_update
  380. **
  381. ** Description start BLE connection parameter update process based on status
  382. **
  383. ** Parameters: lcb : l2cap link control block
  384. **
  385. ** Return value: none
  386. **
  387. *******************************************************************************/
  388. static void l2cble_start_conn_update (tL2C_LCB *p_lcb)
  389. {
  390. UINT16 min_conn_int, max_conn_int, slave_latency, supervision_tout;
  391. tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE);
  392. if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PENDING) {
  393. return;
  394. }
  395. if (p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) {
  396. /* application requests to disable parameters update.
  397. If parameters are already updated, lets set them
  398. up to what has been requested during connection establishement */
  399. if (p_lcb->conn_update_mask & L2C_BLE_NOT_DEFAULT_PARAM &&
  400. /* current connection interval is greater than default min */
  401. p_lcb->min_interval > BTM_BLE_CONN_INT_MIN) {
  402. /* use 7.5 ms as fast connection parameter, 0 slave latency */
  403. min_conn_int = max_conn_int = BTM_BLE_CONN_INT_MIN;
  404. slave_latency = BTM_BLE_CONN_SLAVE_LATENCY_DEF;
  405. supervision_tout = BTM_BLE_CONN_TIMEOUT_DEF;
  406. /* if both side 4.1, or we are master device, send HCI command */
  407. if (p_lcb->link_role == HCI_ROLE_MASTER
  408. #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
  409. || (HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) &&
  410. HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features))
  411. #endif
  412. ) {
  413. btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, min_conn_int, max_conn_int,
  414. slave_latency, supervision_tout, 0, 0);
  415. p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
  416. } else {
  417. l2cu_send_peer_ble_par_req (p_lcb, min_conn_int, max_conn_int, slave_latency, supervision_tout);
  418. }
  419. p_lcb->conn_update_mask &= ~L2C_BLE_NOT_DEFAULT_PARAM;
  420. p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
  421. }
  422. } else {
  423. /* application allows to do update, if we were delaying one do it now */
  424. if (p_lcb->conn_update_mask & L2C_BLE_NEW_CONN_PARAM) {
  425. /* if both side 4.1, or we are master device, send HCI command */
  426. if (p_lcb->link_role == HCI_ROLE_MASTER
  427. #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
  428. || (HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) &&
  429. HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features))
  430. #endif
  431. ) {
  432. btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, p_lcb->min_interval,
  433. p_lcb->max_interval, p_lcb->latency, p_lcb->timeout, 0, 0);
  434. p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
  435. } else {
  436. l2cu_send_peer_ble_par_req (p_lcb, p_lcb->min_interval, p_lcb->max_interval,
  437. p_lcb->latency, p_lcb->timeout);
  438. }
  439. p_lcb->conn_update_mask &= ~L2C_BLE_NEW_CONN_PARAM;
  440. p_lcb->conn_update_mask |= L2C_BLE_NOT_DEFAULT_PARAM;
  441. }
  442. }
  443. }
  444. /*******************************************************************************
  445. **
  446. ** Function l2cble_process_conn_update_evt
  447. **
  448. ** Description This function enables the connection update request from remote
  449. ** after a successful connection update response is received.
  450. **
  451. ** Returns void
  452. **
  453. *******************************************************************************/
  454. void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status)
  455. {
  456. tL2C_LCB *p_lcb;
  457. L2CAP_TRACE_DEBUG("l2cble_process_conn_update_evt");
  458. /* See if we have a link control block for the remote device */
  459. p_lcb = l2cu_find_lcb_by_handle(handle);
  460. if (!p_lcb) {
  461. L2CAP_TRACE_WARNING("l2cble_process_conn_update_evt: Invalid handle: %d", handle);
  462. return;
  463. }
  464. p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING;
  465. if (status != HCI_SUCCESS) {
  466. L2CAP_TRACE_WARNING("l2cble_process_conn_update_evt: Error status: %d", status);
  467. }
  468. l2cble_start_conn_update(p_lcb);
  469. L2CAP_TRACE_DEBUG("l2cble_process_conn_update_evt: conn_update_mask=%d", p_lcb->conn_update_mask);
  470. }
  471. /*******************************************************************************
  472. **
  473. ** Function l2cble_process_sig_cmd
  474. **
  475. ** Description This function is called when a signalling packet is received
  476. ** on the BLE signalling CID
  477. **
  478. ** Returns void
  479. **
  480. *******************************************************************************/
  481. void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len)
  482. {
  483. UINT8 *p_pkt_end;
  484. UINT8 cmd_code, id;
  485. UINT16 cmd_len;
  486. UINT16 min_interval, max_interval, latency, timeout;
  487. p_pkt_end = p + pkt_len;
  488. STREAM_TO_UINT8 (cmd_code, p);
  489. STREAM_TO_UINT8 (id, p);
  490. STREAM_TO_UINT16 (cmd_len, p);
  491. /* Check command length does not exceed packet length */
  492. if ((p + cmd_len) > p_pkt_end) {
  493. L2CAP_TRACE_WARNING ("L2CAP - LE - format error, pkt_len: %d cmd_len: %d code: %d", pkt_len, cmd_len, cmd_code);
  494. return;
  495. }
  496. switch (cmd_code) {
  497. case L2CAP_CMD_REJECT:
  498. case L2CAP_CMD_ECHO_RSP:
  499. case L2CAP_CMD_INFO_RSP:
  500. p += 2;
  501. break;
  502. case L2CAP_CMD_ECHO_REQ:
  503. case L2CAP_CMD_INFO_REQ:
  504. l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0);
  505. break;
  506. case L2CAP_CMD_BLE_UPDATE_REQ:
  507. STREAM_TO_UINT16 (min_interval, p); /* 0x0006 - 0x0C80 */
  508. STREAM_TO_UINT16 (max_interval, p); /* 0x0006 - 0x0C80 */
  509. STREAM_TO_UINT16 (latency, p); /* 0x0000 - 0x03E8 */
  510. STREAM_TO_UINT16 (timeout, p); /* 0x000A - 0x0C80 */
  511. /* If we are a master, the slave wants to update the parameters */
  512. if (p_lcb->link_role == HCI_ROLE_MASTER) {
  513. if (min_interval < BTM_BLE_CONN_INT_MIN_LIMIT) {
  514. min_interval = BTM_BLE_CONN_INT_MIN_LIMIT;
  515. }
  516. if (min_interval < BTM_BLE_CONN_INT_MIN || min_interval > BTM_BLE_CONN_INT_MAX ||
  517. max_interval < BTM_BLE_CONN_INT_MIN || max_interval > BTM_BLE_CONN_INT_MAX ||
  518. latency > BTM_BLE_CONN_LATENCY_MAX ||
  519. /*(timeout >= max_interval && latency > (timeout * 10/(max_interval * 1.25) - 1)) ||*/
  520. timeout < BTM_BLE_CONN_SUP_TOUT_MIN || timeout > BTM_BLE_CONN_SUP_TOUT_MAX ||
  521. max_interval < min_interval) {
  522. l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_UNACCEPTABLE_PARAMS, id);
  523. } else {
  524. l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_OK, id);
  525. p_lcb->min_interval = min_interval;
  526. p_lcb->max_interval = max_interval;
  527. p_lcb->latency = latency;
  528. p_lcb->timeout = timeout;
  529. p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
  530. l2cble_start_conn_update(p_lcb);
  531. }
  532. } else {
  533. l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0);
  534. }
  535. break;
  536. case L2CAP_CMD_BLE_UPDATE_RSP:
  537. p += 2;
  538. break;
  539. default:
  540. L2CAP_TRACE_WARNING ("L2CAP - LE - unknown cmd code: %d", cmd_code);
  541. l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0);
  542. return;
  543. }
  544. }
  545. /*******************************************************************************
  546. **
  547. ** Function l2cble_init_direct_conn
  548. **
  549. ** Description This function is to initate a direct connection
  550. **
  551. ** Returns TRUE connection initiated, FALSE otherwise.
  552. **
  553. *******************************************************************************/
  554. BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb)
  555. {
  556. tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_lcb->remote_bd_addr);
  557. tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
  558. UINT16 scan_int;
  559. UINT16 scan_win;
  560. BD_ADDR peer_addr;
  561. UINT8 peer_addr_type = BLE_ADDR_PUBLIC;
  562. UINT8 own_addr_type = BLE_ADDR_PUBLIC;
  563. /* There can be only one BLE connection request outstanding at a time */
  564. if (p_dev_rec == NULL) {
  565. L2CAP_TRACE_WARNING ("unknown device, can not initate connection");
  566. return (FALSE);
  567. }
  568. scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int;
  569. scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win;
  570. peer_addr_type = p_lcb->ble_addr_type;
  571. memcpy(peer_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN);
  572. #if ( (defined BLE_PRIVACY_SPT) && (BLE_PRIVACY_SPT == TRUE))
  573. own_addr_type = btm_cb.ble_ctr_cb.privacy_mode ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC;
  574. if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) {
  575. if (btm_cb.ble_ctr_cb.privacy_mode >= BTM_PRIVACY_1_2) {
  576. own_addr_type |= BLE_ADDR_TYPE_ID_BIT;
  577. }
  578. btm_ble_enable_resolving_list(BTM_BLE_RL_INIT);
  579. btm_random_pseudo_to_identity_addr(peer_addr, &peer_addr_type);
  580. } else {
  581. btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, TRUE);
  582. }
  583. #endif
  584. if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) {
  585. l2cu_release_lcb (p_lcb);
  586. L2CAP_TRACE_ERROR("initate direct connection fail, topology limitation");
  587. return FALSE;
  588. }
  589. if (!btsnd_hcic_ble_create_ll_conn (scan_int,/* UINT16 scan_int */
  590. scan_win, /* UINT16 scan_win */
  591. FALSE, /* UINT8 white_list */
  592. peer_addr_type, /* UINT8 addr_type_peer */
  593. peer_addr, /* BD_ADDR bda_peer */
  594. own_addr_type, /* UINT8 addr_type_own */
  595. (UINT16) ((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ?
  596. p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* UINT16 conn_int_min */
  597. (UINT16) ((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ?
  598. p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* UINT16 conn_int_max */
  599. (UINT16) ((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ?
  600. p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* UINT16 conn_latency */
  601. (UINT16) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ?
  602. p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), /* conn_timeout */
  603. 0, /* UINT16 min_len */
  604. 0)) { /* UINT16 max_len */
  605. l2cu_release_lcb (p_lcb);
  606. L2CAP_TRACE_ERROR("initate direct connection fail, no resources");
  607. return (FALSE);
  608. } else {
  609. p_lcb->link_state = LST_CONNECTING;
  610. l2cb.is_ble_connecting = TRUE;
  611. memcpy (l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN);
  612. btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_BLE_LINK_CONNECT_TOUT);
  613. btm_ble_set_conn_st (BLE_DIR_CONN);
  614. return (TRUE);
  615. }
  616. }
  617. /*******************************************************************************
  618. **
  619. ** Function l2cble_create_conn
  620. **
  621. ** Description This function initiates an acl connection via HCI
  622. **
  623. ** Returns TRUE if successful, FALSE if connection not started.
  624. **
  625. *******************************************************************************/
  626. BOOLEAN l2cble_create_conn (tL2C_LCB *p_lcb)
  627. {
  628. tBTM_BLE_CONN_ST conn_st = btm_ble_get_conn_st();
  629. BOOLEAN rt = FALSE;
  630. /* There can be only one BLE connection request outstanding at a time */
  631. if (conn_st == BLE_CONN_IDLE) {
  632. rt = l2cble_init_direct_conn(p_lcb);
  633. } else {
  634. L2CAP_TRACE_WARNING ("L2CAP - LE - cannot start new connection at conn st: %d", conn_st);
  635. btm_ble_enqueue_direct_conn_req(p_lcb);
  636. if (conn_st == BLE_BG_CONN) {
  637. btm_ble_suspend_bg_conn();
  638. }
  639. rt = TRUE;
  640. }
  641. return rt;
  642. }
  643. /*******************************************************************************
  644. **
  645. ** Function l2c_link_processs_ble_num_bufs
  646. **
  647. ** Description This function is called when a "controller buffer size"
  648. ** event is first received from the controller. It updates
  649. ** the L2CAP values.
  650. **
  651. ** Returns void
  652. **
  653. *******************************************************************************/
  654. void l2c_link_processs_ble_num_bufs (UINT16 num_lm_ble_bufs)
  655. {
  656. if (num_lm_ble_bufs == 0) {
  657. num_lm_ble_bufs = L2C_DEF_NUM_BLE_BUF_SHARED;
  658. l2cb.num_lm_acl_bufs -= L2C_DEF_NUM_BLE_BUF_SHARED;
  659. }
  660. l2cb.num_lm_ble_bufs = l2cb.controller_le_xmit_window = num_lm_ble_bufs;
  661. }
  662. /*******************************************************************************
  663. **
  664. ** Function l2c_ble_link_adjust_allocation
  665. **
  666. ** Description This function is called when a link is created or removed
  667. ** to calculate the amount of packets each link may send to
  668. ** the HCI without an ack coming back.
  669. **
  670. ** Currently, this is a simple allocation, dividing the
  671. ** number of Controller Packets by the number of links. In
  672. ** the future, QOS configuration should be examined.
  673. **
  674. ** Returns void
  675. **
  676. *******************************************************************************/
  677. void l2c_ble_link_adjust_allocation (void)
  678. {
  679. UINT16 qq, yy, qq_remainder;
  680. tL2C_LCB *p_lcb;
  681. UINT16 hi_quota, low_quota;
  682. UINT16 num_lowpri_links = 0;
  683. UINT16 num_hipri_links = 0;
  684. UINT16 controller_xmit_quota = l2cb.num_lm_ble_bufs;
  685. UINT16 high_pri_link_quota = L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A;
  686. /* If no links active, reset buffer quotas and controller buffers */
  687. if (l2cb.num_ble_links_active == 0) {
  688. l2cb.controller_le_xmit_window = l2cb.num_lm_ble_bufs;
  689. l2cb.ble_round_robin_quota = l2cb.ble_round_robin_unacked = 0;
  690. return;
  691. }
  692. /* First, count the links */
  693. for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) {
  694. if (p_lcb->in_use && p_lcb->transport == BT_TRANSPORT_LE) {
  695. if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) {
  696. num_hipri_links++;
  697. } else {
  698. num_lowpri_links++;
  699. }
  700. }
  701. }
  702. /* now adjust high priority link quota */
  703. low_quota = num_lowpri_links ? 1 : 0;
  704. while ( (num_hipri_links * high_pri_link_quota + low_quota) > controller_xmit_quota ) {
  705. high_pri_link_quota--;
  706. }
  707. /* Work out the xmit quota and buffer quota high and low priorities */
  708. hi_quota = num_hipri_links * high_pri_link_quota;
  709. low_quota = (hi_quota < controller_xmit_quota) ? controller_xmit_quota - hi_quota : 1;
  710. /* Work out and save the HCI xmit quota for each low priority link */
  711. /* If each low priority link cannot have at least one buffer */
  712. if (num_lowpri_links > low_quota) {
  713. l2cb.ble_round_robin_quota = low_quota;
  714. qq = qq_remainder = 0;
  715. }
  716. /* If each low priority link can have at least one buffer */
  717. else if (num_lowpri_links > 0) {
  718. l2cb.ble_round_robin_quota = 0;
  719. l2cb.ble_round_robin_unacked = 0;
  720. qq = low_quota / num_lowpri_links;
  721. qq_remainder = low_quota % num_lowpri_links;
  722. }
  723. /* If no low priority link */
  724. else {
  725. l2cb.ble_round_robin_quota = 0;
  726. l2cb.ble_round_robin_unacked = 0;
  727. qq = qq_remainder = 0;
  728. }
  729. L2CAP_TRACE_EVENT ("l2c_ble_link_adjust_allocation num_hipri: %u num_lowpri: %u low_quota: %u round_robin_quota: %u qq: %u",
  730. num_hipri_links, num_lowpri_links, low_quota,
  731. l2cb.ble_round_robin_quota, qq);
  732. /* Now, assign the quotas to each link */
  733. for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) {
  734. if (p_lcb->in_use && p_lcb->transport == BT_TRANSPORT_LE) {
  735. if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) {
  736. p_lcb->link_xmit_quota = high_pri_link_quota;
  737. } else {
  738. /* Safety check in case we switched to round-robin with something outstanding */
  739. /* if sent_not_acked is added into round_robin_unacked then don't add it again */
  740. /* l2cap keeps updating sent_not_acked for exiting from round robin */
  741. if (( p_lcb->link_xmit_quota > 0 ) && ( qq == 0 )) {
  742. l2cb.ble_round_robin_unacked += p_lcb->sent_not_acked;
  743. }
  744. p_lcb->link_xmit_quota = qq;
  745. if (qq_remainder > 0) {
  746. p_lcb->link_xmit_quota++;
  747. qq_remainder--;
  748. }
  749. }
  750. L2CAP_TRACE_EVENT("l2c_ble_link_adjust_allocation LCB %d Priority: %d XmitQuota: %d",
  751. yy, p_lcb->acl_priority, p_lcb->link_xmit_quota);
  752. L2CAP_TRACE_EVENT(" SentNotAcked: %d RRUnacked: %d",
  753. p_lcb->sent_not_acked, l2cb.round_robin_unacked);
  754. /* There is a special case where we have readjusted the link quotas and */
  755. /* this link may have sent anything but some other link sent packets so */
  756. /* so we may need a timer to kick off this link's transmissions. */
  757. if ( (p_lcb->link_state == LST_CONNECTED)
  758. && (!list_is_empty(p_lcb->link_xmit_data_q))
  759. && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) ) {
  760. btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_FLOW_CONTROL_TOUT);
  761. }
  762. }
  763. }
  764. }
  765. #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
  766. /*******************************************************************************
  767. **
  768. ** Function l2cble_process_rc_param_request_evt
  769. **
  770. ** Description process LE Remote Connection Parameter Request Event.
  771. **
  772. ** Returns void
  773. **
  774. *******************************************************************************/
  775. void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, UINT16 int_max,
  776. UINT16 latency, UINT16 timeout)
  777. {
  778. tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle (handle);
  779. if (p_lcb != NULL) {
  780. p_lcb->min_interval = int_min;
  781. p_lcb->max_interval = int_max;
  782. p_lcb->latency = latency;
  783. p_lcb->timeout = timeout;
  784. /* if update is enabled, always accept connection parameter update */
  785. if ((p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) == 0) {
  786. btsnd_hcic_ble_rc_param_req_reply(handle, int_min, int_max, latency, timeout, 0, 0);
  787. } else {
  788. L2CAP_TRACE_EVENT ("L2CAP - LE - update currently disabled");
  789. p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
  790. btsnd_hcic_ble_rc_param_req_neg_reply (handle, HCI_ERR_UNACCEPT_CONN_INTERVAL);
  791. }
  792. } else {
  793. L2CAP_TRACE_WARNING("No link to update connection parameter")
  794. }
  795. }
  796. #endif
  797. /*******************************************************************************
  798. **
  799. ** Function l2cble_update_data_length
  800. **
  801. ** Description This function update link tx data length if applicable
  802. **
  803. ** Returns void
  804. **
  805. *******************************************************************************/
  806. void l2cble_update_data_length(tL2C_LCB *p_lcb)
  807. {
  808. UINT16 tx_mtu = 0;
  809. UINT16 i = 0;
  810. L2CAP_TRACE_DEBUG("%s", __FUNCTION__);
  811. /* See if we have a link control block for the connection */
  812. if (p_lcb == NULL) {
  813. return;
  814. }
  815. for (i = 0; i < L2CAP_NUM_FIXED_CHNLS; i++) {
  816. if (i + L2CAP_FIRST_FIXED_CHNL != L2CAP_BLE_SIGNALLING_CID) {
  817. if ((p_lcb->p_fixed_ccbs[i] != NULL) &&
  818. (tx_mtu < (p_lcb->p_fixed_ccbs[i]->tx_data_len + L2CAP_PKT_OVERHEAD))) {
  819. tx_mtu = p_lcb->p_fixed_ccbs[i]->tx_data_len + L2CAP_PKT_OVERHEAD;
  820. }
  821. }
  822. }
  823. if (tx_mtu > BTM_BLE_DATA_SIZE_MAX) {
  824. tx_mtu = BTM_BLE_DATA_SIZE_MAX;
  825. }
  826. /* update TX data length if changed */
  827. if (p_lcb->tx_data_len != tx_mtu) {
  828. BTM_SetBleDataLength(p_lcb->remote_bd_addr, tx_mtu);
  829. }
  830. }
  831. /*******************************************************************************
  832. **
  833. ** Function l2cble_process_data_length_change_evt
  834. **
  835. ** Description This function process the data length change event
  836. **
  837. ** Returns void
  838. **
  839. *******************************************************************************/
  840. void l2cble_process_data_length_change_event(UINT16 handle, UINT16 tx_data_len, UINT16 rx_data_len)
  841. {
  842. tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle(handle);
  843. L2CAP_TRACE_DEBUG("%s TX data len = %d", __FUNCTION__, tx_data_len);
  844. if (p_lcb == NULL) {
  845. return;
  846. }
  847. if (tx_data_len > 0) {
  848. p_lcb->tx_data_len = tx_data_len;
  849. }
  850. /* ignore rx_data len for now */
  851. }
  852. /*******************************************************************************
  853. **
  854. ** Function l2cble_set_fixed_channel_tx_data_length
  855. **
  856. ** Description This function update max fixed channel tx data length if applicable
  857. **
  858. ** Returns void
  859. **
  860. *******************************************************************************/
  861. void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, UINT16 fix_cid, UINT16 tx_mtu)
  862. {
  863. tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(remote_bda, BT_TRANSPORT_LE);
  864. UINT16 cid = fix_cid - L2CAP_FIRST_FIXED_CHNL;
  865. L2CAP_TRACE_DEBUG("%s TX MTU = %d", __FUNCTION__, tx_mtu);
  866. if (!controller_get_interface()->supports_ble_packet_extension()) {
  867. L2CAP_TRACE_WARNING("%s, request not supported", __FUNCTION__);
  868. return;
  869. }
  870. /* See if we have a link control block for the connection */
  871. if (p_lcb == NULL) {
  872. return;
  873. }
  874. if (p_lcb->p_fixed_ccbs[cid] != NULL) {
  875. if (tx_mtu > BTM_BLE_DATA_SIZE_MAX) {
  876. tx_mtu = BTM_BLE_DATA_SIZE_MAX;
  877. }
  878. p_lcb->p_fixed_ccbs[cid]->tx_data_len = tx_mtu;
  879. }
  880. l2cble_update_data_length(p_lcb);
  881. }
  882. #endif /* (BLE_INCLUDED == TRUE) */