From 37df680a80720d6b6a2de45870cac171c91b2fc1 Mon Sep 17 00:00:00 2001 From: md5sum-as Date: Wed, 26 Oct 2022 00:15:04 +0300 Subject: [PATCH] Refactoring mifare classic, stage 3 --- tasmota/tasmota_xsns_sensor/xsns_40_pn532.ino | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_40_pn532.ino b/tasmota/tasmota_xsns_sensor/xsns_40_pn532.ino index fee1302f8..50bb6e02a 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_40_pn532.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_40_pn532.ino @@ -82,11 +82,10 @@ struct PN532 { uint8_t command = 0; // Carry command code between functions uint8_t scantimer = 0; // Prevent multiple successful reads within 2 second window bool present = false; // Maintain detection flag - uint16_t atqa; #ifdef USE_PN532_DATA_FUNCTION - uint8_t newdata[16]; + uint16_t atqa; + uint8_t newdata[32]; uint8_t function = 0; -// uint8_t newdata_len = 0; uint32_t pwd_auth=0x64636261; uint16_t pwd_pack=0x6665; uint32_t pwd_auth_new; @@ -601,12 +600,13 @@ void PN532_ScanForTag(void) { } } if (mifareclassic_ReadDataBlock(1, (uint8_t *)card_datas)) { - for (uint32_t i = 0;i < sizeof(card_datas);i++) { + for (uint32_t i = 0; i < 16;i++) { if (!isprint(card_datas[i])) { // do not output non-printable characters to the console card_datas[i] = 0; } } + card_datas[16] = 0; } else { card_datas[0] = 0; } @@ -661,13 +661,6 @@ bool PN532_Command(void) { return serviced; } char argument[XdrvMailbox.data_len]; -/* - for (uint32_t ca=0;ca 15) { Pn532.newdata_len = 15; } -// memcpy(&Pn532.newdata,&argument,Pn532.newdata_len); -// Pn532.newdata[Pn532.newdata_len] = 0x00; // Null terminate the string strncpy((char *)Pn532.newdata,argument,sizeof(Pn532.newdata)); - Pn532.newdata[sizeof(Pn532.newdata)-1]=0; + if (strlen(argument)>16) argument[16]=0; Pn532.function = 2; - AddLog(LOG_LEVEL_INFO, PSTR("NFC: PN532 NFC - Next scanned tag data block 1 will be set to '%s'"), Pn532.newdata); + AddLog(LOG_LEVEL_INFO, PSTR("NFC: PN532 NFC - Next scanned tag data block 1 will be set to '%s'"), argument); ResponseTime_P(PSTR(",\"PN532\":{\"COMMAND\":\"S\"}}")); return serviced; }