From 2c1fd6b7ea8cb37c06ed117e749b55e1f482abce Mon Sep 17 00:00:00 2001 From: Carlos Valdes Date: Thu, 23 Jul 2026 09:57:14 +0200 Subject: [PATCH] fix(ScanI2C): fetch the SE050 probe response with requestFrom() (#11133) --- src/detect/ScanI2CTwoWire.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 429928d57..c543aac85 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -905,15 +905,27 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) break; case 0x48: { - i2cBus->beginTransmission(addr.address); - uint8_t getInfo[] = {0x5A, 0xC0, 0x00, 0xFF, 0xFC}; - uint8_t expectedInfo[] = {0xa5, 0xE0, 0x00, 0x3F, 0x19}; - uint8_t info[5]; + // T=1oI2C soft reset; an SE050 answers A5 E0 00 3F 19. requestFrom() is + // required: readBytes() only drains the RX buffer requestFrom() fills. + const uint8_t getInfo[] = {0x5A, 0xC0, 0x00, 0xFF, 0xFC}; + const uint8_t expectedInfo[] = {0xA5, 0xE0, 0x00, 0x3F, 0x19}; + uint8_t info[sizeof(expectedInfo)] = {0}; size_t len = 0; - i2cBus->write(getInfo, 5); - i2cBus->endTransmission(); - len = i2cBus->readBytes(info, 5); - if (len == 5 && memcmp(expectedInfo, info, len) == 0) { + bool isSE050 = false; + + i2cBus->beginTransmission(addr.address); + i2cBus->write(getInfo, sizeof(getInfo)); + if (i2cBus->endTransmission() == 0) { + delay(2); // guard time before the answer can be read back + len = i2cBus->requestFrom((uint8_t)addr.address, (uint8_t)sizeof(info)); + if (len == sizeof(info)) { + for (size_t i = 0; i < sizeof(info); i++) + info[i] = i2cBus->read(); + isSE050 = (memcmp(expectedInfo, info, sizeof(info)) == 0); + } + } + + if (isSE050) { LOG_INFO("NXP SE050 crypto chip found"); type = NXP_SE050; break;