Attempt to fix Issue 14 and Issue 16: allow DLL creation and add C++ compatibility. (WARNING: this fix couldnt be tested here.)
This commit is contained in:
parent
70ede60e30
commit
bd4a48990e
2 changed files with 32 additions and 18 deletions
|
@ -41,6 +41,20 @@ typedef void* dev_spec; // Device connection specification
|
|||
#define WARN(x, ...) printf("WARNING: " x "\n", ## __VA_ARGS__ )
|
||||
#define ERR(x, ...) printf("ERROR: " x "\n", ## __VA_ARGS__ )
|
||||
|
||||
#if defined __cplusplus
|
||||
#define LIBNFC_EXPORT extern "C"
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#ifdef nfc_EXPORTS
|
||||
#define LIBNFC_EXPORT __declspec( dllexport )
|
||||
#else
|
||||
#define LIBNFC_EXPORT __declspec( dllimport )
|
||||
#endif
|
||||
#else
|
||||
#define LIBNFC_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//#define MIN(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; }
|
||||
|
|
36
src/libnfc.h
36
src/libnfc.h
|
@ -44,7 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||
* When it has successfully claimed a NFC device, memory is allocated to save the device information. It will return a pointer to a dev_info struct.
|
||||
* This pointer should be supplied by every next function of libnfc that should perform an action with this device.
|
||||
*/
|
||||
dev_info* nfc_connect(void);
|
||||
LIBNFC_EXPORT dev_info* nfc_connect(void);
|
||||
|
||||
/**
|
||||
* @fn void nfc_disconnect(dev_info* pdi)
|
||||
|
@ -53,7 +53,7 @@ dev_info* nfc_connect(void);
|
|||
*
|
||||
* Initiator is disconnected and the device, including allocated dev_info struct, is released.
|
||||
*/
|
||||
void nfc_disconnect(dev_info* pdi);
|
||||
LIBNFC_EXPORT void nfc_disconnect(dev_info* pdi);
|
||||
|
||||
/**
|
||||
* @fn nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable)
|
||||
|
@ -67,7 +67,7 @@ void nfc_disconnect(dev_info* pdi);
|
|||
* There are different categories for configuring the PN53X chip features (handle, activate, infinite and accept).
|
||||
* These are defined to organize future settings that will become available when they are needed.
|
||||
*/
|
||||
bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable);
|
||||
LIBNFC_EXPORT bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable);
|
||||
|
||||
/**
|
||||
* @fn nfc_initiator_init(const dev_info* pdi)
|
||||
|
@ -77,7 +77,7 @@ bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnabl
|
|||
*
|
||||
* The NFC device is configured to function as RFID reader. After initialization it can be used to communicate to passive RFID tags and active NFC devices. The reader will act as initiator to communicate peer 2 peer (NFCIP) to other active NFC devices.
|
||||
*/
|
||||
bool nfc_initiator_init(const dev_info* pdi);
|
||||
LIBNFC_EXPORT bool nfc_initiator_init(const dev_info* pdi);
|
||||
|
||||
/**
|
||||
* @fn nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti)
|
||||
|
@ -89,7 +89,7 @@ bool nfc_initiator_init(const dev_info* pdi);
|
|||
* The NFC device will try to find the available passive tags. Some NFC devices are capable to emulate passive tags. The standards (ISO18092 and ECMA-340) describe the modulation that can be used for reader to passive communications. The chip needs to know with what kind of tag it is dealing with, therefore the initial modulation and speed (106, 212 or 424 kbps) should be supplied.
|
||||
* @note For every initial modulation type there is a different collection of information returned (in tag_info pointer pti) They all fit in the data-type which is called tag_info. This is a union which contains the tag information that belongs to the according initial modulation type.
|
||||
*/
|
||||
bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti);
|
||||
LIBNFC_EXPORT bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti);
|
||||
|
||||
/**
|
||||
* @fn nfc_initiator_select_dep_target(const dev_info *pdi, const init_modulation im, const byte_t *pbtPidData, const uint32_t uiPidDataLen, const byte_t *pbtNFCID3i, const uint32_t uiNFCID3iDataLen, const byte_t *pbtGbData, const uint32_t uiGbDataLen, tag_info * pti);
|
||||
|
@ -104,7 +104,7 @@ bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, con
|
|||
* The NFC device will try to find the available target. The standards (ISO18092 and ECMA-340) describe the modulation that can be used for reader to passive communications.
|
||||
* @note tag_info_dep will be returned when the target was acquired successfully.
|
||||
*/
|
||||
bool nfc_initiator_select_dep_target(const dev_info* pdi, const init_modulation im, const byte_t* pbtPidData, const uint32_t uiPidDataLen, const byte_t* pbtNFCID3i, const uint32_t uiNFCID3iDataLen, const byte_t *pbtGbData, const uint32_t uiGbDataLen, tag_info* pti);
|
||||
LIBNFC_EXPORT bool nfc_initiator_select_dep_target(const dev_info* pdi, const init_modulation im, const byte_t* pbtPidData, const uint32_t uiPidDataLen, const byte_t* pbtNFCID3i, const uint32_t uiNFCID3iDataLen, const byte_t *pbtGbData, const uint32_t uiGbDataLen, tag_info* pti);
|
||||
/**
|
||||
* @fn nfc_initiator_deselect_tag(const dev_info* pdi);
|
||||
* @brief Deselect a selected passive or emulated tag
|
||||
|
@ -113,7 +113,7 @@ bool nfc_initiator_select_dep_target(const dev_info* pdi, const init_modulation
|
|||
*
|
||||
* After selecting and communicating with a passive tag, this function could be used to deactivate and release the tag. This is very useful when there are multiple tags available in the field. It is possible to use the nfc_initiator_select_tag() function to select the first available tag, test it for the available features and support, deselect it and skip to the next tag until the correct tag is found.
|
||||
*/
|
||||
bool nfc_initiator_deselect_tag(const dev_info* pdi);
|
||||
LIBNFC_EXPORT bool nfc_initiator_deselect_tag(const dev_info* pdi);
|
||||
|
||||
/**
|
||||
* @fn nfc_initiator_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)
|
||||
|
@ -128,7 +128,7 @@ bool nfc_initiator_deselect_tag(const dev_info* pdi);
|
|||
*
|
||||
* The NFC reader will transmit low-level messages where only the modulation is handled by the PN53X chip. Construction of the frame (data, CRC and parity) is completely done by libnfc. This can be very useful for testing purposes. Some protocols (e.g. MIFARE Classic) require to violate the ISO14443-A standard by sending incorrect parity and CRC bytes. Using this feature you are able to simulate these frames.
|
||||
*/
|
||||
bool nfc_initiator_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);
|
||||
LIBNFC_EXPORT bool nfc_initiator_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);
|
||||
|
||||
/**
|
||||
* @fn nfc_initiator_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen)
|
||||
|
@ -138,7 +138,7 @@ bool nfc_initiator_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, con
|
|||
* The reader will transmit the supplied bytes in pbtTx to the target (tag). It waits for the response and stores the received bytes in the pbtRx byte array. The parity bits are handled by the PN53X chip. The CRC can be generated automatically or handled manually. Using this function, frames can be communicated very fast via the NFC reader to the tag. Tests show that on average this way of communicating is much faster than using the regular driver/middle-ware (often supplied by manufacturers).
|
||||
* @warning The configuration option DCO_HANDLE_PARITY must be set to true (the default value).
|
||||
*/
|
||||
bool nfc_initiator_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
|
||||
LIBNFC_EXPORT bool nfc_initiator_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
|
||||
|
||||
/**
|
||||
* @fn nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen)
|
||||
|
@ -147,7 +147,7 @@ bool nfc_initiator_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, co
|
|||
*
|
||||
* The reader will transmit the supplied (data) bytes in pbtTx to the target (tag). It waits for the response and stores the received bytes in the pbtRx byte array. The difference between this function and nfc_initiator_transceive_bytes is that here pbtTx and pbtRx contain *only* the data sent and received and not any additional commands, that is all handled internally by the PN53X.
|
||||
*/
|
||||
bool nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
|
||||
LIBNFC_EXPORT bool nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
|
||||
|
||||
/**
|
||||
* @fn nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp)
|
||||
|
@ -160,7 +160,7 @@ bool nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx
|
|||
*
|
||||
* First an authentication must take place using Key A or B. It requires a 48 bit Key (6 bytes) and the UID. They are both used to initialize the internal cipher-state of the PN53X chip (http://libnfc.org/hardware/pn53x-chip). After a successful authentication it will be possible to execute other commands (e.g. Read/Write). The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process.
|
||||
*/
|
||||
bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp);
|
||||
LIBNFC_EXPORT bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp);
|
||||
|
||||
/**
|
||||
* @fn nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits)
|
||||
|
@ -171,7 +171,7 @@ bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const ui
|
|||
*
|
||||
* @warning Be aware that this function will wait (hang) until a command is received that is not part of the anti-collision. The RATS command for example would wake up the emulator. After this is received, the send and receive functions can be used.
|
||||
*/
|
||||
bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits);
|
||||
LIBNFC_EXPORT bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits);
|
||||
|
||||
/**
|
||||
* @fn nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar)
|
||||
|
@ -180,7 +180,7 @@ bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits);
|
|||
*
|
||||
* This function makes it possible to receive (raw) bit-frames. It returns all the messages that are stored in the FIFO buffer of the PN53X chip. It does not require to send any frame and thereby could be used to snoop frames that are transmitted by a nearby reader. Check out the DCO_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted frames.
|
||||
*/
|
||||
bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar);
|
||||
LIBNFC_EXPORT bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar);
|
||||
|
||||
/**
|
||||
* @fn nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen)
|
||||
|
@ -189,7 +189,7 @@ bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRx
|
|||
*
|
||||
* The main receive function that returns the received frames from a nearby reader.
|
||||
*/
|
||||
bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen);
|
||||
LIBNFC_EXPORT bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen);
|
||||
|
||||
/**
|
||||
* @fn nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen)
|
||||
|
@ -198,7 +198,7 @@ bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiR
|
|||
*
|
||||
* The main receive function that returns the received data from a nearby reader. The difference between this function and nfc_target_receive_bytes is that here pbtRx contains *only* the data received and not any additional commands, that is all handled internally by the PN53X.
|
||||
*/
|
||||
bool nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen);
|
||||
LIBNFC_EXPORT bool nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen);
|
||||
|
||||
/**
|
||||
* @fn nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar)
|
||||
|
@ -207,7 +207,7 @@ bool nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t*
|
|||
*
|
||||
* This function can be used to transmit (raw) bit-frames to the reader.
|
||||
*/
|
||||
bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar);
|
||||
LIBNFC_EXPORT bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar);
|
||||
|
||||
/**
|
||||
* @fn nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen)
|
||||
|
@ -216,7 +216,7 @@ bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32
|
|||
*
|
||||
* To communicate byte frames and APDU responses to the reader, this function could be used.
|
||||
*/
|
||||
bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen);
|
||||
LIBNFC_EXPORT bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen);
|
||||
|
||||
/**
|
||||
* @fn nfc_target_send_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen)
|
||||
|
@ -225,7 +225,7 @@ bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint3
|
|||
*
|
||||
* To communicate data to the reader, this function could be used. The difference between this function and nfc_target_send_bytes is that here pbtTx contains *only* the data sent and not any additional commands, that is all handled internally by the PN53X.
|
||||
*/
|
||||
bool nfc_target_send_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen);
|
||||
LIBNFC_EXPORT bool nfc_target_send_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen);
|
||||
|
||||
#endif // _LIBNFC_H_
|
||||
|
||||
|
|
Loading…
Reference in a new issue