Skip to content

Commit

Permalink
update sync
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwiz4rd committed Nov 1, 2021
1 parent 5f68caf commit 6de2cf2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
75 changes: 47 additions & 28 deletions libnfc/chips/pn53x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,37 +1109,52 @@ pn53x_initiator_init_collision(struct nfc_device *pnd)

log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Collision Init called");

// pn53x_WriteRegister(pnd, PN53X_REG_CIU_RFCfg, 0x78); // test all above 0x08

// pn53x_WriteRegister(pnd, PN53X_REG_CIU_CommIEn, 0xa0); // RxIEn enabled
// By setting Collevel to 0x07, collisions should not detected by the chip
// pn53x_WriteRegister(pnd, PN53X_REG_CIU_RxThreshold, 0x87);

uint8_t reg;

if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_RFCfg, &reg)) < 0) // 0x48
return res;
// Rember to place 1kOhm pull down resitor on pin AUX1!
// 0x70: On AUX1 -> DAC output: ADC_I combined with ADC_Q
// 0xd0: On AUX1 -> high during data bits, parity and CRC
// 0x50: On AUX1 -> DAC output: ADC_I
// 0x60: On AUX1 -> DAC output: ADC_Q
pn53x_WriteRegister(pnd, PN53X_REG_CIU_AnalogTest, 0x70); // nothing seen on combined
// pn53x_WriteRegister(pnd, PN53X_REG_CIU_AnalogTest, 0x50); // something seen on ADC_I
// pn53x_WriteRegister(pnd, PN53X_REG_CIU_AnalogTest, 0x60); // something seen on ADC_Q

if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_RxThreshold, &reg)) < 0) // 0x84
return res;
// pn53x_WriteRegister(pnd, PN53X_REG_CIU_RxThreshold, 0xf4); // MinLevel and CollLevel
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RFCfg, 0x78); // 48dB gain

if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_Demod, &reg)) < 0) // 0x4d
return res;

if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_RxMode, &reg)) < 0) // 0x08
return res;
// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_AnalogTest, &reg)) < 0) // 0x00 by default
// return res;

if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_CommIEn, &reg)) < 0) // 0x80
return res;
// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_AutoTest, &reg)) < 0) //
// return res;

// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_RFCfg, &reg)) < 0) // 0x48
// return res;

// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_RxThreshold, &reg)) < 0) // 0x84
// return res;

// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_Demod, &reg)) < 0) // 0x4d
// return res;

// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_RxMode, &reg)) < 0) // 0x08
// return res;

// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_CommIEn, &reg)) < 0) // 0x80
// return res;

if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_DivIEn, &reg)) < 0) // 0x00
return res;
// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_DivIEn, &reg)) < 0) // 0x00
// return res;

if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_CommIrq, &reg)) < 0) // 0x04
return res;
// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_CommIrq, &reg)) < 0) // 0x04
// return res;

if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_DivIrq, &reg)) < 0) // 0x03
return res;
// if ((res = pn53x_read_register(pnd, PN53X_REG_CIU_DivIrq, &reg)) < 0) // 0x03
// return res;

return NFC_SUCCESS;
}
Expand Down Expand Up @@ -1657,18 +1672,18 @@ pn53x_initiator_transceive_bits(struct nfc_device *pnd, const uint8_t *pbtTx, co
szFrameBits = ((szRx - 1 - ((ui8Bits == 0) ? 0 : 1)) * 8) + ui8Bits;
else
szFrameBits = 0;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Real framelength in bits %zu, szRx %zu, ui8Bits %d", szFrameBits, szRx, ui8Bits);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Framelength in bits before unwrap: szFrameBits %zu, szRx %zu, ui8Bits %d", szFrameBits, szRx, ui8Bits);

