Added windows (GNU) Makefile, removed ugly dll-directives, fixed rs232 under windows

This commit is contained in:
Roel Verdult 2009-09-29 15:19:15 +00:00
parent ad36a4d1a5
commit 5aab7f9da0
6 changed files with 67 additions and 31 deletions

View file

@ -33,14 +33,14 @@ uint32_t mirror32(uint32_t ui32Bits);
uint64_t mirror64(uint64_t ui64Bits);
void mirror_byte_ts(byte_t *pbts, uint32_t uiLen);
LIBNFC_EXPORT uint32_t swap_endian32(const void* pui32);
LIBNFC_EXPORT uint64_t swap_endian64(const void* pui64);
uint32_t swap_endian32(const void* pui32);
uint64_t swap_endian64(const void* pui64);
LIBNFC_EXPORT void append_iso14443a_crc(byte_t* pbtData, uint32_t uiLen);
void append_iso14443a_crc(byte_t* pbtData, uint32_t uiLen);
LIBNFC_EXPORT void print_hex(const byte_t* pbtData, const uint32_t uiLen);
LIBNFC_EXPORT void print_hex_bits(const byte_t* pbtData, const uint32_t uiBits);
LIBNFC_EXPORT void print_hex_par(const byte_t* pbtData, const uint32_t uiBits, const byte_t* pbtDataPar);
void print_hex(const byte_t* pbtData, const uint32_t uiLen);
void print_hex_bits(const byte_t* pbtData, const uint32_t uiBits);
void print_hex_par(const byte_t* pbtData, const uint32_t uiBits, const byte_t* pbtDataPar);
#endif // _LIBNFC_BITUTILS_H_

View file

@ -769,12 +769,11 @@ bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits)
byte_t abtRx[MAX_FRAME_LEN];
uint32_t uiRxLen;
uint8_t ui8Bits;
byte_t abtCmd[sizeof(pncmd_target_init)];
memcpy(abtCmd,pncmd_target_init,sizeof(pncmd_target_init));
// Save the current configuration settings
bool bCrc = pdi->bCrc;
bool bPar = pdi->bPar;
byte_t abtCmd[sizeof(pncmd_target_init)];
memcpy(abtCmd,pncmd_target_init,sizeof(pncmd_target_init));
// Clear the target init struct, reset to all zeros
memset(abtCmd+2,0x00,37);

View file

@ -48,7 +48,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.
*/
LIBNFC_EXPORT dev_info* nfc_connect(nfc_device_desc_t* device_desc);
dev_info* nfc_connect(nfc_device_desc_t* device_desc);
/**
* @fn void nfc_disconnect(dev_info* pdi)
@ -57,7 +57,7 @@ LIBNFC_EXPORT dev_info* nfc_connect(nfc_device_desc_t* device_desc);
*
* Initiator is disconnected and the device, including allocated dev_info struct, is released.
*/
LIBNFC_EXPORT void nfc_disconnect(dev_info* pdi);
void nfc_disconnect(dev_info* pdi);
/**
* @fn nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable)
@ -71,7 +71,7 @@ LIBNFC_EXPORT 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.
*/
LIBNFC_EXPORT 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);
/**
* @fn nfc_initiator_init(const dev_info* pdi)
@ -81,7 +81,7 @@ LIBNFC_EXPORT bool nfc_configure(dev_info* pdi, const dev_config_option dco, con
*
* 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.
*/
LIBNFC_EXPORT bool nfc_initiator_init(const dev_info* pdi);
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)
@ -95,7 +95,7 @@ LIBNFC_EXPORT 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.
*/
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);
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);
@ -110,7 +110,7 @@ LIBNFC_EXPORT bool nfc_initiator_select_tag(const dev_info* pdi, const init_modu
* 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.
*/
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);
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
@ -119,7 +119,7 @@ LIBNFC_EXPORT bool nfc_initiator_select_dep_target(const dev_info* pdi, const in
*
* 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.
*/
LIBNFC_EXPORT bool nfc_initiator_deselect_tag(const dev_info* pdi);
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)
@ -134,7 +134,7 @@ LIBNFC_EXPORT 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.
*/
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);
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)
@ -144,7 +144,7 @@ LIBNFC_EXPORT bool nfc_initiator_transceive_bits(const dev_info* pdi, const byte
* 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).
*/
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);
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)
@ -153,7 +153,7 @@ LIBNFC_EXPORT bool nfc_initiator_transceive_bytes(const dev_info* pdi, const byt
*
* 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.
*/
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);
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)
@ -166,7 +166,7 @@ LIBNFC_EXPORT bool nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const
*
* 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.
*/
LIBNFC_EXPORT bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp);
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)
@ -177,7 +177,7 @@ LIBNFC_EXPORT bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cm
*
* @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.
*/
LIBNFC_EXPORT bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits);
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)
@ -186,7 +186,7 @@ LIBNFC_EXPORT bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t*
*
* 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.
*/
LIBNFC_EXPORT bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar);
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)
@ -195,7 +195,7 @@ LIBNFC_EXPORT bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, u
*
* The main receive function that returns the received frames from a nearby reader.
*/
LIBNFC_EXPORT bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen);
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)
@ -204,7 +204,7 @@ LIBNFC_EXPORT bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx,
*
* 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.
*/
LIBNFC_EXPORT bool nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen);
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)
@ -213,7 +213,7 @@ LIBNFC_EXPORT bool nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbt
*
* This function can be used to transmit (raw) bit-frames to the reader.
*/
LIBNFC_EXPORT 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_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)
@ -222,7 +222,7 @@ LIBNFC_EXPORT bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx
*
* To communicate byte frames and APDU responses to the reader, this function could be used.
*/
LIBNFC_EXPORT bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen);
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)
@ -231,7 +231,7 @@ LIBNFC_EXPORT bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtT
*
* 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.
*/
LIBNFC_EXPORT bool nfc_target_send_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen);
bool nfc_target_send_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen);
#endif // _LIBNFC_H_

