Rename "byte" type into "byte_t" type.

This commit is contained in:
Romuald Conty 2009-07-16 12:09:06 +00:00
parent 3b8a414cd2
commit e98e7d9415
22 changed files with 180 additions and 180 deletions

View file

@ -30,21 +30,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#define SAK_FLAG_ATS_SUPPORTED 0x20 #define SAK_FLAG_ATS_SUPPORTED 0x20
static byte abtRx[MAX_FRAME_LEN]; static byte_t abtRx[MAX_FRAME_LEN];
static uint32_t uiRxBits; static uint32_t uiRxBits;
static uint32_t uiRxLen; static uint32_t uiRxLen;
static byte abtUid[10]; static byte_t abtUid[10];
static uint32_t uiUidLen = 4; static uint32_t uiUidLen = 4;
static dev_info* pdi; static dev_info* pdi;
// ISO14443A Anti-Collision Commands // ISO14443A Anti-Collision Commands
byte abtReqa [1] = { 0x26 }; byte_t abtReqa [1] = { 0x26 };
byte abtSelectAll [2] = { 0x93,0x20 }; byte_t abtSelectAll [2] = { 0x93,0x20 };
byte abtSelectTag [9] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; byte_t abtSelectTag [9] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
byte abtRats [4] = { 0xe0,0x50,0xbc,0xa5 }; byte_t abtRats [4] = { 0xe0,0x50,0xbc,0xa5 };
byte abtHalt [4] = { 0x50,0x00,0x57,0xcd }; byte_t abtHalt [4] = { 0x50,0x00,0x57,0xcd };
bool transmit_bits(const byte* pbtTx, const uint32_t uiTxBits) bool transmit_bits(const byte_t* pbtTx, const uint32_t uiTxBits)
{ {
// Show transmitted command // Show transmitted command
printf("R: "); print_hex_bits(pbtTx,uiTxBits); printf("R: "); print_hex_bits(pbtTx,uiTxBits);
@ -60,7 +60,7 @@ bool transmit_bits(const byte* pbtTx, const uint32_t uiTxBits)
} }
bool transmit_bytes(const byte* pbtTx, const uint32_t uiTxLen) bool transmit_bytes(const byte_t* pbtTx, const uint32_t uiTxLen)
{ {
// Show transmitted command // Show transmitted command
printf("R: "); print_hex(pbtTx,uiTxLen); printf("R: "); print_hex(pbtTx,uiTxLen);

View file

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "bitutils.h" #include "bitutils.h"
const static byte OddParity[256] = { const static byte_t OddParity[256] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
@ -41,7 +41,7 @@ const static byte OddParity[256] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
}; };
const static byte ByteMirror[256] = { const static byte_t ByteMirror[256] = {
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30,
0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98,
0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64,
@ -64,12 +64,12 @@ const static byte ByteMirror[256] = {
0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
}; };
byte oddparity(const byte bt) byte_t oddparity(const byte_t bt)
{ {
return OddParity[bt]; return OddParity[bt];
} }
void oddparity_bytes(const byte* pbtData, const uint32_t uiLen, byte* pbtPar) void oddparity_bytes(const byte_t* pbtData, const uint32_t uiLen, byte_t* pbtPar)
{ {
uint32_t uiByteNr; uint32_t uiByteNr;
@ -80,24 +80,12 @@ void oddparity_bytes(const byte* pbtData, const uint32_t uiLen, byte* pbtPar)
} }
} }
byte mirror(byte bt) byte_t mirror(byte_t bt)
{ {
return ByteMirror[bt]; return ByteMirror[bt];
} }
uint32_t mirror32(uint32_t ui32Bits) void mirror_bytes(byte_t *pbts, uint32_t uiLen)
{
mirror_bytes((byte*)&ui32Bits,4);
return ui32Bits;
}
uint64_t mirror64(uint64_t ui64Bits)
{
mirror_bytes((byte*)&ui64Bits,8);
return ui64Bits;
}
void mirror_bytes(byte *pbts, uint32_t uiLen)
{ {
uint32_t btNr; uint32_t btNr;
@ -108,6 +96,18 @@ void mirror_bytes(byte *pbts, uint32_t uiLen)
} }
} }
uint32_t mirror32(uint32_t ui32Bits)
{
mirror_bytes((byte_t*)&ui32Bits,4);
return ui32Bits;
}
uint64_t mirror64(uint64_t ui64Bits)
{
mirror_bytes((byte_t*)&ui64Bits,8);
return ui64Bits;
}
uint32_t swap_endian32(const void* pui32) uint32_t swap_endian32(const void* pui32)
{ {
uint32_t ui32N = *((uint32_t*)pui32); uint32_t ui32N = *((uint32_t*)pui32);
@ -120,23 +120,23 @@ uint64_t swap_endian64(const void* pui64)
return (((ui64N&0xFF)<<56)+((ui64N&0xFF00)<<40)+((ui64N&0xFF0000)<<24)+((ui64N&0xFF000000)<<8)+((ui64N&0xFF00000000ull)>>8)+((ui64N&0xFF0000000000ull)>>24)+((ui64N&0xFF000000000000ull)>>40)+((ui64N&0xFF00000000000000ull)>>56)); return (((ui64N&0xFF)<<56)+((ui64N&0xFF00)<<40)+((ui64N&0xFF0000)<<24)+((ui64N&0xFF000000)<<8)+((ui64N&0xFF00000000ull)>>8)+((ui64N&0xFF0000000000ull)>>24)+((ui64N&0xFF000000000000ull)>>40)+((ui64N&0xFF00000000000000ull)>>56));
} }
void append_iso14443a_crc(byte* pbtData, uint32_t uiLen) void append_iso14443a_crc(byte_t* pbtData, uint32_t uiLen)
{ {
byte bt; byte_t bt;
uint32_t wCrc = 0x6363; uint32_t wCrc = 0x6363;
do { do {
bt = *pbtData++; bt = *pbtData++;
bt = (bt^(byte)(wCrc & 0x00FF)); bt = (bt^(byte_t)(wCrc & 0x00FF));
bt = (bt^(bt<<4)); bt = (bt^(bt<<4));
wCrc = (wCrc >> 8)^((uint32_t)bt << 8)^((uint32_t)bt<<3)^((uint32_t)bt>>4); wCrc = (wCrc >> 8)^((uint32_t)bt << 8)^((uint32_t)bt<<3)^((uint32_t)bt>>4);
} while (--uiLen); } while (--uiLen);
*pbtData++ = (byte) (wCrc & 0xFF); *pbtData++ = (byte_t) (wCrc & 0xFF);
*pbtData = (byte) ((wCrc >> 8) & 0xFF); *pbtData = (byte_t) ((wCrc >> 8) & 0xFF);
} }
void print_hex(const byte* pbtData, const uint32_t uiBytes) void print_hex(const byte_t* pbtData, const uint32_t uiBytes)
{ {
uint32_t uiPos; uint32_t uiPos;
@ -147,7 +147,7 @@ void print_hex(const byte* pbtData, const uint32_t uiBytes)
printf("\n"); printf("\n");
} }
void print_hex_bits(const byte* pbtData, const uint32_t uiBits) void print_hex_bits(const byte_t* pbtData, const uint32_t uiBits)
{ {
uint32_t uiPos; uint32_t uiPos;
uint32_t uiBytes = uiBits/8; uint32_t uiBytes = uiBits/8;
@ -163,7 +163,7 @@ void print_hex_bits(const byte* pbtData, const uint32_t uiBits)
printf("\n"); printf("\n");
} }
void print_hex_par(const byte* pbtData, const uint32_t uiBits, const byte* pbtDataPar) void print_hex_par(const byte_t* pbtData, const uint32_t uiBits, const byte_t* pbtDataPar)
{ {
uint32_t uiPos; uint32_t uiPos;
uint32_t uiBytes = uiBits/8; uint32_t uiBytes = uiBits/8;

View file

@ -23,24 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include <stdint.h> #include <stdint.h>
#include "defines.h" #include "types.h"
byte oddparity(const byte bt); byte_t oddparity(const byte_t bt);
void oddparity_bytes(const byte* pbtData, const uint32_t uiLen, byte* pbtPar); void oddparity_byte_ts(const byte_t* pbtData, const uint32_t uiLen, byte_t* pbtPar);
byte mirror(byte bt); byte_t mirror(byte_t bt);
uint32_t mirror32(uint32_t ui32Bits); uint32_t mirror32(uint32_t ui32Bits);
uint64_t mirror64(uint64_t ui64Bits); uint64_t mirror64(uint64_t ui64Bits);
void mirror_bytes(byte *pbts, uint32_t uiLen); void mirror_byte_ts(byte_t *pbts, uint32_t uiLen);
uint32_t swap_endian32(const void* pui32); uint32_t swap_endian32(const void* pui32);
uint64_t swap_endian64(const void* pui64); uint64_t swap_endian64(const void* pui64);
void append_iso14443a_crc(byte* pbtData, uint32_t uiLen); void append_iso14443a_crc(byte_t* pbtData, uint32_t uiLen);
void print_hex(const byte* pbtData, const uint32_t uiLen); void print_hex(const byte_t* pbtData, const uint32_t uiLen);
void print_hex_bits(const byte* pbtData, const uint32_t uiBits); void print_hex_bits(const byte_t* pbtData, const uint32_t uiBits);
void print_hex_par(const byte* pbtData, const uint32_t uiBits, const byte* pbtDataPar); void print_hex_par(const byte_t* pbtData, const uint32_t uiBits, const byte_t* pbtDataPar);
#endif // _LIBNFC_BITUTILS_H_ #endif // _LIBNFC_BITUTILS_H_

View file

@ -23,8 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
// #define DEBUG /* DEBUG flag can also be enabled using ./configure --enable-debug */ // #define DEBUG /* DEBUG flag can also be enabled using ./configure --enable-debug */
typedef unsigned char byte;
typedef void* dev_spec; // Device connection specification typedef void* dev_spec; // Device connection specification
#define INVALID_DEVICE_INFO 0 #define INVALID_DEVICE_INFO 0
#define MAX_FRAME_LEN 264 #define MAX_FRAME_LEN 264
@ -32,8 +30,8 @@ typedef void* dev_spec; // Device connection specification
#define MAX_DEVICES 16 #define MAX_DEVICES 16
// Useful macros // Useful macros
#define MIN(a,b) (((a) < (b)) ? (a) : (b)) //#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b)) //#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define INNER_XOR8(n) {n ^= (n >> 4); n ^= (n >> 2); n ^= (n >> 1); n &= 0x01; } #define INNER_XOR8(n) {n ^= (n >> 4); n ^= (n >> 2); n ^= (n >> 1); n &= 0x01; }
#define INNER_XOR32(n) {n ^= (n >> 16); n ^= (n >> 8); INNER_XOR8(n); } #define INNER_XOR32(n) {n ^= (n >> 16); n ^= (n >> 8); INNER_XOR8(n); }
#define INNER_XOR64(n) {n ^= (n >> 32); INNER_XOR32(n); } #define INNER_XOR64(n) {n ^= (n >> 32); INNER_XOR32(n); }

View file

@ -55,13 +55,13 @@ typedef struct {
SCARD_IO_REQUEST ioCard; SCARD_IO_REQUEST ioCard;
} dev_spec_acr122; } dev_spec_acr122;
static byte abtTxBuf[ACR122_WRAP_LEN+ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0x00 }; static byte_t abtTxBuf[ACR122_WRAP_LEN+ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0x00 };
static byte abtRxCmd[5] = { 0xFF,0xC0,0x00,0x00 }; static byte_t abtRxCmd[5] = { 0xFF,0xC0,0x00,0x00 };
static byte uiRxCmdLen = sizeof(abtRxCmd); static byte_t uiRxCmdLen = sizeof(abtRxCmd);
static byte abtRxBuf[ACR122_RESPONSE_LEN]; static byte_t abtRxBuf[ACR122_RESPONSE_LEN];
static size_t ulRxBufLen; static size_t ulRxBufLen;
static byte abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 }; static byte_t abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 };
static byte abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 }; static byte_t abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 };
dev_info* dev_acr122_connect(const uint32_t uiIndex) dev_info* dev_acr122_connect(const uint32_t uiIndex)
{ {
@ -178,7 +178,7 @@ void dev_acr122_disconnect(dev_info* pdi)
free(pdi); free(pdi);
} }
bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) bool dev_acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen)
{ {
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds; dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;
@ -247,7 +247,7 @@ char* dev_acr122_firmware(const dev_spec ds)
{ {
uiResult = SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtGetFw,sizeof(abtGetFw),abtFw,ulFwLen,(void*)&ulFwLen); uiResult = SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtGetFw,sizeof(abtGetFw),abtFw,ulFwLen,(void*)&ulFwLen);
} else { } else {
uiResult = SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtGetFw,sizeof(abtGetFw),NULL,(byte*)abtFw,(void*)&ulFwLen); uiResult = SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtGetFw,sizeof(abtGetFw),NULL,(byte_t*)abtFw,(void*)&ulFwLen);
} }
#ifdef DEBUG #ifdef DEBUG
@ -263,13 +263,13 @@ char* dev_acr122_firmware(const dev_spec ds)
bool dev_acr122_led_red(const dev_spec ds, bool bOn) bool dev_acr122_led_red(const dev_spec ds, bool bOn)
{ {
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds; dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;
byte abtBuf[2]; byte_t abtBuf[2];
size_t ulBufLen = sizeof(abtBuf); size_t ulBufLen = sizeof(abtBuf);
if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
{ {
return (SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtLed,sizeof(abtLed),abtBuf,ulBufLen,(void*)&ulBufLen) == SCARD_S_SUCCESS); return (SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtLed,sizeof(abtLed),abtBuf,ulBufLen,(void*)&ulBufLen) == SCARD_S_SUCCESS);
} else { } else {
return (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtLed,sizeof(abtLed),NULL,(byte*)abtBuf,(void*)&ulBufLen) == SCARD_S_SUCCESS); return (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtLed,sizeof(abtLed),NULL,(byte_t*)abtBuf,(void*)&ulBufLen) == SCARD_S_SUCCESS);
} }
} }

