• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <string.h>
16 #include "esp_gatt_common_api.h"
17 #include "esp_bt_main.h"
18 #include "esp_gatt_defs.h"
19 #include "btc_gatt_common.h"
20 
21 /**
22  * @brief           This function is called to set local MTU,
23  *                  the function is called before BLE connection.
24  *
25  * @param[in]       mtu: the size of MTU.
26  *
27  * @return
28  *                  - ESP_OK: success
29  *                  - other: failed
30  *
31  */
esp_ble_gatt_set_local_mtu(uint16_t mtu)32 esp_err_t esp_ble_gatt_set_local_mtu (uint16_t mtu)
33 {
34     btc_msg_t msg;
35     btc_ble_gatt_com_args_t arg;
36 
37     ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
38 
39     if ((mtu < ESP_GATT_DEF_BLE_MTU_SIZE) || (mtu > ESP_GATT_MAX_MTU_SIZE)) {
40         return ESP_ERR_INVALID_SIZE;
41     }
42 
43     msg.sig = BTC_SIG_API_CALL;
44     msg.pid = BTC_PID_GATT_COMMON;
45     msg.act = BTC_GATT_ACT_SET_LOCAL_MTU;
46     arg.set_mtu.mtu = mtu;
47 
48     return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatt_com_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
49 }
50 
51 #if (BLE_INCLUDED == 1)
52 extern UINT16 L2CA_GetFreePktBufferNum_LE(void);
53 
54 /**
55  * @brief           This function is called to get currently sendable packets number on controller,
56  *                  the function is called only in BLE running core and single connection now.
57  *
58  * @return
59  *                  sendable packets number on controller
60  *
61  */
62 
esp_ble_get_sendable_packets_num(void)63 uint16_t esp_ble_get_sendable_packets_num (void)
64 {
65     return L2CA_GetFreePktBufferNum_LE();
66 }
67 
68 /**
69  * @brief           This function is used to query the number of available buffers for the current connection.
70  *                  When you need to query the current available buffer number, it is recommended to use this API.
71  * @param[in]       conn_id: current connection id.
72  *
73  * @return
74  *                  Number of available buffers for the current connection
75  *
76  */
77 
78 extern UINT16 L2CA_GetCurFreePktBufferNum_LE(UINT16 conn_id);
esp_ble_get_cur_sendable_packets_num(uint16_t connid)79 uint16_t esp_ble_get_cur_sendable_packets_num (uint16_t connid)
80 {
81     return L2CA_GetCurFreePktBufferNum_LE(connid);
82 }
83 #endif
84