View file

@ -94,7 +94,7 @@ serial_port rs232_open(const char* pcPortName)
return sp;
}
void rs232_set_speed(const serial_port sp, const uint32_t uiPortSpeed)
void rs232_set_speed(serial_port sp, const uint32_t uiPortSpeed)
{
DBG("Serial port speed requested to be set to %d bauds.", uiPortSpeed);
// Set port speed (Input and Output)
@ -281,8 +281,10 @@ void rs232_close(const serial_port sp)
free(sp);
}
void rs232_set_speed(const serial_port sp, const uint32_t uiPortSpeed)
void rs232_set_speed(serial_port sp, const uint32_t uiPortSpeed)
{
serial_port_windows* spw;
DBG("Serial port speed requested to be set to %d bauds.", uiPortSpeed);
// Set port speed (Input and Output)
switch(uiPortSpeed) {
@ -298,7 +300,7 @@ void rs232_set_speed(const serial_port sp, const uint32_t uiPortSpeed)
ERR("Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed);
};
serial_port_windows* spw = (serial_port_windows*)sp;
spw = (serial_port_windows*)sp;
spw->dcb.BaudRate = uiPortSpeed;
if (!SetCommState(spw->hPort, &spw->dcb))
{

View file

@ -49,7 +49,7 @@ typedef void* serial_port;
serial_port rs232_open(const char* pcPortName);
void rs232_close(const serial_port sp);
void rs232_set_speed(const serial_port sp, uint32_t uiPortSpeed);
void rs232_set_speed(serial_port sp, const uint32_t uiPortSpeed);
uint32_t rs232_get_speed(const serial_port sp);
bool rs232_cts(const serial_port sp);

35
win32/Makefile Normal file
View file

@ -0,0 +1,35 @@
###############################################
# General settings
###############################################
VPATH=../src
###############################################
# Compiler settings
###############################################
CC = cl
LD = link
CFLAGS = -O2 -GL -I "$(INCLUDE)" -I "libusb" -I "stdint" -D "WIN32" -D "LIBNFC_EXPORTS" -MT -D "_CRT_SECURE_NO_WARNINGS" -D "HAVE_PCSC_LITE" -D "_WINDLL" -EHsc -W3 -nologo -c -Wp64 -TC -wd4996 -errorReport:prompt
LDFLAGS = -INCREMENTAL:NO -NOLOGO -LIBPATH:"libusb" -MANIFEST:NO -OPT:REF -OPT:ICF -LTCG -MACHINE:X86 -ERRORREPORT:PROMPT winscard.lib libusb.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
###############################################
# Files
###############################################
OBJS = dev_pn531.obj dev_pn533.obj dev_acr122.obj dev_arygon.obj bitutils.obj rs232.obj libnfc.obj
HEADERS = dev_acr122.h bitutils.h defines.h libnfc.h
LIBNFC = libnfc
EXES = anticol list emulate relay mftool
all: $(LIBNFC) $(EXES)
%.obj : %.c
$(CC) $(CFLAGS) $<
libnfc: $(OBJS)
$(LD) -OUT:$(LIBNFC).dll -DLL -DEF:"libnfc.def" -SUBSYSTEM:WINDOWS $(LDFLAGS) $(OBJS)
% : %.c $(LIBNFC)
$(CC) $(CFLAGS) $<
$(LD) /OUT:$@.exe -SUBSYSTEM:CONSOLE $(LDFLAGS) $(OBJS) $@
clean:
rm -f $(OBJS) $(LIBNFC) $(EXES)