View file

@ -32,7 +32,7 @@ dev_info* dev_acr122_connect(const uint32_t uiIndex);
void dev_acr122_disconnect(dev_info* pdi); void dev_acr122_disconnect(dev_info* pdi);
// Callback function used by libnfc to transmit commands to the PN53X chip // Callback function used by libnfc to transmit commands to the PN53X chip
bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); bool dev_acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
// Various additional features this device supports // Various additional features this device supports
char* dev_acr122_firmware(const dev_spec ds); char* dev_acr122_firmware(const dev_spec ds);

View file

@ -34,7 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#define BUFFER_LENGTH 256 #define BUFFER_LENGTH 256
#define USB_TIMEOUT 30000 #define USB_TIMEOUT 30000
static byte abtTxBuf[BUFFER_LENGTH] = { 0x32, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" static byte_t abtTxBuf[BUFFER_LENGTH] = { 0x32, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
dev_info* dev_arygon_connect(const uint32_t uiIndex) dev_info* dev_arygon_connect(const uint32_t uiIndex)
{ {
@ -88,9 +88,9 @@ void dev_arygon_disconnect(dev_info* pdi)
free(pdi); free(pdi);
} }
bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) bool dev_arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen)
{ {
byte abtRxBuf[BUFFER_LENGTH]; byte_t abtRxBuf[BUFFER_LENGTH];
uint32_t uiRxBufLen = BUFFER_LENGTH; uint32_t uiRxBufLen = BUFFER_LENGTH;
uint32_t uiPos; uint32_t uiPos;

View file

@ -29,7 +29,7 @@ dev_info* dev_arygon_connect(const uint32_t uiIndex);
void dev_arygon_disconnect(dev_info* pdi); void dev_arygon_disconnect(dev_info* pdi);
// Callback function used by libnfc to transmit commands to the PN53X chip // Callback function used by libnfc to transmit commands to the PN53X chip
bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); bool dev_arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
#endif // _LIBNFC_DEV_ARYGON_H_ #endif // _LIBNFC_DEV_ARYGON_H_

View file

@ -171,7 +171,7 @@ void dev_pn531_disconnect(dev_info* pdi)
free(pdi); free(pdi);
} }
bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) bool dev_pn531_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;
@ -197,7 +197,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u
#ifdef DEBUG #ifdef DEBUG
printf("Tx: "); printf("Tx: ");
print_hex((byte*)buffer,uiTxLen+7); print_hex((byte_t*)buffer,uiTxLen+7);
#endif #endif
ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT); ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT);
@ -220,7 +220,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u
#ifdef DEBUG #ifdef DEBUG
printf("Rx: "); printf("Rx: ");
print_hex((byte*)buf,ret); print_hex((byte_t*)buf,ret);
#endif #endif
if( ret == 6 ) if( ret == 6 )
@ -236,7 +236,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u
#ifdef DEBUG #ifdef DEBUG
printf("Rx: "); printf("Rx: ");
print_hex((byte*)buf,ret); print_hex((byte_t*)buf,ret);
#endif #endif
} }

