1 /*
2  * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <string.h>
8 #include "esp_gatt_common_api.h"
9 #include "esp_bt_main.h"
10 #include "esp_gatt_defs.h"
11 #include "btc_gatt_common.h"
12 
13 /**
14  * @brief           This function is called to set local MTU,
15  *                  the function is called before BLE connection.
16  *
17  * @param[in]       mtu: the size of MTU.
18  *
19  * @return
20  *                  - ESP_OK: success
21  *                  - other: failed
22  *
23  */
esp_ble_gatt_set_local_mtu(uint16_t mtu)24 esp_err_t esp_ble_gatt_set_local_mtu (uint16_t mtu)
25 {
26     btc_msg_t msg = {0};
27     btc_ble_gatt_com_args_t arg;
28 
29     ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
30 
31     if ((mtu < ESP_GATT_DEF_BLE_MTU_SIZE) || (mtu > ESP_GATT_MAX_MTU_SIZE)) {
32         return ESP_ERR_INVALID_SIZE;
33     }
34 
35     msg.sig = BTC_SIG_API_CALL;
36     msg.pid = BTC_PID_GATT_COMMON;
37     msg.act = BTC_GATT_ACT_SET_LOCAL_MTU;
38     arg.set_mtu.mtu = mtu;
39 
40     return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatt_com_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
41 }
42 
43 #if (BLE_INCLUDED == TRUE)
44 extern UINT16 L2CA_GetFreePktBufferNum_LE(void);
45 
46 /**
47  * @brief           This function is called to get currently sendable packets number on controller,
48  *                  the function is called only in BLE running core and single connection now.
49  *
50  * @return
51  *                  sendable packets number on controller
52  *
53  */
54 
esp_ble_get_sendable_packets_num(void)55 uint16_t esp_ble_get_sendable_packets_num (void)
56 {
57     return L2CA_GetFreePktBufferNum_LE();
58 }
59 
60 /**
61  * @brief           This function is used to query the number of available buffers for the current connection.
62  *                  When you need to query the current available buffer number, it is recommended to use this API.
63  * @param[in]       conn_id: current connection id.
64  *
65  * @return
66  *                  Number of available buffers for the current connection
67  *
68  */
69 
70 extern UINT16 L2CA_GetCurFreePktBufferNum_LE(UINT16 conn_id);
esp_ble_get_cur_sendable_packets_num(uint16_t connid)71 uint16_t esp_ble_get_cur_sendable_packets_num (uint16_t connid)
72 {
73     return L2CA_GetCurFreePktBufferNum_LE(connid);
74 }
75 #endif
76