Skip to content

Commit 70548ac

Browse files
committed
reads MFC SE
1 parent 3f83d81 commit 70548ac

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

sam_api.c

+27-7
Original file line numberDiff line numberDiff line change
@@ -763,32 +763,50 @@ void seader_mfc_transmit(
763763
(format[0] == 0x00 && format[1] == 0x00 && format[2] == 0x40) ||
764764
(format[0] == 0x00 && format[1] == 0x00 && format[2] == 0x24) ||
765765
(format[0] == 0x00 && format[1] == 0x00 && format[2] == 0x44)) {
766-
//bit_buffer_copy_bytes_with_parity(tx_buffer, buffer, len * 8);
766+
memset(display, 0, sizeof(display));
767+
for(uint8_t i = 0; i < len; i++) {
768+
snprintf(display + (i * 2), sizeof(display), "%02x", buffer[i]);
769+
}
770+
FURI_LOG_D(TAG, "NFC Send with parity %d: %s", len, display);
767771

772+
// Only handles message up to 8 data bytes
768773
uint8_t tx_parity = 0;
774+
uint8_t len_without_parity = len - 1;
769775

770776
// Don't forget to swap the bits of buffer[8]
771777
for(size_t i = 0; i < len; i++) {
772778
bit_lib_reverse_bits(buffer + i, 0, 8);
773779
}
774780

775781
// Pull out parity bits
776-
for(size_t i = 0; i < 8; i++) {
782+
for(size_t i = 0; i < len_without_parity; i++) {
777783
bool val = bit_lib_get_bit(buffer + i + 1, i);
778784
bit_lib_set_bit(&tx_parity, i, val);
779785
}
780786

781-
for(size_t i = 0; i < 8; i++) {
787+
for(size_t i = 0; i < len_without_parity; i++) {
782788
buffer[i] = (buffer[i] << i) | (buffer[i + 1] >> (8 - i));
783789
}
784-
bit_buffer_append_bytes(tx_buffer, buffer, 8);
790+
bit_buffer_append_bytes(tx_buffer, buffer, len_without_parity);
785791

786-
for(size_t i = 0; i < 8; i++) {
792+
for(size_t i = 0; i < len_without_parity; i++) {
787793
bit_lib_reverse_bits(buffer + i, 0, 8);
788794
bit_buffer_set_byte_with_parity(
789795
tx_buffer, i, buffer[i], bit_lib_get_bit(&tx_parity, i));
790796
}
791797

798+
memset(display, 0, sizeof(display));
799+
for(uint8_t i = 0; i < bit_buffer_get_size_bytes(tx_buffer); i++) {
800+
snprintf(
801+
display + (i * 2), sizeof(display), "%02x", bit_buffer_get_byte(tx_buffer, i));
802+
}
803+
FURI_LOG_D(
804+
TAG,
805+
"NFC Send without parity %d: %s [%02x]",
806+
bit_buffer_get_size_bytes(tx_buffer),
807+
display,
808+
tx_parity);
809+
792810
MfClassicError error = mf_classic_poller_send_custom_parity_frame(
793811
mfc_poller, tx_buffer, rx_buffer, MF_CLASSIC_FWT_FC);
794812
if(error != MfClassicErrorNone) {
@@ -805,7 +823,8 @@ void seader_mfc_transmit(
805823
snprintf(
806824
display + (i * 2), sizeof(display), "%02x", bit_buffer_get_byte(rx_buffer, i));
807825
}
808-
FURI_LOG_D(TAG, "NFC Response %d: %s [%02x]", length, display, rx_parity[0]);
826+
FURI_LOG_D(
827+
TAG, "NFC Response without parity %d: %s [%02x]", length, display, rx_parity[0]);
809828

810829
uint8_t with_parity[SEADER_POLLER_MAX_BUFFER_SIZE];
811830
memset(with_parity, 0, sizeof(with_parity));
@@ -848,7 +867,8 @@ void seader_mfc_transmit(
848867
snprintf(
849868
display + (i * 2), sizeof(display), "%02x", bit_buffer_get_byte(rx_buffer, i));
850869
}
851-
FURI_LOG_D(TAG, "NFC Response %d: %s [%02x]", length, display, rx_parity[0]);
870+
FURI_LOG_D(
871+
TAG, "NFC Response with parity %d: %s [%02x]", length, display, rx_parity[0]);
852872

853873
} else {
854874
FURI_LOG_W(TAG, "UNHANDLED FORMAT");

0 commit comments

Comments
 (0)