View file

@ -32,7 +32,7 @@ dev_info* dev_pn531_connect(const uint32_t uiIndex);
void dev_pn531_disconnect(dev_info* pdi); void dev_pn531_disconnect(dev_info* pdi);
// Callback function used by libnfc to transmit commands to the PN53X chip // Callback function used by libnfc to transmit commands to the PN53X chip
bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); bool dev_pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
#endif // _LIBNFC_DEV_PN531_H_ #endif // _LIBNFC_DEV_PN531_H_

View file

@ -166,7 +166,7 @@ void dev_pn533_disconnect(dev_info* pdi)
free(pdi); free(pdi);
} }
bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* 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;
@ -192,7 +192,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u
#ifdef DEBUG #ifdef DEBUG
printf("Tx: "); printf("Tx: ");
print_hex((byte*)buffer,uiTxLen+7); print_hex((byte_t*)buffer,uiTxLen+7);
#endif #endif
ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT); ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT);
@ -215,7 +215,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u
#ifdef DEBUG #ifdef DEBUG
printf("Rx: "); printf("Rx: ");
print_hex((byte*)buf,ret); print_hex((byte_t*)buf,ret);
#endif #endif
if( ret == 6 ) if( ret == 6 )
@ -231,7 +231,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u
#ifdef DEBUG #ifdef DEBUG
printf("Rx: "); printf("Rx: ");
print_hex((byte*)buf,ret); print_hex((byte_t*)buf,ret);
#endif #endif
} }

View file

@ -29,7 +29,7 @@ dev_info* dev_pn533_connect(const uint32_t uiIndex);
void dev_pn533_disconnect(dev_info* pdi); void dev_pn533_disconnect(dev_info* pdi);
// Callback function used by libnfc to transmit commands to the PN53X chip // Callback function used by libnfc to transmit commands to the PN53X chip
bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* 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);
#endif // _LIBNFC_DEV_PN533_H_ #endif // _LIBNFC_DEV_PN533_H_

View file

@ -26,18 +26,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "libnfc.h" #include "libnfc.h"
static byte abtRecv[MAX_FRAME_LEN]; static byte_t abtRecv[MAX_FRAME_LEN];
static uint32_t uiRecvBits; static uint32_t uiRecvBits;
static dev_info* pdi; static dev_info* pdi;
// ISO14443A Anti-Collision response // ISO14443A Anti-Collision response
byte abtAtqa [2] = { 0x04,0x00 }; byte_t abtAtqa [2] = { 0x04,0x00 };
byte abtUidBcc [5] = { 0xDE,0xAD,0xBE,0xAF,0x62 }; byte_t abtUidBcc [5] = { 0xDE,0xAD,0xBE,0xAF,0x62 };
byte abtSak [9] = { 0x08,0xb6,0xdd }; byte_t abtSak [9] = { 0x08,0xb6,0xdd };
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
byte* pbtTx = NULL; byte_t* pbtTx = NULL;
uint32_t uiTxBits; uint32_t uiTxBits;
// Try to open the NFC reader // Try to open the NFC reader

View file

@ -58,44 +58,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#define PARAM_NO_AMBLE 0x40 #define PARAM_NO_AMBLE 0x40
// PN53X configuration // PN53X configuration
byte pncmd_get_firmware_version [ 2] = { 0xD4,0x02 }; byte_t pncmd_get_firmware_version [ 2] = { 0xD4,0x02 };
byte pncmd_get_general_status [ 2] = { 0xD4,0x04 }; byte_t pncmd_get_general_status [ 2] = { 0xD4,0x04 };
byte pncmd_get_register [ 4] = { 0xD4,0x06 }; byte_t pncmd_get_register [ 4] = { 0xD4,0x06 };
byte pncmd_set_register [ 5] = { 0xD4,0x08 }; byte_t pncmd_set_register [ 5] = { 0xD4,0x08 };
byte pncmd_set_parameters [ 3] = { 0xD4,0x12 }; byte_t pncmd_set_parameters [ 3] = { 0xD4,0x12 };
// RF field configuration // RF field configuration
byte pncmd_rf_configure_field [ 4] = { 0xD4,0x32,0x01 }; byte_t pncmd_rf_configure_field [ 4] = { 0xD4,0x32,0x01 };
byte pncmd_rf_configure_timing [ 4] = { 0xD4,0x32,0x02 }; byte_t pncmd_rf_configure_timing [ 4] = { 0xD4,0x32,0x02 };
byte pncmd_rf_configure_retry_data [ 4] = { 0xD4,0x32,0x04 }; byte_t pncmd_rf_configure_retry_data [ 4] = { 0xD4,0x32,0x04 };
byte pncmd_rf_configure_retry_select [ 6] = { 0xD4,0x32,0x05 }; byte_t pncmd_rf_configure_retry_select [ 6] = { 0xD4,0x32,0x05 };
// Reader // Reader
byte pncmd_reader_list_passive [264] = { 0xD4,0x4A }; byte_t pncmd_reader_list_passive [264] = { 0xD4,0x4A };
byte pncmd_reader_select [ 3] = { 0xD4,0x54 }; byte_t pncmd_reader_select [ 3] = { 0xD4,0x54 };
byte pncmd_reader_deselect [ 3] = { 0xD4,0x44,0x00 }; byte_t pncmd_reader_deselect [ 3] = { 0xD4,0x44,0x00 };
byte pncmd_reader_release [ 3] = { 0xD4,0x52,0x00 }; byte_t pncmd_reader_release [ 3] = { 0xD4,0x52,0x00 };
byte pncmd_reader_set_baud_rate [ 5] = { 0xD4,0x4E }; byte_t pncmd_reader_set_baud_rate [ 5] = { 0xD4,0x4E };
byte pncmd_reader_exchange_data [265] = { 0xD4,0x40 }; byte_t pncmd_reader_exchange_data [265] = { 0xD4,0x40 };
byte pncmd_reader_auto_poll [ 5] = { 0xD4,0x60 }; byte_t pncmd_reader_auto_poll [ 5] = { 0xD4,0x60 };
// Target // Target
byte pncmd_target_get_data [ 2] = { 0xD4,0x86 }; byte_t pncmd_target_get_data [ 2] = { 0xD4,0x86 };
byte pncmd_target_init [ 39] = { 0xD4,0x8C }; byte_t pncmd_target_init [ 39] = { 0xD4,0x8C };
byte pncmd_target_virtual_card [ 4] = { 0xD4,0x14 }; byte_t pncmd_target_virtual_card [ 4] = { 0xD4,0x14 };
byte pncmd_target_receive [ 2] = { 0xD4,0x88 }; byte_t pncmd_target_receive [ 2] = { 0xD4,0x88 };
byte pncmd_target_send [264] = { 0xD4,0x90 }; byte_t pncmd_target_send [264] = { 0xD4,0x90 };
byte pncmd_target_get_status [ 2] = { 0xD4,0x8A }; byte_t pncmd_target_get_status [ 2] = { 0xD4,0x8A };
// Exchange raw data frames // Exchange raw data frames
byte pncmd_exchange_raw_data [266] = { 0xD4,0x42 }; byte_t pncmd_exchange_raw_data [266] = { 0xD4,0x42 };
// Global buffers used for communication with the PN53X chip // Global buffers used for communication with the PN53X chip
#define MAX_FRAME_LEN 264 #define MAX_FRAME_LEN 264
static byte abtRx[MAX_FRAME_LEN]; static byte_t abtRx[MAX_FRAME_LEN];
static uint32_t uiRxLen; static uint32_t uiRxLen;
bool pn53x_transceive(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen) bool pn53x_transceive(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen)
{ {
// Reset the receiving buffer // Reset the receiving buffer
uiRxLen = MAX_FRAME_LEN; uiRxLen = MAX_FRAME_LEN;
@ -110,7 +110,7 @@ bool pn53x_transceive(const dev_info* pdi, const byte* pbtTx, const uint32_t uiT
return true; return true;
} }
byte pn53x_get_reg(const dev_info* pdi, uint16_t ui16Reg) byte_t pn53x_get_reg(const dev_info* pdi, uint16_t ui16Reg)
{ {
uint8_t ui8Value; uint8_t ui8Value;
uint32_t uiValueLen = 1; uint32_t uiValueLen = 1;
@ -148,10 +148,10 @@ bool pn53x_set_tx_bits(const dev_info* pdi, uint8_t ui8Bits)
return true; return true;
} }
bool pn53x_wrap_frame(const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtFrame, uint32_t* puiFrameBits) bool pn53x_wrap_frame(const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar, byte_t* pbtFrame, uint32_t* puiFrameBits)
{ {
byte btFrame; byte_t btFrame;
byte btData; byte_t btData;
uint32_t uiBitPos; uint32_t uiBitPos;
uint32_t uiDataPos = 0; uint32_t uiDataPos = 0;
uint32_t uiBitsLeft = uiTxBits; uint32_t uiBitsLeft = uiTxBits;
@ -204,13 +204,13 @@ bool pn53x_wrap_frame(const byte* pbtTx, const uint32_t uiTxBits, const byte* pb
} }
} }
bool pn53x_unwrap_frame(const byte* pbtFrame, const uint32_t uiFrameBits, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar) bool pn53x_unwrap_frame(const byte_t* pbtFrame, const uint32_t uiFrameBits, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar)
{ {
byte btFrame; byte_t btFrame;
byte btData; byte_t btData;
uint8_t uiBitPos; uint8_t uiBitPos;
uint32_t uiDataPos = 0; uint32_t uiDataPos = 0;
byte* pbtFramePos = (byte*) pbtFrame; byte_t* pbtFramePos = (byte_t*) pbtFrame;
uint32_t uiBitsLeft = uiFrameBits; uint32_t uiBitsLeft = uiFrameBits;
// Make sure we should frame at least something // Make sure we should frame at least something
@ -254,7 +254,7 @@ dev_info* nfc_connect()
{ {
dev_info* pdi; dev_info* pdi;
uint32_t uiDev; uint32_t uiDev;
byte abtFw[4]; byte_t abtFw[4];
uint32_t uiFwLen = sizeof(abtFw); uint32_t uiFwLen = sizeof(abtFw);
// Search through the device list for an available device // Search through the device list for an available device
@ -312,7 +312,7 @@ void nfc_disconnect(dev_info* pdi)
bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable) bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable)
{ {
byte btValue; byte_t btValue;
// Make sure we are dealing with a active device // Make sure we are dealing with a active device
if (!pdi->bActive) return false; if (!pdi->bActive) return false;
@ -384,7 +384,7 @@ bool nfc_reader_init(const dev_info* pdi)
return true; return true;
} }
bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti) bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti)
{ {
// Make sure we are dealing with a active device // Make sure we are dealing with a active device
if (!pdi->bActive) return false; if (!pdi->bActive) return false;
@ -485,7 +485,7 @@ bool nfc_reader_deselect(const dev_info* pdi)
return (pdi->pdc->transceive(pdi->ds,pncmd_reader_deselect,3,NULL,NULL)); return (pdi->pdc->transceive(pdi->ds,pncmd_reader_deselect,3,NULL,NULL));
} }
bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar) bool nfc_reader_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar)
{ {
uint32_t uiFrameBits = 0; uint32_t uiFrameBits = 0;
uint32_t uiFrameBytes = 0; uint32_t uiFrameBytes = 0;
@ -539,7 +539,7 @@ bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const ui
return true; return true;
} }
bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen)
{ {
// We can not just send bytes without parity if while the PN53X expects we handled them // We can not just send bytes without parity if while the PN53X expects we handled them
if (!pdi->bPar) return false; if (!pdi->bPar) return false;
@ -608,7 +608,7 @@ bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8
} }
// When available, copy the parameter bytes // When available, copy the parameter bytes
if (uiParamLen) memcpy(pncmd_reader_exchange_data+5,(byte*)pmp,uiParamLen); if (uiParamLen) memcpy(pncmd_reader_exchange_data+5,(byte_t*)pmp,uiParamLen);
// Fire the mifare command // Fire the mifare command
if (!pn53x_transceive(pdi,pncmd_reader_exchange_data,5+uiParamLen)) return false; if (!pn53x_transceive(pdi,pncmd_reader_exchange_data,5+uiParamLen)) return false;
@ -620,7 +620,7 @@ bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8
return true; return true;
} }
bool nfc_target_init(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits) bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits)
{ {
uint8_t ui8Bits; uint8_t ui8Bits;
@ -670,7 +670,7 @@ bool nfc_target_init(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits)
return true; return true;
} }
bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar) bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar)
{ {
uint32_t uiFrameBits; uint32_t uiFrameBits;
uint8_t ui8Bits; uint8_t ui8Bits;
@ -700,7 +700,7 @@ bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBi
return true; return true;
} }
bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxLen) bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen)
{ {
// Try to gather a received frame from the reader // Try to gather a received frame from the reader
if (!pn53x_transceive(pdi,pncmd_target_receive,2)) return false; if (!pn53x_transceive(pdi,pncmd_target_receive,2)) return false;
@ -715,7 +715,7 @@ bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxL
return true; return true;
} }
bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar) bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar)
{ {
uint32_t uiFrameBits = 0; uint32_t uiFrameBits = 0;
uint32_t uiFrameBytes = 0; uint32_t uiFrameBytes = 0;
@ -750,7 +750,7 @@ bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t
} }
bool nfc_target_send_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen) bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen)
{ {
// We can not just send bytes without parity if while the PN53X expects we handled them // We can not just send bytes without parity if while the PN53X expects we handled them
if (!pdi->bPar) return false; if (!pdi->bPar) return false;

View file

@ -33,17 +33,17 @@ void nfc_disconnect(dev_info* pdi);
bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable); bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable);
bool nfc_reader_init(const dev_info* pdi); bool nfc_reader_init(const dev_info* pdi);
bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti); bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti);
bool nfc_reader_deselect(const dev_info* pdi); bool nfc_reader_deselect(const dev_info* pdi);
bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar); bool nfc_reader_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar);
bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp); bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp);
bool nfc_target_init(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits); bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits);
bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar); bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar);
bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxLen); bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen);
bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar); bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar);
bool nfc_target_send_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen); bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen);
#endif // _LIBNFC_H_ #endif // _LIBNFC_H_

