esp_gatt_common_api.c 2.5 KB

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