esp_gatt_common_api.c 2.1 KB

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