ZigBee OTA image block callback error

Author: lsroka76Created Mar 22, 2026Updated Sep 28, 2026
LabelsType: Feature requestStatus: To be implementedArea: Zigbee

Board

ESP32 C6

Device Description

N/A

Hardware Configuration

ESP32 C6

Version

v3.3.6

Type

Bug

IDE Name

Arduino IDE

Operating System

Windows 11

Flash frequency

80 MHz

PSRAM enabled

no

Upload speed

921600

Description

For some time I've been trying to implement OTA server in my ZigBee gateway, but I failed many times and then I discovered some bug in code. First - OTA image block request handler is implemented in somehow limited way - user has no access to FileOffset field, only size of necessary data is supplied - but that isn't a problem or at least it shouldn't be.

After many failed attempts to upgrade Sonoff TRVZB with new OTA firmware I finally have started to analyze ZigBee command payload and discovered some bugs.

In first image block request Sonoff is asking for 0x3F(63) bytes of data starting from position 0:

`[200452][D][ZigbeeCore.cpp:515] zb_apsde_data_indication_handler(): APSDE INDICATION - Received APSDE-DATA indication, status: 0 [200453][D][ZigbeeCore.cpp:519] zb_apsde_data_indication_handler(): APSDE INDICATION - dst_endpoint: 1, src_endpoint: 1, dst_addr_mode: 255

APSDE INDICATION - src_addr_mode: 0, cluster_id: 0x0019, asdu_length: 17

APSDE INDICATION - dst_short_addr: 0x0000, src_short_addr: 0x574a

APSDE INDICATION - profile_id: 0x0104, security_status: 0, lqi: 71, rx_time: 0 [200454][I][ZigbeeHandlers.cpp:247] zb_raw_cmd_handler(): cluster id: 0x19, command id: 3 [200455][I][ZigbeeHandlers.cpp:250] zb_raw_cmd_handler(): src endpoint (0x1, dst endpoint 0x1 [200455][I][ZigbeeHandlers.cpp:254] zb_raw_cmd_handler(): is common comand 0, disable_default_response 1, is_manuf_specific 0 [200456][I][ZigbeeHandlers.cpp:258] zb_raw_cmd_handler(): manuf_specific 0x0 [200456][I][ZigbeeHandlers.cpp:262] zb_raw_cmd_handler(): RAW bufid: 7 size: 14 [200457][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 //field control [200457][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x86 // [200457][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x12 //manufacturer id 0x1286 [200458][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x07 [200458][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x20 //image type 0x2007 [200458][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x01 [200459][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x14 [200459][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [200459][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 //version 0x0001401 (4 bytes) [200460][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [200460][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [200460][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [200461][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 //file offset = 0x00000000 [200461][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x3F //max data size = 63`

but in my ota_handler, which is defined as:

esp_err_t ZigbeeGateway::zb_ota_next_data_handler( esp_zb_ota_zcl_information_t message, uint16_t index, uint8_t size, uint8_t **data); I'm receiving:

[177716][I][ZigbeeGateway.cpp:2746] zb_ota_next_data_handler(): cmd id 3, manufacturer specific 0 [177716][I][ZigbeeGateway.cpp:2757] zb_ota_next_data_handler(): -- OTA Server transmits data from 0x0 to 0x574a: progress [0/333092] [177731][I][ZigbeeGateway.cpp:2771] zb_ota_next_data_handler(): size = 7 Of course I know that server can transmit less data than max data size, but on next image block request from Sonoff I'm getting:

APSDE INDICATION - profile_id: 0x0104, security_status: 0, lqi: 71, rx_time: 0 [178132][I][ZigbeeHandlers.cpp:247] zb_raw_cmd_handler(): cluster id: 0x19, command id: 3 [178132][I][ZigbeeHandlers.cpp:250] zb_raw_cmd_handler(): src endpoint (0x1, dst endpoint 0x1 [178133][I][ZigbeeHandlers.cpp:254] zb_raw_cmd_handler(): is common comand 0, disable_default_response 1, is_manuf_specific 0 [178133][I][ZigbeeHandlers.cpp:258] zb_raw_cmd_handler(): manuf_specific 0x0 [178134][I][ZigbeeHandlers.cpp:262] zb_raw_cmd_handler(): RAW bufid: 12 size: 14 [178134][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [178134][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x86 [178135][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x12 [178135][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x07 [178135][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x20 [178136][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x01 [178136][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x14 [178136][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [178137][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [178137][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x3F //file offset = 63! <- should be 7? [178138][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [178138][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [178138][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x00 [178139][I][ZigbeeHandlers.cpp:265] zb_raw_cmd_handler(): 0x3F and this time handler receives right data: [178144][I][ZigbeeGateway.cpp:2746] zb_ota_next_data_handler(): cmd id 3, manufacturer specific 0 [178144][I][ZigbeeGateway.cpp:2757] zb_ota_next_data_handler(): -- OTA Server transmits data from 0x0 to 0x574a: progress [7/333092] [178159][I][ZigbeeGateway.cpp:2771] zb_ota_next_data_handler(): size = 63

It looks like for first request ZigBee library is cutting first 56 bytes (OTA header?) but Sonoff (and most other commercial devices) requires sending complete OTA file (including header) and because of that after 30 minutes of sending 300K file I'm getting INVALID OTA IMAGE error.

Sketch

cpp
as above

Debug Message

plain
as above

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.