1
0
mirror of synced 2024-11-23 23:50:56 +01:00

fix felica read and write

This commit is contained in:
QHPaeek 2024-09-14 11:57:48 +08:00
parent ef279f9a06
commit ebb2565ce4
2 changed files with 14 additions and 8 deletions

View File

@ -7,7 +7,7 @@
#elif defined(ESP8266) #elif defined(ESP8266)
#pragma message "当前的开发板是 ESP8266" #pragma message "当前的开发板是 ESP8266"
#define SerialDevice Serial #define SerialDevice Serial
#define PN532_SPI_SS D4 //#define PN532_SPI_SS D4
#define LED_PIN D5 #define LED_PIN D5
#elif defined(ESP32) #elif defined(ESP32)
@ -196,7 +196,7 @@ typedef union {
struct { struct {
uint8_t RW_status[2]; uint8_t RW_status[2];
uint8_t numBlock; uint8_t numBlock;
uint8_t blockData[1][1][16]; uint8_t blockData[4][16];
}; };
uint8_t felica_payload[1]; uint8_t felica_payload[1];
}; };
@ -385,13 +385,12 @@ void nfc_felica_through() {
break; break;
case FelicaReadWithoutEncryptData: case FelicaReadWithoutEncryptData:
{ {
uint16_t serviceCodeList[1] = { (uint16_t)(req.serviceCodeList[1] << 8 | req.serviceCodeList[0]) }; uint16_t serviceCodeList = req.serviceCodeList[1] << 8 | req.serviceCodeList[0];
uint16_t blockList[4];
for (uint8_t i = 0; i < req.numBlock; i++) { for (uint8_t i = 0; i < req.numBlock; i++) {
uint16_t blockList[1] = { (uint16_t)(req.blockList[i][0] << 8 | req.blockList[i][1]) }; blockList[i] = (uint16_t)(req.blockList[i][0] << 8 | req.blockList[i][1]);
if (nfc.felica_ReadWithoutEncryption(1, serviceCodeList, 1, blockList, res.blockData[i]) != 1) {
memset(res.blockData[i], 0, 16); // dummy data
}
} }
nfc.felica_ReadWithoutEncryption(1, &serviceCodeList, req.numBlock, blockList, res.blockData);
res.RW_status[0] = 0; res.RW_status[0] = 0;
res.RW_status[1] = 0; res.RW_status[1] = 0;
res.numBlock = req.numBlock; res.numBlock = req.numBlock;
@ -400,7 +399,10 @@ void nfc_felica_through() {
break; break;
case FelicaWriteWithoutEncryptData: case FelicaWriteWithoutEncryptData:
{ {
res_init(0x0C); // WriteWithoutEncryption,ignore uint16_t serviceCodeList = req.serviceCodeList[1] << 8 | req.serviceCodeList[0];
uint16_t blockList = (uint16_t)(req.blockList_write[0][0] << 8 | req.blockList_write[0][1]);
nfc.felica_WriteWithoutEncryption(1, &serviceCodeList, 1, &blockList, &req.blockData);
res_init(0x0C);
res.RW_status[0] = 0; res.RW_status[0] = 0;
res.RW_status[1] = 0; res.RW_status[1] = 0;
} }

View File

@ -95,8 +95,12 @@ void loop() {
case CMD_CARD_HALT: case CMD_CARD_HALT:
case CMD_EXT_TO_NORMAL_MODE: case CMD_EXT_TO_NORMAL_MODE:
case CMD_TO_UPDATER_MODE: case CMD_TO_UPDATER_MODE:
res_init();
break;
case CMD_SEND_HEX_DATA: case CMD_SEND_HEX_DATA:
res_init(); res_init();
res.status = STATUS_COMP_DUMMY_3RD;
break; break;
case STATUS_SUM_ERROR: case STATUS_SUM_ERROR: