Replace locally defined "null" to standard library defined "NULL" (stddef.h).
Replace "ulong" usage by "size_t" from standard library (since ulong type was only used to store sizeof() result).
This commit is contained in:
parent
ab3664b056
commit
f34857487d
9 changed files with 150 additions and 139 deletions
|
@ -13,7 +13,7 @@ AC_PATH_PROG(PKG_CONFIG, pkg-config)
|
||||||
|
|
||||||
# Checks for header files.
|
# Checks for header files.
|
||||||
AC_HEADER_STDC
|
AC_HEADER_STDC
|
||||||
AC_CHECK_HEADERS([stdlib.h stdint.h])
|
AC_CHECK_HEADERS([stdio.h stdlib.h stdint.h stddef.h])
|
||||||
|
|
||||||
|
|
||||||
# libusb
|
# libusb
|
||||||
|
|
|
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ bool transmit_bits(const byte* pbtTx, const uint32_t uiTxBits)
|
||||||
printf("R: "); print_hex_bits(pbtTx,uiTxBits);
|
printf("R: "); print_hex_bits(pbtTx,uiTxBits);
|
||||||
|
|
||||||
// Transmit the bit frame command, we don't use the arbitrary parity feature
|
// Transmit the bit frame command, we don't use the arbitrary parity feature
|
||||||
if (!nfc_reader_transceive_bits(pdi,pbtTx,uiTxBits,null,abtRx,&uiRxBits,null)) return false;
|
if (!nfc_reader_transceive_bits(pdi,pbtTx,uiTxBits,NULL,abtRx,&uiRxBits,NULL)) return false;
|
||||||
|
|
||||||
// Show received answer
|
// Show received answer
|
||||||
printf("T: "); print_hex_bits(abtRx,uiRxBits);
|
printf("T: "); print_hex_bits(abtRx,uiRxBits);
|
||||||
|
|
|
@ -21,15 +21,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#ifndef _LIBNFC_DEFINES_H_
|
#ifndef _LIBNFC_DEFINES_H_
|
||||||
#define _LIBNFC_DEFINES_H_
|
#define _LIBNFC_DEFINES_H_
|
||||||
|
|
||||||
// #define DEBUG
|
// #define DEBUG /* DEBUG flag can also be enabled using ./configure --enable-debug */
|
||||||
|
|
||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
typedef unsigned long ulong;
|
|
||||||
|
|
||||||
#define null 0
|
|
||||||
|
|
||||||
typedef void* dev_spec; // Device connection specification
|
typedef void* dev_spec; // Device connection specification
|
||||||
#define INVALID_DEVICE_INFO null
|
#define INVALID_DEVICE_INFO 0
|
||||||
#define MAX_FRAME_LEN 264
|
#define MAX_FRAME_LEN 264
|
||||||
#define DEVICE_NAME_LENGTH 256
|
#define DEVICE_NAME_LENGTH 256
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,16 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#include "dev_acr122.h"
|
||||||
|
|
||||||
#include "defines.h"
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <winscard.h>
|
#include <winscard.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include "defines.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include "dev_acr122.h"
|
|
||||||
#include "bitutils.h"
|
#include "bitutils.h"
|
||||||
|
|
||||||
// WINDOWS: #define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500)
|
// WINDOWS: #define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500)
|
||||||
|
@ -53,7 +55,7 @@ static byte abtTxBuf[ACR122_WRAP_LEN+ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0
|
||||||
static byte abtRxCmd[5] = { 0xFF,0xC0,0x00,0x00 };
|
static byte abtRxCmd[5] = { 0xFF,0xC0,0x00,0x00 };
|
||||||
static byte uiRxCmdLen = sizeof(abtRxCmd);
|
static byte uiRxCmdLen = sizeof(abtRxCmd);
|
||||||
static byte abtRxBuf[ACR122_RESPONSE_LEN];
|
static byte abtRxBuf[ACR122_RESPONSE_LEN];
|
||||||
static ulong ulRxBufLen;
|
static size_t ulRxBufLen;
|
||||||
static byte abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 };
|
static byte abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 };
|
||||||
static byte abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 };
|
static byte abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 };
|
||||||
|
|
||||||
|
@ -61,7 +63,7 @@ dev_info* dev_acr122_connect(const uint32_t uiIndex)
|
||||||
{
|
{
|
||||||
char* pacReaders[MAX_READERS];
|
char* pacReaders[MAX_READERS];
|
||||||
char acList[256+64*MAX_READERS];
|
char acList[256+64*MAX_READERS];
|
||||||
ulong ulListLen = sizeof(acList);
|
size_t ulListLen = sizeof(acList);
|
||||||
uint32_t uiPos;
|
uint32_t uiPos;
|
||||||
uint32_t uiReaderCount;
|
uint32_t uiReaderCount;
|
||||||
uint32_t uiReader;
|
uint32_t uiReader;
|
||||||
|
@ -75,10 +77,10 @@ dev_info* dev_acr122_connect(const uint32_t uiIndex)
|
||||||
memset(acList,0x00,ulListLen);
|
memset(acList,0x00,ulListLen);
|
||||||
|
|
||||||
// Test if context succeeded
|
// Test if context succeeded
|
||||||
if (SCardEstablishContext(SCARD_SCOPE_USER,null,null,&(dsa.hCtx)) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO;
|
if (SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&(dsa.hCtx)) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO;
|
||||||
|
|
||||||
// Retrieve the string array of all available pcsc readers
|
// Retrieve the string array of all available pcsc readers
|
||||||
if (SCardListReaders(dsa.hCtx,null,acList,(void*)&ulListLen) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO;
|
if (SCardListReaders(dsa.hCtx,NULL,acList,(void*)&ulListLen) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Found the following PCSC device(s)\n");
|
printf("Found the following PCSC device(s)\n");
|
||||||
|
@ -132,7 +134,7 @@ dev_info* dev_acr122_connect(const uint32_t uiIndex)
|
||||||
|
|
||||||
// Retrieve the current firmware version
|
// Retrieve the current firmware version
|
||||||
pcFirmware = dev_acr122_firmware((dev_info*)&dsa);
|
pcFirmware = dev_acr122_firmware((dev_info*)&dsa);
|
||||||
if (strstr(pcFirmware,FIRMWARE_TEXT) != null)
|
if (strstr(pcFirmware,FIRMWARE_TEXT) != NULL)
|
||||||
{
|
{
|
||||||
// We found a occurence, test if it has the right index
|
// We found a occurence, test if it has the right index
|
||||||
if (uiDevIndex != 0)
|
if (uiDevIndex != 0)
|
||||||
|
@ -194,7 +196,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t
|
||||||
{
|
{
|
||||||
if (SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtTxBuf,uiTxLen+5,abtRxBuf,ulRxBufLen,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false;
|
if (SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtTxBuf,uiTxLen+5,abtRxBuf,ulRxBufLen,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false;
|
||||||
} else {
|
} else {
|
||||||
if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtTxBuf,uiTxLen+5,null,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false;
|
if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtTxBuf,uiTxLen+5,NULL,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_T0)
|
if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_T0)
|
||||||
|
@ -208,7 +210,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t
|
||||||
// Retrieve the response bytes
|
// Retrieve the response bytes
|
||||||
abtRxCmd[4] = abtRxBuf[1];
|
abtRxCmd[4] = abtRxBuf[1];
|
||||||
ulRxBufLen = sizeof(abtRxBuf);
|
ulRxBufLen = sizeof(abtRxBuf);
|
||||||
if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtRxCmd,uiRxCmdLen,null,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false;
|
if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtRxCmd,uiRxCmdLen,NULL,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -217,7 +219,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t
|
||||||
#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;
|
||||||
|
|
||||||
// Make sure we have an emulated answer that fits the return buffer
|
// Make sure we have an emulated answer that fits the return buffer
|
||||||
if (ulRxBufLen < 4 || (ulRxBufLen-4) > *puiRxLen) return false;
|
if (ulRxBufLen < 4 || (ulRxBufLen-4) > *puiRxLen) return false;
|
||||||
|
@ -235,13 +237,13 @@ char* dev_acr122_firmware(const dev_spec ds)
|
||||||
|
|
||||||
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;
|
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;
|
||||||
static char abtFw[11];
|
static char abtFw[11];
|
||||||
ulong ulFwLen = sizeof(abtFw);
|
size_t ulFwLen = sizeof(abtFw);
|
||||||
memset(abtFw,0x00,ulFwLen);
|
memset(abtFw,0x00,ulFwLen);
|
||||||
if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
|
if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
|
||||||
{
|
{
|
||||||
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*)abtFw,(void*)&ulFwLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -258,12 +260,12 @@ 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 abtBuf[2];
|
||||||
ulong 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*)abtBuf,(void*)&ulBufLen) == SCARD_S_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,13 @@ Thanks to d18c7db and Okko for example code
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "defines.h"
|
#include <stdio.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
#include "dev_pn531.h"
|
#include "dev_pn531.h"
|
||||||
#include "bitutils.h"
|
#include "bitutils.h"
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ dev_info* dev_pn531_connect(const uint32_t uiIndex)
|
||||||
|
|
||||||
dsp.uiEndPointIn = 0;
|
dsp.uiEndPointIn = 0;
|
||||||
dsp.uiEndPointOut = 0;
|
dsp.uiEndPointOut = 0;
|
||||||
dsp.pudh = null;
|
dsp.pudh = NULL;
|
||||||
|
|
||||||
usb_init();
|
usb_init();
|
||||||
if (usb_find_busses() < 0) return INVALID_DEVICE_INFO;
|
if (usb_find_busses() < 0) return INVALID_DEVICE_INFO;
|
||||||
|
@ -234,7 +236,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
if(ret < 9) return false;
|
if(ret < 9) return false;
|
||||||
|
|
|
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ byte abtSak [9] = { 0x08,0xb6,0xdd };
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
byte* pbtTx = null;
|
byte* pbtTx = NULL;
|
||||||
uint32_t uiTxBits;
|
uint32_t uiTxBits;
|
||||||
|
|
||||||
// Try to open the NFC reader
|
// Try to open the NFC reader
|
||||||
|
@ -68,7 +69,7 @@ int main(int argc, const char* argv[])
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
// Test if we received a frame
|
// Test if we received a frame
|
||||||
if (nfc_target_receive_bits(pdi,abtRecv,&uiRecvBits,null))
|
if (nfc_target_receive_bits(pdi,abtRecv,&uiRecvBits,NULL))
|
||||||
{
|
{
|
||||||
// Prepare the command to send back for the anti-collision request
|
// Prepare the command to send back for the anti-collision request
|
||||||
switch(uiRecvBits)
|
switch(uiRecvBits)
|
||||||
|
@ -102,7 +103,7 @@ int main(int argc, const char* argv[])
|
||||||
if(uiTxBits)
|
if(uiTxBits)
|
||||||
{
|
{
|
||||||
// Send and print the command to the screen
|
// Send and print the command to the screen
|
||||||
nfc_target_send_bits(pdi,pbtTx,uiTxBits,null);
|
nfc_target_send_bits(pdi,pbtTx,uiTxBits,NULL);
|
||||||
printf("T: ");
|
printf("T: ");
|
||||||
print_hex_bits(pbtTx,uiTxBits);
|
print_hex_bits(pbtTx,uiTxBits);
|
||||||
}
|
}
|
||||||
|
|
19
src/libnfc.c
19
src/libnfc.c
|
@ -19,10 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libnfc.h"
|
#include "libnfc.h"
|
||||||
#include "bitutils.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "bitutils.h"
|
||||||
|
|
||||||
// Registers and symbols masks used to covers parts within a register
|
// Registers and symbols masks used to covers parts within a register
|
||||||
#define REG_CIU_TX_MODE 0x6302
|
#define REG_CIU_TX_MODE 0x6302
|
||||||
#define SYMBOL_TX_CRC_ENABLE 0x80
|
#define SYMBOL_TX_CRC_ENABLE 0x80
|
||||||
|
@ -120,13 +123,13 @@ bool pn53x_set_reg(const dev_info* pdi, uint16_t ui16Reg, uint8_t ui8SybmolMask,
|
||||||
pncmd_set_register[2] = ui16Reg >> 8;
|
pncmd_set_register[2] = ui16Reg >> 8;
|
||||||
pncmd_set_register[3] = ui16Reg & 0xff;
|
pncmd_set_register[3] = ui16Reg & 0xff;
|
||||||
pncmd_set_register[4] = ui8Value | (pn53x_get_reg(pdi,ui16Reg) & (~ui8SybmolMask));
|
pncmd_set_register[4] = ui8Value | (pn53x_get_reg(pdi,ui16Reg) & (~ui8SybmolMask));
|
||||||
return pdi->pdc->transceive(pdi->ds,pncmd_set_register,5,null,null);
|
return pdi->pdc->transceive(pdi->ds,pncmd_set_register,5,NULL,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pn53x_set_parameters(const dev_info* pdi, uint8_t ui8Value)
|
bool pn53x_set_parameters(const dev_info* pdi, uint8_t ui8Value)
|
||||||
{
|
{
|
||||||
pncmd_set_parameters[2] = ui8Value;
|
pncmd_set_parameters[2] = ui8Value;
|
||||||
return pdi->pdc->transceive(pdi->ds,pncmd_set_parameters,3,null,null);
|
return pdi->pdc->transceive(pdi->ds,pncmd_set_parameters,3,NULL,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pn53x_set_tx_bits(const dev_info* pdi, uint8_t ui8Bits)
|
bool pn53x_set_tx_bits(const dev_info* pdi, uint8_t ui8Bits)
|
||||||
|
@ -233,7 +236,7 @@ bool pn53x_unwrap_frame(const byte* pbtFrame, const uint32_t uiFrameBits, byte*
|
||||||
btFrame = mirror(pbtFramePos[uiDataPos+1]);
|
btFrame = mirror(pbtFramePos[uiDataPos+1]);
|
||||||
btData |= (btFrame >> (8-uiBitPos));
|
btData |= (btFrame >> (8-uiBitPos));
|
||||||
pbtRx[uiDataPos] = mirror(btData);
|
pbtRx[uiDataPos] = mirror(btData);
|
||||||
if(pbtRxPar != null) pbtRxPar[uiDataPos] = ((btFrame >> (7-uiBitPos)) & 0x01);
|
if(pbtRxPar != NULL) pbtRxPar[uiDataPos] = ((btFrame >> (7-uiBitPos)) & 0x01);
|
||||||
// Increase the data (without parity bit) position
|
// Increase the data (without parity bit) position
|
||||||
uiDataPos++;
|
uiDataPos++;
|
||||||
// Test if we are done
|
// Test if we are done
|
||||||
|
@ -263,7 +266,7 @@ dev_info* nfc_connect()
|
||||||
{
|
{
|
||||||
// Great we have claimed a device
|
// Great we have claimed a device
|
||||||
pdi->pdc = &(dev_callbacks_list[uiDev]);
|
pdi->pdc = &(dev_callbacks_list[uiDev]);
|
||||||
pdi->pdc->transceive(pdi->ds,pncmd_get_register,4,null,null);
|
pdi->pdc->transceive(pdi->ds,pncmd_get_register,4,NULL,NULL);
|
||||||
|
|
||||||
// Try to retrieve PN53x chip revision
|
// Try to retrieve PN53x chip revision
|
||||||
if (!pdi->pdc->transceive(pdi->ds,pncmd_get_firmware_version,2,abtFw,&uiFwLen))
|
if (!pdi->pdc->transceive(pdi->ds,pncmd_get_firmware_version,2,abtFw,&uiFwLen))
|
||||||
|
@ -332,7 +335,7 @@ bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnabl
|
||||||
|
|
||||||
case DCO_ACTIVATE_FIELD:
|
case DCO_ACTIVATE_FIELD:
|
||||||
pncmd_rf_configure_field[3] = (bEnable) ? 1 : 0;
|
pncmd_rf_configure_field[3] = (bEnable) ? 1 : 0;
|
||||||
if (!pdi->pdc->transceive(pdi->ds,pncmd_rf_configure_field,4,null,null)) return false;
|
if (!pdi->pdc->transceive(pdi->ds,pncmd_rf_configure_field,4,NULL,NULL)) return false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DCO_ACTIVATE_CRYPTO1:
|
case DCO_ACTIVATE_CRYPTO1:
|
||||||
|
@ -345,7 +348,7 @@ bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnabl
|
||||||
pncmd_rf_configure_retry_select[3] = (bEnable) ? 0xff : 0x00; // MxRtyATR, default: active = 0xff, passive = 0x02
|
pncmd_rf_configure_retry_select[3] = (bEnable) ? 0xff : 0x00; // MxRtyATR, default: active = 0xff, passive = 0x02
|
||||||
pncmd_rf_configure_retry_select[4] = (bEnable) ? 0xff : 0x00; // MxRtyPSL, default: 0x01
|
pncmd_rf_configure_retry_select[4] = (bEnable) ? 0xff : 0x00; // MxRtyPSL, default: 0x01
|
||||||
pncmd_rf_configure_retry_select[5] = (bEnable) ? 0xff : 0x00; // MxRtyPassiveActivation, default: 0xff
|
pncmd_rf_configure_retry_select[5] = (bEnable) ? 0xff : 0x00; // MxRtyPassiveActivation, default: 0xff
|
||||||
if(!pdi->pdc->transceive(pdi->ds,pncmd_rf_configure_retry_select,6,null,null)) return false;
|
if(!pdi->pdc->transceive(pdi->ds,pncmd_rf_configure_retry_select,6,NULL,NULL)) return false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DCO_ACCEPT_INVALID_FRAMES:
|
case DCO_ACCEPT_INVALID_FRAMES:
|
||||||
|
@ -477,7 +480,7 @@ bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte
|
||||||
|
|
||||||
bool nfc_reader_deselect(const dev_info* pdi)
|
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* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar)
|
||||||
|
|
|
@ -19,8 +19,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "libnfc.h"
|
#include "libnfc.h"
|
||||||
|
|
||||||
static dev_info* pdi;
|
static dev_info* pdi;
|
||||||
|
@ -56,7 +59,7 @@ int main(int argc, const char* argv[])
|
||||||
printf("\nConnected to NFC reader: %s\n\n",pdi->acName);
|
printf("\nConnected to NFC reader: %s\n\n",pdi->acName);
|
||||||
|
|
||||||
// Poll for a ISO14443A (MIFARE) tag
|
// Poll for a ISO14443A (MIFARE) tag
|
||||||
if (nfc_reader_select(pdi,IM_ISO14443A_106,null,null,&ti))
|
if (nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti))
|
||||||
{
|
{
|
||||||
printf("The following (NFC) ISO14443A tag was found:\n\n");
|
printf("The following (NFC) ISO14443A tag was found:\n\n");
|
||||||
printf(" ATQA (SENS_RES): "); print_hex(ti.tia.abtAtqa,2);
|
printf(" ATQA (SENS_RES): "); print_hex(ti.tia.abtAtqa,2);
|
||||||
|
@ -78,14 +81,14 @@ int main(int argc, const char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll for a ISO14443B tag
|
// Poll for a ISO14443B tag
|
||||||
if (nfc_reader_select(pdi,IM_ISO14443B_106,null,null,&ti))
|
if (nfc_reader_select(pdi,IM_ISO14443B_106,NULL,NULL,&ti))
|
||||||
{
|
{
|
||||||
// No test results yet
|
// No test results yet
|
||||||
printf("iso14443b\n");
|
printf("iso14443b\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll for a Jewel tag
|
// Poll for a Jewel tag
|
||||||
if (nfc_reader_select(pdi,IM_JEWEL_106,null,null,&ti))
|
if (nfc_reader_select(pdi,IM_JEWEL_106,NULL,NULL,&ti))
|
||||||
{
|
{
|
||||||
// No test results yet
|
// No test results yet
|
||||||
printf("jewel\n");
|
printf("jewel\n");
|
||||||
|
|
14
src/mftool.c
14
src/mftool.c
|
@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
@ -72,7 +74,7 @@ bool read_card()
|
||||||
{
|
{
|
||||||
printf("x");
|
printf("x");
|
||||||
// When a failure occured we need to redo the anti-collision
|
// When a failure occured we need to redo the anti-collision
|
||||||
if (!nfc_reader_select(pdi,IM_ISO14443A_106,null,null,&ti))
|
if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti))
|
||||||
{
|
{
|
||||||
printf("!\nError: tag was removed\n");
|
printf("!\nError: tag was removed\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -155,7 +157,7 @@ bool write_card()
|
||||||
{
|
{
|
||||||
printf("x");
|
printf("x");
|
||||||
// When a failure occured we need to redo the anti-collision
|
// When a failure occured we need to redo the anti-collision
|
||||||
if (!nfc_reader_select(pdi,IM_ISO14443A_106,null,null,&ti))
|
if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti))
|
||||||
{
|
{
|
||||||
printf("!\nError: tag was removed\n");
|
printf("!\nError: tag was removed\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -251,7 +253,7 @@ int main(int argc, const char* argv[])
|
||||||
bUseKeyA = (tolower(*(argv[2])) == 'a');
|
bUseKeyA = (tolower(*(argv[2])) == 'a');
|
||||||
|
|
||||||
pfKeys = fopen(argv[3],"rb");
|
pfKeys = fopen(argv[3],"rb");
|
||||||
if (pfKeys == null)
|
if (pfKeys == NULL)
|
||||||
{
|
{
|
||||||
printf("Could not open file: %s\n",argv[3]);
|
printf("Could not open file: %s\n",argv[3]);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -270,7 +272,7 @@ int main(int argc, const char* argv[])
|
||||||
} else {
|
} else {
|
||||||
pfDump = fopen(argv[4],"rb");
|
pfDump = fopen(argv[4],"rb");
|
||||||
|
|
||||||
if (pfDump == null)
|
if (pfDump == NULL)
|
||||||
{
|
{
|
||||||
printf("Could not open dump file: %s\n",argv[4]);
|
printf("Could not open dump file: %s\n",argv[4]);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -310,7 +312,7 @@ int main(int argc, const char* argv[])
|
||||||
printf("Connected to NFC reader: %s\n",pdi->acName);
|
printf("Connected to NFC reader: %s\n",pdi->acName);
|
||||||
|
|
||||||
// Try to find a MIFARE Classic tag
|
// Try to find a MIFARE Classic tag
|
||||||
if (!nfc_reader_select(pdi,IM_ISO14443A_106,null,null,&ti))
|
if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti))
|
||||||
{
|
{
|
||||||
printf("Error: no tag was found\n");
|
printf("Error: no tag was found\n");
|
||||||
nfc_disconnect(pdi);
|
nfc_disconnect(pdi);
|
||||||
|
@ -349,7 +351,7 @@ int main(int argc, const char* argv[])
|
||||||
printf("Writing data to file: %s\n",argv[4]);
|
printf("Writing data to file: %s\n",argv[4]);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
pfDump = fopen(argv[4],"wb");
|
pfDump = fopen(argv[4],"wb");
|
||||||
if (pfKeys == null)
|
if (pfKeys == NULL)
|
||||||
{
|
{
|
||||||
printf("Could not open file: %s\n",argv[4]);
|
printf("Could not open file: %s\n",argv[4]);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue