Skip to content

Commit d7a7350

Browse files
committed
Fixes to align with the latest specifications,and Fixes some API to more secure
1 parent 99bd9ab commit d7a7350

2 files changed

Lines changed: 15 additions & 22 deletions

File tree

src/unit/unit_Finger2.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ bool UnitFinger2::begin()
126126
return false;
127127
}
128128

129-
if (!wakeup() || !writeSystemRegister(RegisterID::ScoreLevel, _cfg.score_level)) {
130-
M5_LIB_LOGE("Failed to writeSystemRegister");
131-
return false;
132-
}
133-
134129
// Get maximum page id
135130
SystemBasicParams params{};
136131
if (!wakeup() || !readSystemParams(params)) {
@@ -565,12 +560,6 @@ bool UnitFinger2::writeSystemRegister(const finger2::RegisterID reg_id, const ui
565560
{
566561
// Check args
567562
switch (reg_id) {
568-
case RegisterID::ScoreLevel:
569-
if (value < 1 || value > 5) {
570-
M5_LIB_LOGE("ScoreLevel must be 1 - 5 (%u)", value);
571-
return false;
572-
}
573-
break;
574563
case RegisterID::PacketSize:
575564
if (value > 3) {
576565
M5_LIB_LOGE("PacketSize must be 0 - 3 (%u)", value);
@@ -593,12 +582,12 @@ bool UnitFinger2::writeSystemRegister(const finger2::RegisterID reg_id, const ui
593582
return transceive_command(pkt, CMD_WRITE_REGISTER, _address, params, sizeof(params));
594583
}
595584

596-
bool UnitFinger2::readInformationPage(uint8_t inf[512])
585+
bool UnitFinger2::readInformationPage(uint8_t info[512])
597586
{
598-
if (!inf) {
587+
if (!info) {
599588
return false;
600589
}
601-
memset(inf, 0x00, 512);
590+
memset(info, 0x00, 512);
602591

603592
Packet pkt{};
604593
if (!transceive_command(pkt, CMD_READ_FLASH_INFORMATION, _address)) {
@@ -614,10 +603,16 @@ bool UnitFinger2::readInformationPage(uint8_t inf[512])
614603
break;
615604
}
616605
uint16_t sz = (((uint16_t)rbuf[7]) << 8) | (uint16_t)rbuf[8];
617-
memcpy(inf + pos, rbuf.data() + 9, sz - 2);
618-
pos += sz - 2;
606+
if (sz <= 2) {
607+
break;
608+
}
609+
sz -= 2;
610+
if (pos + sz < 512) {
611+
memcpy(info + pos, rbuf.data() + 9, sz);
612+
}
613+
pos += sz;
619614
if (confirm == PID_TERMINATE_DATA) {
620-
return true;
615+
return pos == 512;
621616
}
622617
}
623618
return false;

src/unit/unit_Finger2.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ enum class LEDColor : uint8_t {
6767
@brief PS_WriteReg target register
6868
*/
6969
enum class RegisterID : uint8_t {
70-
ScoreLevel = 5, //!< 0x05:Match threshold (Lenient:1 - Strict:5) (3 as default)
71-
PacketSize, //!< 0x06:Data packet size (0:32,1:64,2:128,3:256) (1 as default)
70+
PacketSize = 6, //!< 0x06:Data packet size (0:32,1:64,2:128,3:256) (1 as default)
7271
};
7372

7473
/*!
@@ -277,7 +276,6 @@ class UnitFinger2 : public Component {
277276
uint32_t timeout_ms{1000 * 4}; //!< Serial I/O timeout (ms)
278277
finger2::WorkMode work_mode{finger2::WorkMode::ScheduledSleep}; //!< Work mode
279278
uint8_t sleep_time{10}; //!< Scheduled sleep time (10 - 254) sec
280-
uint8_t score_level{3}; //!< Match threshold (Lenient:1 - Strict:5)
281279
};
282280

283281
///@name Settings for begin
@@ -727,10 +725,10 @@ class UnitFinger2 : public Component {
727725
/*!
728726
@brief Read the the information page in FLASH( 512 bytes)
729727
@details PS_ReadINFpage
730-
@param inf Buffer (at least 512 bytes)
728+
@param info Buffer (at least 512 bytes)
731729
@return True if successful
732730
*/
733-
bool readInformationPage(uint8_t inf[512]);
731+
bool readInformationPage(uint8_t info[512]);
734732

735733
/*!
736734
@brief Read the random number (32bits)

0 commit comments

Comments
 (0)