Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PN532 - don't read extra page and fix size #1565

Merged
merged 1 commit into from Mar 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions esphome/components/pn532/pn532_mifare_ultralight.cpp
Expand Up @@ -17,12 +17,12 @@ nfc::NfcTag *PN532::read_mifare_ultralight_tag_(std::vector<uint8_t> &uid) {
if (!this->find_mifare_ultralight_ndef_(message_length, message_start_index)) {
return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2);
}
ESP_LOGVV(TAG, "message length: %d, start: %d", message_length, message_start_index);

if (message_length == 0) {
return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2);
}
std::vector<uint8_t> data;
uint8_t index = 0;
for (uint8_t page = nfc::MIFARE_ULTRALIGHT_DATA_START_PAGE; page < nfc::MIFARE_ULTRALIGHT_MAX_PAGE; page++) {
std::vector<uint8_t> page_data;
if (!this->read_mifare_ultralight_page_(page, page_data)) {
Expand All @@ -31,13 +31,12 @@ nfc::NfcTag *PN532::read_mifare_ultralight_tag_(std::vector<uint8_t> &uid) {
}
data.insert(data.end(), page_data.begin(), page_data.end());

if (index >= (message_length + message_start_index))
if (data.size() >= (message_length + message_start_index))
break;

index += page_data.size();
}

data.erase(data.begin(), data.begin() + message_start_index);
data.erase(data.begin() + message_length, data.end());

return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2, data);
}
Expand Down