mirror of
https://github.com/esphome/esphome.git
synced 2026-09-15 17:18:40 +00:00
[pn7160][pn7150][pn532] Fix tag purge skipping, NDEF bounds check, and NDEF length byte order (#14460)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
9abba79c54
commit
246a8bff0c
@@ -99,7 +99,7 @@ bool PN532::find_mifare_ultralight_ndef_(const std::vector<uint8_t> &page_3_to_6
|
||||
uint8_t &message_start_index) {
|
||||
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
|
||||
|
||||
if (!(page_3_to_6.size() > p4_offset + 5)) {
|
||||
if (!(page_3_to_6.size() > p4_offset + 6)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ bool PN532::write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, nfc::NdefMessage *
|
||||
} else {
|
||||
encoded.insert(encoded.begin() + 1, 0xFF);
|
||||
encoded.insert(encoded.begin() + 2, (message_length >> 8) & 0xFF);
|
||||
encoded.insert(encoded.begin() + 2, message_length & 0xFF);
|
||||
encoded.insert(encoded.begin() + 3, message_length & 0xFF);
|
||||
}
|
||||
encoded.push_back(0xFE);
|
||||
|
||||
|
||||
@@ -562,9 +562,9 @@ optional<size_t> PN7150::find_tag_uid_(const nfc::NfcTagUid &uid) {
|
||||
}
|
||||
|
||||
void PN7150::purge_old_tags_() {
|
||||
for (size_t i = 0; i < this->discovered_endpoint_.size(); i++) {
|
||||
if (millis() - this->discovered_endpoint_[i].last_seen > this->tag_ttl_) {
|
||||
this->erase_tag_(i);
|
||||
for (size_t i = this->discovered_endpoint_.size(); i > 0; i--) {
|
||||
if (millis() - this->discovered_endpoint_[i - 1].last_seen > this->tag_ttl_) {
|
||||
this->erase_tag_(i - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ uint8_t PN7150::find_mifare_ultralight_ndef_(const std::vector<uint8_t> &page_3_
|
||||
uint8_t &message_start_index) {
|
||||
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
|
||||
|
||||
if (!(page_3_to_6.size() > p4_offset + 5)) {
|
||||
if (!(page_3_to_6.size() > p4_offset + 6)) {
|
||||
return nfc::STATUS_FAILED;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ uint8_t PN7150::write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, const std::sha
|
||||
} else {
|
||||
encoded.insert(encoded.begin() + 1, 0xFF);
|
||||
encoded.insert(encoded.begin() + 2, (message_length >> 8) & 0xFF);
|
||||
encoded.insert(encoded.begin() + 2, message_length & 0xFF);
|
||||
encoded.insert(encoded.begin() + 3, message_length & 0xFF);
|
||||
}
|
||||
encoded.push_back(0xFE);
|
||||
|
||||
|
||||
@@ -589,9 +589,9 @@ optional<size_t> PN7160::find_tag_uid_(const nfc::NfcTagUid &uid) {
|
||||
}
|
||||
|
||||
void PN7160::purge_old_tags_() {
|
||||
for (size_t i = 0; i < this->discovered_endpoint_.size(); i++) {
|
||||
if (millis() - this->discovered_endpoint_[i].last_seen > this->tag_ttl_) {
|
||||
this->erase_tag_(i);
|
||||
for (size_t i = this->discovered_endpoint_.size(); i > 0; i--) {
|
||||
if (millis() - this->discovered_endpoint_[i - 1].last_seen > this->tag_ttl_) {
|
||||
this->erase_tag_(i - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ uint8_t PN7160::find_mifare_ultralight_ndef_(const std::vector<uint8_t> &page_3_
|
||||
uint8_t &message_start_index) {
|
||||
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
|
||||
|
||||
if (!(page_3_to_6.size() > p4_offset + 5)) {
|
||||
if (!(page_3_to_6.size() > p4_offset + 6)) {
|
||||
return nfc::STATUS_FAILED;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ uint8_t PN7160::write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, const std::sha
|
||||
} else {
|
||||
encoded.insert(encoded.begin() + 1, 0xFF);
|
||||
encoded.insert(encoded.begin() + 2, (message_length >> 8) & 0xFF);
|
||||
encoded.insert(encoded.begin() + 2, message_length & 0xFF);
|
||||
encoded.insert(encoded.begin() + 3, message_length & 0xFF);
|
||||
}
|
||||
encoded.push_back(0xFE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user