Code cleanup.

This commit is contained in:
Romuald Conty 2009-09-08 08:14:36 +00:00
parent 30c2fc4c93
commit 67aa84ad76
5 changed files with 28 additions and 34 deletions

View file

@ -118,28 +118,22 @@ dev_info* dev_pn533_connect(const nfc_device_desc_t* device_desc)
uiDevIndex--;
continue;
}
#ifdef DEBUG
printf("Found PN533 device\n");
#endif
DBG("Found PN533 device.");
// Open the PN533 USB device
dsp.pudh = usb_open(dev);
get_end_points(dev,&dsp);
if(usb_set_configuration(dsp.pudh,1) < 0)
{
#ifdef DEBUG
printf("Setting config failed\n");
#endif
usb_close(dsp.pudh);
get_end_points(dev,&dsp);
if(usb_set_configuration(dsp.pudh,1) < 0)
{
DBG("Setting config failed");
usb_close(dsp.pudh);
return INVALID_DEVICE_INFO;
}
if(usb_claim_interface(dsp.pudh,0) < 0)
{
#ifdef DEBUG
printf("Can't claim interface\n");
#endif
DBG("Can't claim interface");
usb_close(dsp.pudh);
return INVALID_DEVICE_INFO;
}
@ -159,43 +153,43 @@ dev_info* dev_pn533_connect(const nfc_device_desc_t* device_desc)
}
}
return pdi;
}
}
void dev_pn533_disconnect(dev_info* pdi)
{
dev_spec_pn533* pdsp = (dev_spec_pn533*)pdi->ds;
usb_release_interface(pdsp->pudh,0);
usb_close(pdsp->pudh);
usb_close(pdsp->pudh);
free(pdi->ds);
free(pdi);
}
}
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;
int ret = 0;
{
uint32_t uiPos = 0;
int ret = 0;
char buf[BUFFER_LENGTH];
dev_spec_pn533* pdsp = (dev_spec_pn533*)ds;
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
buffer[3] = uiTxLen;
buffer[3] = uiTxLen;
// Packet length checksum
buffer[4] = BUFFER_LENGTH - buffer[3];
buffer[4] = BUFFER_LENGTH - buffer[3];
// Copy the PN53X command into the packet buffer
memmove(buffer+5,pbtTx,uiTxLen);
// Calculate data payload checksum
buffer[uiTxLen+5] = 0;
buffer[uiTxLen+5] = 0;
for(uiPos=0; uiPos < uiTxLen; uiPos++)
{
buffer[uiTxLen+5] -= buffer[uiPos+5];
}
// End of stream marker
buffer[uiTxLen+6] = 0;
buffer[uiTxLen+6] = 0;
#ifdef DEBUG
printf("Tx: ");
printf(" TX: ");
print_hex((byte_t*)buffer,uiTxLen+7);
#endif
@ -218,7 +212,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t
}
#ifdef DEBUG
printf("Rx: ");
printf(" RX: ");
print_hex((byte_t*)buf,ret);
#endif
@ -234,12 +228,12 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t
}
#ifdef DEBUG
printf("Rx: ");
printf(" RX: ");
print_hex((byte_t*)buf,ret);
#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;
// Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable)

View file

@ -31,7 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "dev_arygon.h"
const static struct dev_callbacks dev_callbacks_list[] = {
// Driver Name Connect Transceive Disconect
// Driver Name Connect Transceive Disconnect
#ifdef HAVE_PCSC_LITE
{ "ACR122", dev_acr122_connect, dev_acr122_transceive, dev_acr122_disconnect },
#endif

View file

@ -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
if (!pn53x_set_reg(pdi,REG_CIU_BIT_FRAMING,SYMBOL_TX_LAST_BITS,ui8Bits)) return false;
// Store the new setting
((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
if (uiBitsLeft == 0) return false;
// Handle a short response (1byte) as a special case
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
*puiFrameBits = uiTxBits + (uiTxBits/8);
// Parse the data bytes and add the 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 + ...
@ -226,7 +226,7 @@ bool pn53x_unwrap_frame(const byte_t* pbtFrame, const uint32_t uiFrameBits, byte
*puiRxBits = uiFrameBits;
return true;
}
// Calculate the data length in bits
*puiRxBits = uiFrameBits - (uiFrameBits/9);

View file

@ -92,7 +92,7 @@ bool read_card()
// Set the authentication information (uid)
memcpy(mp.mpa.abtUid,ti.tia.abtUid,4);
// Determin if we should use the a or the b key
if (bUseKeyA)
{

View file

@ -117,7 +117,7 @@ int main(int argc,char* argv[])
{
// Redirect the answer back to the reader
nfc_target_send_bits(pdiTag,abtTagRx,uiTagRxBits,abtTagRxPar);
// Print the tag frame to the screen
if(!quiet_output)
{