diff --git a/src/platform/ESP32/ChipDeviceScanner.h b/src/platform/ESP32/ChipDeviceScanner.h index d921ba08e859a2..81c23d8f921fa8 100644 --- a/src/platform/ESP32/ChipDeviceScanner.h +++ b/src/platform/ESP32/ChipDeviceScanner.h @@ -17,6 +17,7 @@ #pragma once +#include #include #include @@ -31,7 +32,6 @@ #include "esp_gattc_api.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" -#include #include #include #endif diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp index 189ebd9dae6775..c581d1fd6d6290 100644 --- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp +++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp @@ -659,7 +659,13 @@ bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBle return false; } - rc = ble_gattc_write_flat(conId, chr->chr.val_handle, pBuf->Start(), pBuf->DataLength(), OnWriteComplete, this); + if (pBuf->DataLength() > UINT16_MAX) + { + ChipLogError(Ble, "Buffer data Length is too long"); + return false; + } + rc = ble_gattc_write_flat(conId, chr->chr.val_handle, pBuf->Start(), static_cast(pBuf->DataLength()), OnWriteComplete, + this); if (rc != 0) { ChipLogError(Ble, "ble_gattc_write_flat failed: %d", rc);