View file

@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "libnfc.h" #include "libnfc.h"
static dev_info* pdi; static dev_info* pdi;
static byte abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 };
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {

View file

@ -231,7 +231,7 @@ int main(int argc, const char* argv[])
{ {
bool b4K; bool b4K;
bool bReadAction; bool bReadAction;
byte* pbtUID; byte_t* pbtUID;
FILE* pfKeys; FILE* pfKeys;
FILE* pfDump; FILE* pfDump;

View file

@ -24,21 +24,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "defines.h" #include "defines.h"
typedef struct { typedef struct {
byte abtUID[4]; byte_t abtUID[4];
byte btBCC; byte_t btBCC;
byte btUnknown; byte_t btUnknown;
byte abtATQA[2]; byte_t abtATQA[2];
byte abtUnknown[8]; byte_t abtUnknown[8];
} mifare_block_manufacturer; } mifare_block_manufacturer;
typedef struct { typedef struct {
byte abtData[16]; byte_t abtData[16];
} mifare_block_data; } mifare_block_data;
typedef struct { typedef struct {
byte abtKeyA[6]; byte_t abtKeyA[6];
byte abtAccessBits[4]; byte_t abtAccessBits[4];
byte abtKeyB[6]; byte_t abtKeyB[6];
} mifare_block_trailer; } mifare_block_trailer;
typedef union { typedef union {

View file

@ -25,11 +25,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "libnfc.h" #include "libnfc.h"
static byte abtReaderRx[MAX_FRAME_LEN]; static byte_t abtReaderRx[MAX_FRAME_LEN];
static byte abtReaderRxPar[MAX_FRAME_LEN]; static byte_t abtReaderRxPar[MAX_FRAME_LEN];
static uint32_t uiReaderRxBits; static uint32_t uiReaderRxBits;
static byte abtTagRx[MAX_FRAME_LEN]; static byte_t abtTagRx[MAX_FRAME_LEN];
static byte abtTagRxPar[MAX_FRAME_LEN]; static byte_t abtTagRxPar[MAX_FRAME_LEN];
static uint32_t uiTagRxBits; static uint32_t uiTagRxBits;
static dev_info* pdiReader; static dev_info* pdiReader;
static dev_info* pdiTag; static dev_info* pdiTag;

View file

@ -101,7 +101,7 @@ bool rs232_cts(const serial_port sp)
return (status & TIOCM_CTS); return (status & TIOCM_CTS);
} }
bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen) bool rs232_receive(const serial_port sp, byte_t* pbtRx, uint32_t* puiRxLen)
{ {
int iResult; int iResult;
uint32_t uiCount = 0; uint32_t uiCount = 0;
@ -132,7 +132,7 @@ bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen)
} }
} }
bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen) bool rs232_send(const serial_port sp, const byte_t* pbtTx, const uint32_t uiTxLen)
{ {
int iResult; int iResult;
iResult = write(((serial_port_unix*)sp)->fd,pbtTx,uiTxLen); iResult = write(((serial_port_unix*)sp)->fd,pbtTx,uiTxLen);
@ -209,12 +209,12 @@ bool rs232_cts(const serial_port sp)
return (dwStatus & MS_CTS_ON); return (dwStatus & MS_CTS_ON);
} }
bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen) bool rs232_receive(const serial_port sp, byte_t* pbtRx, uint32_t* puiRxLen)
{ {
return (ReadFile(((serial_port_windows*)sp)->hPort,pbtRx,*puiRxLen,(LPDWORD)puiRxLen,NULL) != NULL); return (ReadFile(((serial_port_windows*)sp)->hPort,pbtRx,*puiRxLen,(LPDWORD)puiRxLen,NULL) != NULL);
} }
bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen) bool rs232_send(const serial_port sp, const byte_t* pbtTx, const uint32_t uiTxLen)
{ {
DWORD dwTxLen; DWORD dwTxLen;
return (WriteFile(((serial_port_windows*)sp)->hPort,pbtTx,uiTxLen,&dwTxLen,NULL) != NULL); return (WriteFile(((serial_port_windows*)sp)->hPort,pbtTx,uiTxLen,&dwTxLen,NULL) != NULL);

View file

@ -49,8 +49,8 @@ typedef void* serial_port;
serial_port rs232_open(const char* pcPortName); serial_port rs232_open(const char* pcPortName);
void rs232_close(const serial_port sp); void rs232_close(const serial_port sp);
bool rs232_cts(const serial_port sp); bool rs232_cts(const serial_port sp);
bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen); bool rs232_receive(const serial_port sp, byte_t* pbtRx, uint32_t* puiRxLen);
bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen); bool rs232_send(const serial_port sp, const byte_t* pbtTx, const uint32_t uiTxLen);
#endif // _LIBNFC_RS232_H_ #endif // _LIBNFC_RS232_H_

View file

@ -26,7 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "defines.h" #include "defines.h"
// Compiler directive, set struct alignment to 1 byte for compatibility typedef uint8_t byte_t;
// Compiler directive, set struct alignment to 1 byte_t for compatibility
#pragma pack(1) #pragma pack(1)
typedef enum { typedef enum {
@ -51,7 +53,7 @@ typedef struct {
struct dev_callbacks { struct dev_callbacks {
const char* acDriver; // Driver description const char* acDriver; // Driver description
dev_info* (*connect)(const uint32_t uiIndex); dev_info* (*connect)(const uint32_t uiIndex);
bool (*transceive)(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); bool (*transceive)(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
void (*disconnect)(dev_info* pdi); void (*disconnect)(dev_info* pdi);
}; };
@ -77,37 +79,37 @@ typedef enum {
}init_modulation; }init_modulation;
typedef struct { typedef struct {
byte abtAtqa[2]; byte_t abtAtqa[2];
byte btSak; byte_t btSak;
uint32_t uiUidLen; uint32_t uiUidLen;
byte abtUid[10]; byte_t abtUid[10];
uint32_t uiAtsLen; uint32_t uiAtsLen;
byte abtAts[36]; byte_t abtAts[36];
}tag_info_iso14443a; }tag_info_iso14443a;
typedef struct { typedef struct {
uint32_t uiLen; uint32_t uiLen;
byte btResCode; byte_t btResCode;
byte abtId[8]; byte_t abtId[8];
byte abtPad[8]; byte_t abtPad[8];
byte abtSysCode[2]; byte_t abtSysCode[2];
}tag_info_felica; }tag_info_felica;
typedef struct { typedef struct {
byte abtAtqb[12]; byte_t abtAtqb[12];
byte abtId[4]; byte_t abtId[4];
byte btParam1; byte_t btParam1;
byte btParam2; byte_t btParam2;
byte btParam3; byte_t btParam3;
byte btParam4; byte_t btParam4;
byte btCid; byte_t btCid;
uint32_t uiInfLen; uint32_t uiInfLen;
byte abtInf[64]; byte_t abtInf[64];
}tag_info_iso14443b; }tag_info_iso14443b;
typedef struct { typedef struct {
byte btSensRes[2]; byte_t btSensRes[2];
byte btId[4]; byte_t btId[4];
}tag_info_jewel; }tag_info_jewel;
typedef union { typedef union {
@ -133,16 +135,16 @@ typedef enum {
// MIFARE Classic command params // MIFARE Classic command params
typedef struct { typedef struct {
byte abtKey[6]; byte_t abtKey[6];
byte abtUid[4]; byte_t abtUid[4];
}mifare_param_auth; }mifare_param_auth;
typedef struct { typedef struct {
byte abtData[16]; byte_t abtData[16];
}mifare_param_data; }mifare_param_data;
typedef struct { typedef struct {
byte abtValue[4]; byte_t abtValue[4];
}mifare_param_value; }mifare_param_value;
typedef union { typedef union {