Struggling with BLE OTA encrypted updates
Posted: Fri Apr 19, 2024 10:50 pm
Hi everyone,
I've been grappling with this issue for several days now, and I'm at a loss. Previously, I had successfully implemented OTA updates using non-encrypted images with ESP-IDF/iOS. I am now transitioning to using encrypted images, which has proven quite complex.
I've integrated the OTA BLE example from the ESP-IDF into my project. The process begins with establishing a connection and completing handshaking through custom characteristics, after which I send encrypted data to my ESP device. The setup involves a callback named ota_recv_fw_cb, which is established with esp_ble_ota_recv_fw_data_callback(ota_recv_fw_cb, decrypt_handle). However, I'm unsure how to correctly route data to this callback.
Here’s how I've configured the GATT characteristic for OTA data:
And here is the callback associated with this characteristic:
However, after attempting to write the encrypted data to my device, I encounter the following errors:
Why am I seeing this error? Could it be related to the "Firmware package format" as detailed here: https://components.espressif.com/compon ... if/ble_ota. Is there a specific format I need to apply to each data chunk I send? Can someone steer me in the right direction to avoid further wasted hours?
Programming is a hobby of mine, but this part of the project is to frustrating Any guidance or insights would be greatly appreciated.
I've been grappling with this issue for several days now, and I'm at a loss. Previously, I had successfully implemented OTA updates using non-encrypted images with ESP-IDF/iOS. I am now transitioning to using encrypted images, which has proven quite complex.
I've integrated the OTA BLE example from the ESP-IDF into my project. The process begins with establishing a connection and completing handshaking through custom characteristics, after which I send encrypted data to my ESP device. The setup involves a callback named ota_recv_fw_cb, which is established with esp_ble_ota_recv_fw_data_callback(ota_recv_fw_cb, decrypt_handle). However, I'm unsure how to correctly route data to this callback.
Here’s how I've configured the GATT characteristic for OTA data:
Code: Select all
{
// Characteristic: OTA data
.uuid = &gatt_svr_chr_ota_data_uuid.u,
.access_cb = gatt_svr_chr_ota_data_cb,
.flags = BLE_GATT_CHR_F_WRITE,
.val_handle = &ota_data_val_handle,
}
Code: Select all
int gatt_svr_chr_ota_data_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg)
{
uint8_t *data = ctxt->om->om_data;
uint16_t len = ctxt->om->om_len;
ota_recv_fw_cb(data, len);
return 0;
}
Code: Select all
E (4378) esp_ota_ops: OTA image has invalid magic byte (expected 0xE9, saw 0xcf)
E (4388) ESP_BLE_OTA: esp_ota_write failed!
E (4388) ESP_BLE_OTA: OTA failed
Programming is a hobby of mine, but this part of the project is to frustrating Any guidance or insights would be greatly appreciated.