pn53x: handle properly ReadRegister of PN533
This commit is contained in:
parent
ae522c843c
commit
c937e8d178
2 changed files with 15 additions and 12 deletions
|
@ -164,13 +164,24 @@ pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen
|
||||||
bool
|
bool
|
||||||
pn53x_get_reg (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value)
|
pn53x_get_reg (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value)
|
||||||
{
|
{
|
||||||
size_t szValueLen = 1;
|
size_t szValueLen;
|
||||||
byte_t abtCmd[sizeof (pncmd_get_register)];
|
byte_t abtCmd[sizeof (pncmd_get_register)];
|
||||||
memcpy (abtCmd, pncmd_get_register, sizeof (pncmd_get_register));
|
memcpy (abtCmd, pncmd_get_register, sizeof (pncmd_get_register));
|
||||||
|
|
||||||
abtCmd[2] = ui16Reg >> 8;
|
abtCmd[2] = ui16Reg >> 8;
|
||||||
abtCmd[3] = ui16Reg & 0xff;
|
abtCmd[3] = ui16Reg & 0xff;
|
||||||
return pn53x_transceive (pnd, abtCmd, 4, ui8Value, &szValueLen);
|
if (pn53x_transceive (pnd, abtCmd, sizeof (pncmd_get_register), ui8Value, &szValueLen)) {
|
||||||
|
if (pnd->nc == NC_PN533) {
|
||||||
|
// PN533 prepends its answer by a status byte
|
||||||
|
if (ui8Value[0] == 0) {
|
||||||
|
ui8Value[0] = ui8Value[1];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -186,7 +197,7 @@ pn53x_set_reg (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
abtCmd[4] = ui8Value | (ui8Current & (~ui8SymbolMask));
|
abtCmd[4] = ui8Value | (ui8Current & (~ui8SymbolMask));
|
||||||
return pn53x_transceive (pnd, abtCmd, 5, NULL, NULL);
|
return pn53x_transceive (pnd, abtCmd, sizeof (pncmd_set_register), NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -196,7 +207,7 @@ pn53x_set_parameters (nfc_device_t * pnd, uint8_t ui8Value)
|
||||||
memcpy (abtCmd, pncmd_set_parameters, sizeof (pncmd_set_parameters));
|
memcpy (abtCmd, pncmd_set_parameters, sizeof (pncmd_set_parameters));
|
||||||
|
|
||||||
abtCmd[2] = ui8Value;
|
abtCmd[2] = ui8Value;
|
||||||
return pn53x_transceive (pnd, abtCmd, 3, NULL, NULL);
|
return pn53x_transceive (pnd, abtCmd, sizeof (pncmd_set_parameters), NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -367,14 +367,6 @@ pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szT
|
||||||
// Remove the preceding and appending bytes 00 00 FF xx Fx .. .. .. xx 00 (x = variable)
|
// Remove the preceding and appending bytes 00 00 FF xx Fx .. .. .. xx 00 (x = variable)
|
||||||
*pszRxLen = ret - 7 - 2;
|
*pszRxLen = ret - 7 - 2;
|
||||||
|
|
||||||
// Get register: nuke extra byte (awful hack)
|
|
||||||
if ((abtRx[5] == 0xd5) && (abtRx[6] == 0x07) && (*pszRxLen == 2)) {
|
|
||||||
// DBG("awful hack: abtRx[7]=%02x, abtRx[8]=%02x, we only keep abtRx[8]=%02x", abtRx[7], abtRx[8], abtRx[8]);
|
|
||||||
*pszRxLen = (*pszRxLen) - 1;
|
|
||||||
memcpy (pbtRx, abtRx + 8, *pszRxLen);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy (pbtRx, abtRx + 7, *pszRxLen);
|
memcpy (pbtRx, abtRx + 7, *pszRxLen);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue