Code cleanup.
This commit is contained in:
parent
30c2fc4c93
commit
67aa84ad76
5 changed files with 28 additions and 34 deletions
|
@ -118,28 +118,22 @@ dev_info* dev_pn533_connect(const nfc_device_desc_t* device_desc)
|
||||||
uiDevIndex--;
|
uiDevIndex--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
DBG("Found PN533 device.");
|
||||||
printf("Found PN533 device\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Open the PN533 USB device
|
// Open the PN533 USB device
|
||||||
dsp.pudh = usb_open(dev);
|
dsp.pudh = usb_open(dev);
|
||||||
|
|
||||||
get_end_points(dev,&dsp);
|
get_end_points(dev,&dsp);
|
||||||
if(usb_set_configuration(dsp.pudh,1) < 0)
|
if(usb_set_configuration(dsp.pudh,1) < 0)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
DBG("Setting config failed");
|
||||||
printf("Setting config failed\n");
|
usb_close(dsp.pudh);
|
||||||
#endif
|
|
||||||
usb_close(dsp.pudh);
|
|
||||||
return INVALID_DEVICE_INFO;
|
return INVALID_DEVICE_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(usb_claim_interface(dsp.pudh,0) < 0)
|
if(usb_claim_interface(dsp.pudh,0) < 0)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
DBG("Can't claim interface");
|
||||||
printf("Can't claim interface\n");
|
|
||||||
#endif
|
|
||||||
usb_close(dsp.pudh);
|
usb_close(dsp.pudh);
|
||||||
return INVALID_DEVICE_INFO;
|
return INVALID_DEVICE_INFO;
|
||||||
}
|
}
|
||||||
|
@ -159,43 +153,43 @@ dev_info* dev_pn533_connect(const nfc_device_desc_t* device_desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pdi;
|
return pdi;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dev_pn533_disconnect(dev_info* pdi)
|
void dev_pn533_disconnect(dev_info* pdi)
|
||||||
{
|
{
|
||||||
dev_spec_pn533* pdsp = (dev_spec_pn533*)pdi->ds;
|
dev_spec_pn533* pdsp = (dev_spec_pn533*)pdi->ds;
|
||||||
usb_release_interface(pdsp->pudh,0);
|
usb_release_interface(pdsp->pudh,0);
|
||||||
usb_close(pdsp->pudh);
|
usb_close(pdsp->pudh);
|
||||||
free(pdi->ds);
|
free(pdi->ds);
|
||||||
free(pdi);
|
free(pdi);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen)
|
bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen)
|
||||||
{
|
{
|
||||||
uint32_t uiPos = 0;
|
uint32_t uiPos = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char buf[BUFFER_LENGTH];
|
char buf[BUFFER_LENGTH];
|
||||||
dev_spec_pn533* pdsp = (dev_spec_pn533*)ds;
|
dev_spec_pn533* pdsp = (dev_spec_pn533*)ds;
|
||||||
|
|
||||||
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
|
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
|
||||||
buffer[3] = uiTxLen;
|
buffer[3] = uiTxLen;
|
||||||
// Packet length checksum
|
// Packet length checksum
|
||||||
buffer[4] = BUFFER_LENGTH - buffer[3];
|
buffer[4] = BUFFER_LENGTH - buffer[3];
|
||||||
// Copy the PN53X command into the packet buffer
|
// Copy the PN53X command into the packet buffer
|
||||||
memmove(buffer+5,pbtTx,uiTxLen);
|
memmove(buffer+5,pbtTx,uiTxLen);
|
||||||
|
|
||||||
// Calculate data payload checksum
|
// Calculate data payload checksum
|
||||||
buffer[uiTxLen+5] = 0;
|
buffer[uiTxLen+5] = 0;
|
||||||
for(uiPos=0; uiPos < uiTxLen; uiPos++)
|
for(uiPos=0; uiPos < uiTxLen; uiPos++)
|
||||||
{
|
{
|
||||||
buffer[uiTxLen+5] -= buffer[uiPos+5];
|
buffer[uiTxLen+5] -= buffer[uiPos+5];
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of stream marker
|
// End of stream marker
|
||||||
buffer[uiTxLen+6] = 0;
|
buffer[uiTxLen+6] = 0;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Tx: ");
|
printf(" TX: ");
|
||||||
print_hex((byte_t*)buffer,uiTxLen+7);
|
print_hex((byte_t*)buffer,uiTxLen+7);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -218,7 +212,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Rx: ");
|
printf(" RX: ");
|
||||||
print_hex((byte_t*)buf,ret);
|
print_hex((byte_t*)buf,ret);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -234,12 +228,12 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Rx: ");
|
printf(" RX: ");
|
||||||
print_hex((byte_t*)buf,ret);
|
print_hex((byte_t*)buf,ret);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the answer should be ignored, just return a succesful result
|
// When the answer should be ignored, just return a succesful result
|
||||||
if(pbtRx == NULL || puiRxLen == NULL) return true;
|
if(pbtRx == NULL || puiRxLen == NULL) return true;
|
||||||
|
|
||||||
// Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable)
|
// Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable)
|
||||||
|
|
|
@ -31,7 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
#include "dev_arygon.h"
|
#include "dev_arygon.h"
|
||||||
|
|
||||||
const static struct dev_callbacks dev_callbacks_list[] = {
|
const static struct dev_callbacks dev_callbacks_list[] = {
|
||||||
// Driver Name Connect Transceive Disconect
|
// Driver Name Connect Transceive Disconnect
|
||||||
#ifdef HAVE_PCSC_LITE
|
#ifdef HAVE_PCSC_LITE
|
||||||
{ "ACR122", dev_acr122_connect, dev_acr122_transceive, dev_acr122_disconnect },
|
{ "ACR122", dev_acr122_connect, dev_acr122_transceive, dev_acr122_disconnect },
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -144,7 +144,7 @@ bool pn53x_set_tx_bits(const dev_info* pdi, uint8_t ui8Bits)
|
||||||
{
|
{
|
||||||
// Set the amount of transmission bits in the PN53X chip register
|
// Set the amount of transmission bits in the PN53X chip register
|
||||||
if (!pn53x_set_reg(pdi,REG_CIU_BIT_FRAMING,SYMBOL_TX_LAST_BITS,ui8Bits)) return false;
|
if (!pn53x_set_reg(pdi,REG_CIU_BIT_FRAMING,SYMBOL_TX_LAST_BITS,ui8Bits)) return false;
|
||||||
|
|
||||||
// Store the new setting
|
// Store the new setting
|
||||||
((dev_info*)pdi)->ui8TxBits = ui8Bits;
|
((dev_info*)pdi)->ui8TxBits = ui8Bits;
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ bool pn53x_wrap_frame(const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t
|
||||||
|
|
||||||
// Make sure we should frame at least something
|
// Make sure we should frame at least something
|
||||||
if (uiBitsLeft == 0) return false;
|
if (uiBitsLeft == 0) return false;
|
||||||
|
|
||||||
// Handle a short response (1byte) as a special case
|
// Handle a short response (1byte) as a special case
|
||||||
if (uiBitsLeft < 9)
|
if (uiBitsLeft < 9)
|
||||||
{
|
{
|
||||||
|
@ -172,7 +172,7 @@ bool pn53x_wrap_frame(const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t
|
||||||
|
|
||||||
// We start by calculating the frame length in bits
|
// We start by calculating the frame length in bits
|
||||||
*puiFrameBits = uiTxBits + (uiTxBits/8);
|
*puiFrameBits = uiTxBits + (uiTxBits/8);
|
||||||
|
|
||||||
// Parse the data bytes and add the parity bits
|
// Parse the data bytes and add the parity bits
|
||||||
// This is really a sensitive process, mirror the frame bytes and append parity bits
|
// This is really a sensitive process, mirror the frame bytes and append parity bits
|
||||||
// buffer = mirror(frame-byte) + parity + mirror(frame-byte) + parity + ...
|
// buffer = mirror(frame-byte) + parity + mirror(frame-byte) + parity + ...
|
||||||
|
@ -226,7 +226,7 @@ bool pn53x_unwrap_frame(const byte_t* pbtFrame, const uint32_t uiFrameBits, byte
|
||||||
*puiRxBits = uiFrameBits;
|
*puiRxBits = uiFrameBits;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the data length in bits
|
// Calculate the data length in bits
|
||||||
*puiRxBits = uiFrameBits - (uiFrameBits/9);
|
*puiRxBits = uiFrameBits - (uiFrameBits/9);
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ bool read_card()
|
||||||
|
|
||||||
// Set the authentication information (uid)
|
// Set the authentication information (uid)
|
||||||
memcpy(mp.mpa.abtUid,ti.tia.abtUid,4);
|
memcpy(mp.mpa.abtUid,ti.tia.abtUid,4);
|
||||||
|
|
||||||
// Determin if we should use the a or the b key
|
// Determin if we should use the a or the b key
|
||||||
if (bUseKeyA)
|
if (bUseKeyA)
|
||||||
{
|
{
|
||||||
|
|
|
@ -117,7 +117,7 @@ int main(int argc,char* argv[])
|
||||||
{
|
{
|
||||||
// Redirect the answer back to the reader
|
// Redirect the answer back to the reader
|
||||||
nfc_target_send_bits(pdiTag,abtTagRx,uiTagRxBits,abtTagRxPar);
|
nfc_target_send_bits(pdiTag,abtTagRx,uiTagRxBits,abtTagRxPar);
|
||||||
|
|
||||||
// Print the tag frame to the screen
|
// Print the tag frame to the screen
|
||||||
if(!quiet_output)
|
if(!quiet_output)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue