Skip to content

Commit f1c97c0

Browse files
committed
fix "hf felica raw" length of buffer calculations. Added some more comments to explain whats going on. Thanks to @dxl for the solutions!
1 parent fd06c38 commit f1c97c0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
44

55
## [unreleased][unreleased]
6+
- fix `hf felica raw` - wrong length calculationes. Thanks @dxl for the solutions! (@iceman1001)
67
- Added basic QR code generation support. Thanks @mistial-dev for the idea! (@iceman1001)
78
- Added identification of NDEF/Open print tag record (@iceman1001)
89
- Added support for Bruce dump files [.rfid] (@iceman1001)

armsrc/felica.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,26 +572,31 @@ void felica_sendraw(const PacketCommandNG *c) {
572572

573573
if ((param & FELICA_RAW) == FELICA_RAW) {
574574

575-
// 2 sync, 1 len, 2crc == 5
575+
// 2 sync, 1 len, 2 crc == 5
576576
uint8_t *buf = BigBuf_calloc(len + 5);
577577
// add sync bits
578578
buf[0] = 0xb2;
579579
buf[1] = 0x4d;
580-
buf[2] = len;
580+
581+
// len (number of bytes) + 1 for len byte itself
582+
buf[2] = len + 1;
581583

582584
// copy command
583-
memcpy(buf + 2, c->data.asBytes, len);
585+
memcpy(buf + 3, c->data.asBytes, len);
584586

585587
if ((param & FELICA_APPEND_CRC) == FELICA_APPEND_CRC) {
586588
// Don't append crc on empty bytearray...
587-
if (len > 0) {
588-
AddCrc(buf + 2, len);
589+
if (len) {
590+
// n bytes + len 1 byte
591+
AddCrc(buf + 2, len + 1);
589592
}
590593
}
591594

592595
if (g_dbglevel >= DBG_DEBUG) {
593596
Dbprintf("Transmit Frame (no CRC shown):");
594-
Dbhexdump(len, buf, 0);
597+
// 0,1,2, n
598+
Dbhexdump(len + 1 + 2, buf, 0);
599+
// total buffer length: len + 1 len byte + 2 sync bytes + 2 crc bytes
595600
Dbprintf("Buffer Length: %i", buf[2] + 4);
596601
};
597602

0 commit comments

Comments
 (0)