Hardware abstraction layer for libnfc:
Suppress any PN53x references in nfc.c Improve nfc_driver_t struct to embedded HAL API Merge macros from nfc-messages.h into nfc-internal.h Remove useless files: nfc-messages.h, buses.h and chips.h Implement HAL for ARYGON driver Move send/receive callbacks from nfc_driver_t to internal chip io callbacks (since there are dedicated to pn53x framing)
This commit is contained in:
parent
9b202d1dbf
commit
0efa47880b
17 changed files with 153 additions and 178 deletions
|
@ -1,5 +1,5 @@
|
|||
|
||||
nfcinclude_HEADERS = nfc.h nfc-types.h nfc-messages.h
|
||||
nfcinclude_HEADERS = nfc.h nfc-types.h
|
||||
nfcincludedir = $(includedir)/nfc
|
||||
|
||||
EXTRA_DIST = CMakeLists.txt
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* Public platform independent Near Field Communication (NFC) library
|
||||
*
|
||||
* Copyright (C) 2009, Roel Verdult
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*
|
||||
* @file nfc-messages.h
|
||||
* @brief Printing macros
|
||||
*/
|
||||
// TODO remove this file from installed headers.
|
||||
#ifndef _LIBNFC_MESSAGES_H_
|
||||
# define _LIBNFC_MESSAGES_H_
|
||||
|
||||
# include <err.h>
|
||||
|
||||
// #define DEBUG /* DEBUG flag can also be enabled using ./configure --enable-debug */
|
||||
|
||||
// Useful macros
|
||||
# ifdef DEBUG
|
||||
// #define DBG(x, args...) printf("DBG %s:%d: " x "\n", __FILE__, __LINE__,## args )
|
||||
# define DBG(...) do { \
|
||||
warnx ("DBG %s:%d", __FILE__, __LINE__); \
|
||||
warnx (" " __VA_ARGS__ ); \
|
||||
} while (0)
|
||||
# else
|
||||
# define DBG(...) {}
|
||||
# endif
|
||||
|
||||
# define WARN(...) warnx ("WARNING: " __VA_ARGS__ )
|
||||
# define ERR(...) warnx ("ERROR: " __VA_ARGS__ )
|
||||
|
||||
#endif // _LIBNFC_MESSAGES_H_
|
|
@ -3,7 +3,7 @@ SUBDIRS = chips buses drivers .
|
|||
# set the include path found by configure
|
||||
INCLUDES = $(all_includes) $(LIBNFC_CFLAGS)
|
||||
|
||||
noinst_HEADERS = chips.h buses.h drivers.h mirror-subr.h nfc-internal.h
|
||||
noinst_HEADERS = drivers.h mirror-subr.h nfc-internal.h
|
||||
lib_LTLIBRARIES = libnfc.la
|
||||
libnfc_la_SOURCES = nfc.c iso14443-subr.c mirror-subr.c
|
||||
libnfc_la_LDFLAGS = -no-undefined -version-info 1:0:0
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/**
|
||||
* Public platform independent Near Field Communication (NFC) library
|
||||
*
|
||||
* Copyright (C) 2009, Roel Verdult
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*
|
||||
* @file buses.h
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#include <nfc/nfc-types.h>
|
|
@ -30,7 +30,7 @@
|
|||
#include "uart.h"
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "libnfc/nfc-internal.h"
|
||||
|
||||
// Test if we are dealing with unix operating systems
|
||||
#ifndef _WIN32
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/*-
|
||||
* Public platform independent Near Field Communication (NFC) library
|
||||
*
|
||||
* Copyright (C) 2009, 2010, Roel Verdult, Romuald Conty
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file chips.h
|
||||
* @brief NFC chips header
|
||||
*/
|
||||
|
||||
#ifndef __NFC_CHIPS_H__
|
||||
# define __NFC_CHIPS_H__
|
||||
|
||||
# include <nfc/nfc-types.h>
|
||||
|
||||
# include "chips/pn53x.h"
|
||||
|
||||
#endif // __NFC_CHIPS_H__
|
|
@ -20,10 +20,12 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file pn53x.h
|
||||
* @file pn53x.c
|
||||
* @brief PN531, PN532 and PN533 common functions
|
||||
*/
|
||||
|
||||
/* vim:set ts=2 sw=2 et: */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
@ -34,7 +36,6 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
|
||||
#include "pn53x.h"
|
||||
#include "pn53x-internal.h"
|
||||
|
@ -47,6 +48,8 @@
|
|||
|
||||
#include <sys/param.h>
|
||||
|
||||
// TODO: reorder functions according to header
|
||||
|
||||
// TODO: Count max bytes for InJumpForDEP reply
|
||||
const byte_t pncmd_initiator_jump_for_dep[68] = { 0xD4, 0x56 };
|
||||
|
||||
|
@ -134,9 +137,9 @@ pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, b
|
|||
}
|
||||
|
||||
// Call the send/receice callback functions of the current driver
|
||||
if (!pnd->driver->send (pnd, pbtTx, szTx))
|
||||
if (!((struct pn53x_data*)(pnd->chip_data))->io->send (pnd, pbtTx, szTx))
|
||||
return false;
|
||||
int res = pnd->driver->receive (pnd, pbtRx, *pszRx);
|
||||
int res = ((struct pn53x_data*)(pnd->chip_data))->io->receive (pnd, pbtRx, *pszRx);
|
||||
if (res < 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -490,6 +493,19 @@ pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, pn53x_typ
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_initiator_init (nfc_device_t * pnd)
|
||||
{
|
||||
// Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards)
|
||||
if (!pn53x_write_register (pnd, REG_CIU_TX_AUTO, SYMBOL_FORCE_100_ASK, 0x40))
|
||||
return false;
|
||||
|
||||
// Configure the PN53X to be an Initiator or Reader/Writer
|
||||
if (!pn53x_write_register (pnd, REG_CIU_CONTROL, SYMBOL_INITIATOR, 0x10))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_initiator_select_passive_target (nfc_device_t * pnd,
|
||||
const nfc_modulation_t nm,
|
||||
|
@ -548,6 +564,11 @@ pn53x_initiator_poll_targets (nfc_device_t * pnd,
|
|||
return pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, btPollNr, btPeriod, pntTargets, pszTargetFound);
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_initiator_deselect_target (nfc_device_t * pnd)
|
||||
{
|
||||
return (pn53x_InDeselect (pnd, 0)); // 0 mean deselect all selected targets
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief C wrapper to InListPassiveTarget command
|
||||
|
|
|
@ -93,7 +93,6 @@
|
|||
# define DENACK 0x0100/* NACK */
|
||||
# define DEACKMISMATCH 0x0200/* Unexpected data */
|
||||
# define DEISERRFRAME 0x0300/* Error frame */
|
||||
# define DENOTSUP 0x0400/* Not supported */
|
||||
|
||||
typedef enum {
|
||||
PN531 = 0x01,
|
||||
|
@ -107,12 +106,17 @@ typedef enum {
|
|||
EXECUTE = 0x02, // Need to cancel the running command to process new one
|
||||
} pn53x_state;
|
||||
|
||||
struct pn53x_io {
|
||||
bool (*send)(nfc_device_t * pnd, const byte_t * pbtData, const size_t szData);
|
||||
int (*receive)(nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen);
|
||||
};
|
||||
|
||||
struct pn53x_data {
|
||||
pn53x_type type;
|
||||
pn53x_state state;
|
||||
const struct pn53x_io * io;
|
||||
};
|
||||
|
||||
|
||||
/* PN53x specific types */
|
||||
/**
|
||||
* @enum pn53x_modulation_t
|
||||
|
@ -197,8 +201,7 @@ typedef enum {
|
|||
|
||||
bool pn53x_init(nfc_device_t * pnd);
|
||||
bool pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t *pszRx);
|
||||
bool pn53x_read_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value);
|
||||
bool pn53x_write_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
|
||||
|
||||
bool pn53x_set_parameters (nfc_device_t * pnd, const uint8_t ui8Value, const bool bEnable);
|
||||
bool pn53x_set_tx_bits (nfc_device_t * pnd, const uint8_t ui8Bits);
|
||||
bool pn53x_wrap_frame (const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtFrame,
|
||||
|
@ -208,11 +211,14 @@ bool pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, b
|
|||
bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData,
|
||||
pn53x_type chip_type, nfc_modulation_type_t nmt,
|
||||
nfc_target_info_t * pnti);
|
||||
bool pn53x_read_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value);
|
||||
bool pn53x_write_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
|
||||
bool pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[18]);
|
||||
bool pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable);
|
||||
bool pn53x_check_communication (nfc_device_t *pnd);
|
||||
|
||||
// NFC device as Initiator functions
|
||||
bool pn53x_initiator_init (nfc_device_t * pnd);
|
||||
bool pn53x_initiator_select_passive_target (nfc_device_t * pnd,
|
||||
const nfc_modulation_t nm,
|
||||
const byte_t * pbtInitData, const size_t szInitData,
|
||||
|
@ -230,6 +236,8 @@ bool pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtT
|
|||
byte_t * pbtRxPar);
|
||||
bool pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx,
|
||||
byte_t * pbtRx, size_t * pszRx);
|
||||
bool pn53x_initiator_deselect_target (nfc_device_t * pnd);
|
||||
|
||||
// NFC device as Target functions
|
||||
bool pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx);
|
||||
bool pn53x_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar);
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "acr122.h"
|
||||
#include "../drivers.h"
|
||||
#include "libnfc/drivers.h"
|
||||
|
||||
// Bus
|
||||
#include <winscard.h>
|
||||
|
@ -54,7 +54,6 @@
|
|||
#endif
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
|
||||
#define SCARD_OPERATION_SUCCESS 0x61
|
||||
#define SCARD_OPERATION_ERROR 0x63
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
|
||||
#include "libnfc/drivers.h"
|
||||
#include "libnfc/nfc-internal.h"
|
||||
|
@ -174,6 +173,7 @@ arygon_connect (const nfc_device_desc_t * pndd)
|
|||
|
||||
// The PN53x chip connected to ARYGON MCU doesn't seems to be in SLEEP mode
|
||||
((struct pn53x_data*)(pnd->chip_data))->state = NORMAL;
|
||||
((struct pn53x_data*)(pnd->chip_data))->io = &arygon_tama_io;
|
||||
pnd->driver = &arygon_driver;
|
||||
|
||||
// Check communication using "Reset TAMA" command
|
||||
|
@ -449,14 +449,32 @@ arygon_ack (const nfc_device_spec_t nds)
|
|||
}
|
||||
*/
|
||||
|
||||
const struct pn53x_io arygon_tama_io = {
|
||||
.send = arygon_tama_send,
|
||||
.receive = arygon_tama_receive,
|
||||
};
|
||||
|
||||
const struct nfc_driver_t arygon_driver = {
|
||||
.name = ARYGON_DRIVER_NAME,
|
||||
.probe = arygon_probe,
|
||||
.connect = arygon_connect,
|
||||
.send = arygon_tama_send,
|
||||
.receive = arygon_tama_receive,
|
||||
.disconnect = arygon_disconnect,
|
||||
.strerror = pn53x_strerror,
|
||||
|
||||
.initiator_init = pn53x_initiator_init,
|
||||
.initiator_select_passive_target = pn53x_initiator_select_passive_target,
|
||||
.initiator_poll_targets = pn53x_initiator_poll_targets,
|
||||
.initiator_select_dep_target = pn53x_initiator_select_dep_target,
|
||||
.initiator_deselect_target = pn53x_initiator_deselect_target,
|
||||
.initiator_transceive_bytes = pn53x_initiator_transceive_bytes,
|
||||
.initiator_transceive_bits = pn53x_initiator_transceive_bits,
|
||||
|
||||
.target_init = pn53x_target_init,
|
||||
.target_send_bytes = pn53x_target_send_bytes,
|
||||
.target_receive_bytes = pn53x_target_receive_bytes,
|
||||
.target_send_bits = pn53x_target_send_bits,
|
||||
.target_receive_bits = pn53x_target_receive_bits,
|
||||
|
||||
.configure = pn53x_configure,
|
||||
};
|
||||
|
||||
|
|
|
@ -38,5 +38,6 @@ bool arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size
|
|||
int arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData);
|
||||
|
||||
extern const struct nfc_driver_t arygon_driver;
|
||||
extern const struct pn53x_io arygon_tama_io;
|
||||
|
||||
#endif // ! __NFC_DRIVER_ARYGON_H__
|
||||
|
|
|
@ -32,8 +32,7 @@ Thanks to d18c7db and Okko for example code
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../drivers.h"
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "libnfc/drivers.h"
|
||||
|
||||
nfc_device_desc_t *
|
||||
pn531_usb_pick_device (void)
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
|
||||
#include "libnfc/drivers.h"
|
||||
#include "libnfc/nfc-internal.h"
|
||||
|
|
|
@ -32,8 +32,7 @@ Thanks to d18c7db and Okko for example code
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../drivers.h"
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "libnfc/drivers.h"
|
||||
|
||||
nfc_device_desc_t *
|
||||
pn533_usb_pick_device (void)
|
||||
|
|
|
@ -36,11 +36,10 @@ Thanks to d18c7db and Okko for example code
|
|||
#include <usb.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../drivers.h"
|
||||
#include "../chips/pn53x.h"
|
||||
#include "libnfc/drivers.h"
|
||||
#include "libnfc/chips/pn53x.h"
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
|
||||
#define BUFFER_LENGTH 256
|
||||
#define USB_TIMEOUT 0
|
||||
|
|
|
@ -25,8 +25,16 @@
|
|||
#ifndef __NFC_INTERNAL_H__
|
||||
# define __NFC_INTERNAL_H__
|
||||
|
||||
# include <err.h>
|
||||
|
||||
// TODO: Put generic errors here
|
||||
# define DENOTSUP 0x0400/* Not supported */
|
||||
|
||||
/**
|
||||
* @macro PRINT_HEX
|
||||
* @brief Print a byte-array in hexadecimal format (only in DEBUG mode)
|
||||
*/
|
||||
# ifdef DEBUG
|
||||
//# if 1
|
||||
# define PRINT_HEX(pcTag, pbtData, szBytes) do { \
|
||||
size_t __szPos; \
|
||||
printf(" %s: ", pcTag); \
|
||||
|
@ -43,14 +51,75 @@
|
|||
} while (0);
|
||||
# endif
|
||||
|
||||
/**
|
||||
* @macro DBG
|
||||
* @brief Print a message of standard output only in DEBUG mode
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define DBG(...) do { \
|
||||
warnx ("DBG %s:%d", __FILE__, __LINE__); \
|
||||
warnx (" " __VA_ARGS__ ); \
|
||||
} while (0)
|
||||
#else
|
||||
# define DBG(...) {}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @macro WARN
|
||||
* @brief Print a warn message
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define WARN(...) do { \
|
||||
warnx ("WARNING %s:%d", __FILE__, __LINE__); \
|
||||
warnx (" " __VA_ARGS__ ); \
|
||||
} while (0)
|
||||
#else
|
||||
# define WARN(...) warnx ("WARNING: " __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @macro ERR
|
||||
* @brief Print a error message
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define ERR(...) do { \
|
||||
warnx ("ERROR %s:%d", __FILE__, __LINE__); \
|
||||
warnx (" " __VA_ARGS__ ); \
|
||||
} while (0)
|
||||
#else
|
||||
# define ERR(...) warnx ("ERROR: " __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
#define HAL( FUNCTION, ... ) pnd->iLastError = 0; \
|
||||
if (pnd->driver->FUNCTION) { \
|
||||
return pnd->driver->FUNCTION( __VA_ARGS__ ); \
|
||||
} else { \
|
||||
pnd->iLastError = DENOTSUP; \
|
||||
return false; \
|
||||
}
|
||||
|
||||
struct nfc_driver_t {
|
||||
const char *name;
|
||||
bool (*probe)(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound);
|
||||
nfc_device_t * (*connect)(const nfc_device_desc_t * pndd);
|
||||
bool (*send)(nfc_device_t * pnd, const byte_t * pbtData, const size_t szData);
|
||||
int (*receive)(nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen);
|
||||
void (*disconnect)(nfc_device_t * pnd);
|
||||
const char *(*strerror)(const nfc_device_t * pnd);
|
||||
|
||||
bool (*initiator_init) (nfc_device_t * pnd);
|
||||
bool (*initiator_select_passive_target) (nfc_device_t * pnd, const nfc_modulation_t nm, const byte_t * pbtInitData, const size_t szInitData, nfc_target_t * pnt);
|
||||
bool (*initiator_poll_targets) (nfc_device_t * pnd, const nfc_modulation_t * pnmModulations, const size_t szModulations, const byte_t btPollNr, const byte_t btPeriod, nfc_target_t * pntTargets, size_t * pszTargetFound);
|
||||
bool (*initiator_select_dep_target) (nfc_device_t * pnd, const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, const nfc_dep_info_t * pndiInitiator, nfc_target_t * pnt);
|
||||
bool (*initiator_deselect_target) (nfc_device_t * pnd);
|
||||
bool (*initiator_transceive_bytes) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx);
|
||||
bool (*initiator_transceive_bits) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar);
|
||||
|
||||
bool (*target_init) (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx);
|
||||
bool (*target_send_bytes) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx);
|
||||
bool (*target_receive_bytes) (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx);
|
||||
bool (*target_send_bits) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar);
|
||||
bool (*target_receive_bits) (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar);
|
||||
|
||||
bool (*configure) (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable);
|
||||
};
|
||||
|
||||
#endif // __NFC_INTERNAL_H__
|
||||
|
|
64
libnfc/nfc.c
64
libnfc/nfc.c
|
@ -40,14 +40,12 @@
|
|||
#include <nfc/nfc.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include "../contrib/windows.h"
|
||||
# include "contrib/windows.h"
|
||||
#endif
|
||||
|
||||
#include "chips.h"
|
||||
#include "drivers.h"
|
||||
#include "nfc-internal.h"
|
||||
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
nfc_device_desc_t *nfc_pick_device (void);
|
||||
|
@ -246,9 +244,7 @@ nfc_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * ps
|
|||
bool
|
||||
nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_configure (pnd, ndo, bEnable);
|
||||
HAL (configure, pnd, ndo, bEnable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,17 +259,7 @@ nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEn
|
|||
bool
|
||||
nfc_initiator_init (nfc_device_t * pnd)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
// Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards)
|
||||
if (!pn53x_write_register (pnd, REG_CIU_TX_AUTO, SYMBOL_FORCE_100_ASK, 0x40))
|
||||
return false;
|
||||
|
||||
// Configure the PN53X to be an Initiator or Reader/Writer
|
||||
if (!pn53x_write_register (pnd, REG_CIU_CONTROL, SYMBOL_INITIATOR, 0x10))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
HAL (initiator_init, pnd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,8 +291,6 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd,
|
|||
byte_t abtInit[MAX(12, szInitData)];
|
||||
size_t szInit;
|
||||
|
||||
pnd->iLastError = 0;
|
||||
|
||||
// TODO Put this in a function: this part is defined by ISO14443-3 (UID and Cascade levels)
|
||||
switch (nm.nmt) {
|
||||
case NMT_ISO14443A:
|
||||
|
@ -339,7 +323,7 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd,
|
|||
break;
|
||||
}
|
||||
|
||||
return pn53x_initiator_select_passive_target (pnd, nm, abtInit, szInit, pnt);
|
||||
HAL (initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -440,9 +424,7 @@ nfc_initiator_poll_targets (nfc_device_t * pnd,
|
|||
const byte_t btPollNr, const byte_t btPeriod,
|
||||
nfc_target_t * pntTargets, size_t * pszTargetFound)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_initiator_poll_targets (pnd, pnmModulations, szModulations, btPollNr, btPeriod, pntTargets, pszTargetFound);
|
||||
HAL (initiator_poll_targets, pnd, pnmModulations, szModulations, btPollNr, btPeriod, pntTargets, pszTargetFound);
|
||||
}
|
||||
|
||||
|
||||
|
@ -466,9 +448,7 @@ nfc_initiator_select_dep_target (nfc_device_t * pnd,
|
|||
const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr,
|
||||
const nfc_dep_info_t * pndiInitiator, nfc_target_t * pnt)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_initiator_select_dep_target (pnd, ndm, nbr, pndiInitiator, pnt);
|
||||
HAL (initiator_select_dep_target, pnd, ndm, nbr, pndiInitiator, pnt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -486,9 +466,7 @@ nfc_initiator_select_dep_target (nfc_device_t * pnd,
|
|||
bool
|
||||
nfc_initiator_deselect_target (nfc_device_t * pnd)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return (pn53x_InDeselect (pnd, 0)); // 0 mean deselect all selected targets
|
||||
HAL (initiator_deselect_target, pnd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -511,9 +489,7 @@ bool
|
|||
nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
|
||||
size_t * pszRx)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_initiator_transceive_bytes (pnd, pbtTx, szTx, pbtRx, pszRx);
|
||||
HAL (initiator_transceive_bytes, pnd, pbtTx, szTx, pbtRx, pszRx)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -555,9 +531,7 @@ bool
|
|||
nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar,
|
||||
byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_initiator_transceive_bits (pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, pbtRxPar);
|
||||
HAL (initiator_transceive_bits, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, pbtRxPar);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -585,9 +559,7 @@ nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const s
|
|||
bool
|
||||
nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_target_init (pnd, pnt, pbtRx, pszRx);
|
||||
HAL (target_init, pnd, pnt, pbtRx, pszRx);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -613,9 +585,7 @@ nfc_abort_command (nfc_device_t * pnd)
|
|||
bool
|
||||
nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_target_send_bytes (pnd, pbtTx, szTx);
|
||||
HAL (target_send_bytes, pnd, pbtTx, szTx);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -630,9 +600,7 @@ nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t sz
|
|||
bool
|
||||
nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_target_receive_bytes (pnd, pbtRx, pszRx);
|
||||
HAL (target_receive_bytes, pnd, pbtRx, pszRx);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -645,9 +613,7 @@ nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx)
|
|||
bool
|
||||
nfc_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_target_send_bits (pnd, pbtTx, szTxBits, pbtTxPar);
|
||||
HAL (target_send_bits, pnd, pbtTx, szTxBits, pbtTxPar);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -664,9 +630,7 @@ nfc_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szT
|
|||
bool
|
||||
nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_target_receive_bits (pnd, pbtRx, pszRxBits, pbtRxPar);
|
||||
HAL (target_receive_bits, pnd, pbtRx, pszRxBits, pbtRxPar);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue