esp_gatt_common_api.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. }