if (pbtRx != NULL) {
// Ignore the status byte from the PN53X here, it was checked earlier in pn53x_transceive()
// Check if we should recover the parity bits ourself
if (!pnd->bPar) {
// Print unwrapped response
printf("<= ");
for (size_t szPos = 0; szPos < szFrameBits/8; szPos++) {
printf("%02x ", abtRx[szPos]);
}
printf(" (not unwrapped) \n");
// printf("<= ");
// for (size_t szPos = 0; szPos < szFrameBits/8; szPos++) {
// printf("%02x ", abtRx[szPos]);
// }
// printf(" (not unwrapped) \n");
// Unwrap the response frame
if ((res = pn53x_unwrap_frame(abtRx + 1, szFrameBits, pbtRx, pbtRxPar)) < 0)
return res;
Expand All @@ -1680,7 +1695,8 @@ pn53x_initiator_transceive_bits(struct nfc_device *pnd, const uint8_t *pbtTx, co
memcpy(pbtRx, abtRx + 1, szRx - 1);
}
}


log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Framelength in bits after unwrap: szRxBits %zu", szRxBits);
// Everything went successful
return szRxBits;
}
Expand Down Expand Up @@ -2460,6 +2476,7 @@ pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
#define SAK_ISO14443_4_COMPLIANT 0x20
#define SAK_ISO18092_COMPLIANT 0x40
int
// TODO: FIX THIS FUNCTION -> SEGMENTATION FAULT
pn53x_target_init(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRxLen, int timeout)
{
pn53x_reset_settings(pnd);
Expand Down Expand Up @@ -2706,7 +2723,9 @@ pn53x_target_receive_bits(struct nfc_device *pnd, uint8_t *pbtRx, const size_t s
uint8_t ui8Bits = ui8rcc & SYMBOL_RX_LAST_BITS;

// Recover the real frame length in bits
size_t szFrameBits = ((szRx - 1 - ((ui8Bits == 0) ? 0 : 1)) * 8) + ui8Bits;
size_t szFrameBits = 0;
if (szRx - 1 > 0) // solves possible segmentation fault on bit collisions

This comment has been minimized.

Copy link
@blackwiz4rd

blackwiz4rd Dec 3, 2022

Author Owner

This is the most relevant part to fix issues

szFrameBits = ((szRx - 1 - ((ui8Bits == 0) ? 0 : 1)) * 8) + ui8Bits;

// Ignore the status byte from the PN53X here, it was checked earlier in pn53x_transceive()
// Check if we should recover the parity bits ourself
Expand Down
4 changes: 2 additions & 2 deletions libnfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ nfc_initiator_init(nfc_device *pnd)
* - Easy framing is enabled (NP_EASY_FRAMING = false)
* - Auto-switching in ISO14443-4 mode is enabled (NP_AUTO_ISO14443_4 = false)
* - Invalid frames are not accepted (NP_ACCEPT_INVALID_FRAMES = true)
* - Multiple frames are not accepted (NP_ACCEPT_MULTIPLE_FRAMES = false)
* - Multiple frames are accepted (NP_ACCEPT_MULTIPLE_FRAMES = true)
* - 14443-A mode is activated (NP_FORCE_ISO14443_A = true)
* - speed is set to 106 kbps (NP_FORCE_SPEED_106 = true)
* - Let the device try forever to find a target (NP_INFINITE_SELECT = false)
Expand Down Expand Up @@ -566,7 +566,7 @@ nfc_initiator_init_collision(nfc_device *pnd)
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_INVALID_FRAMES, true)) < 0)
return res;
// Disallow multiple frames
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_MULTIPLE_FRAMES, false)) < 0)
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_MULTIPLE_FRAMES, true)) < 0)
return res;
HAL(initiator_init_collision, pnd);
}
Expand Down
2 changes: 1 addition & 1 deletion utils/nfc-barcode
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ DUALCASE=1; export DUALCASE # for MKS sh
# if CDPATH is set.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH

relink_command="(cd /home/luca/Desktop/libnfc/utils; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl; export PATH; gcc -g -O2 -Wall -pedantic -Wextra -std=c99 -Du_int8_t=uint8_t -Du_int16_t=uint16_t -o \$progdir/\$file nfc-barcode.o ../libnfc/.libs/libnfc.so ./.libs/libnfcutils.a /usr/lib/libnfc.so -lusb -Wl,-rpath -Wl,/home/luca/Desktop/libnfc/libnfc/.libs)"
relink_command="(cd /home/luca/Desktop/rfid-gnuradio/libnfc/utils; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl; export PATH; gcc -g -O2 -Wall -pedantic -Wextra -std=c99 -Du_int8_t=uint8_t -Du_int16_t=uint16_t -o \$progdir/\$file nfc-barcode.o ../libnfc/.libs/libnfc.so ./.libs/libnfcutils.a /usr/lib/libnfc.so -lusb -Wl,-rpath -Wl,/home/luca/Desktop/rfid-gnuradio/libnfc/libnfc/.libs)"

# This environment variable determines our operation mode.
if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
Expand Down

0 comments on commit 6de2cf2

Please sign in to comment.