From 6f1e6c0a69b6fdc3e68a043f7c6f3253583a278a Mon Sep 17 00:00:00 2001 From: developer4 Date: Wed, 31 May 2017 14:16:26 +0200 Subject: [PATCH] initial revision --- .cproject | 273 ++++++++++++++++++ .gitmodules | 3 + .project | 26 ++ .settings/org.eclipse.cdt.core.prefs | 21 ++ .../org.eclipse.cdt.managedbuilder.core.prefs | 51 ++++ lib | 1 + src/ini.h | 20 ++ src/main.c | 80 +++++ src/uFR.c | 112 +++++++ src/uFR.h | 16 + src/utils.c | 42 +++ src/utils.h | 15 + 12 files changed, 660 insertions(+) create mode 100644 .cproject create mode 100644 .gitmodules create mode 100644 .project create mode 100644 .settings/org.eclipse.cdt.core.prefs create mode 100644 .settings/org.eclipse.cdt.managedbuilder.core.prefs create mode 160000 lib create mode 100644 src/ini.h create mode 100644 src/main.c create mode 100644 src/uFR.c create mode 100644 src/uFR.h create mode 100644 src/utils.c create mode 100644 src/utils.h diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..8f03723 --- /dev/null +++ b/.cproject @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b270676 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib"] + path = lib + url = https://git.d-logic.net/nfc-rfid-reader-sdk/ufr-lib.git diff --git a/.project b/.project new file mode 100644 index 0000000..2d61a26 --- /dev/null +++ b/.project @@ -0,0 +1,26 @@ + + + ufr-apdu-example + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs new file mode 100644 index 0000000..4aa4836 --- /dev/null +++ b/.settings/org.eclipse.cdt.core.prefs @@ -0,0 +1,21 @@ +eclipse.preferences.version=1 +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/MINGW_HOME/delimiter=; +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/MINGW_HOME/operation=replace +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/MINGW_HOME/value=C\:\\mingw-w64\\i686-5.1.0-posix-dwarf-rt_v4-rev0\\mingw32 +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/append=true +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/appendContributed=true +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/MINGW_HOME/delimiter=; +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/MINGW_HOME/operation=replace +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/MINGW_HOME/value=C\:\\mingw-w64\\x86_64-5.1.0-posix-seh-rt_v4-rev0\\mingw64 +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/append=true +environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/appendContributed=true +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/MINGW_HOME/delimiter=; +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/MINGW_HOME/operation=replace +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/MINGW_HOME/value=C\:\\mingw-w64\\i686-5.1.0-posix-dwarf-rt_v4-rev0\\mingw32 +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/append=true +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/appendContributed=true +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/MINGW_HOME/delimiter=; +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/MINGW_HOME/operation=replace +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/MINGW_HOME/value=C\:\\mingw-w64\\x86_64-5.1.0-posix-seh-rt_v4-rev0\\mingw64 +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/append=true +environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/appendContributed=true diff --git a/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/.settings/org.eclipse.cdt.managedbuilder.core.prefs new file mode 100644 index 0000000..73e1322 --- /dev/null +++ b/.settings/org.eclipse.cdt.managedbuilder.core.prefs @@ -0,0 +1,51 @@ +eclipse.preferences.version=1 +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/appendContributed=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/appendContributed=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/appendContributed=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/appendContributed=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/appendContributed=true diff --git a/lib b/lib new file mode 160000 index 0000000..630442f --- /dev/null +++ b/lib @@ -0,0 +1 @@ +Subproject commit 630442fb0387cf61cced19e24ed3ba9506160870 diff --git a/src/ini.h b/src/ini.h new file mode 100644 index 0000000..3c44270 --- /dev/null +++ b/src/ini.h @@ -0,0 +1,20 @@ +/* + * ini.h + */ + +#ifndef INI_H_ +#define INI_H_ + +#define APP_VERSION "1.0" + +#define EXIT_ON_WRONG_FW_DEPENDENCY +#define MIN_DEPEND_FW_VER_MAJOR 3 +#define MIN_DEPEND_FW_VER_MINOR 9 +#define MIN_DEPEND_FW_VER_BUILD 36 + +#define EXIT_ON_WRONG_LIB_DEPENDENCY +#define MIN_DEPEND_LIB_VER_MAJOR 4 +#define MIN_DEPEND_LIB_VER_MINOR 0 +#define MIN_DEPEND_LIB_VER_BUILD 25 + +#endif /* INI_H_ */ diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..4e30149 --- /dev/null +++ b/src/main.c @@ -0,0 +1,80 @@ +/* + ============================================================================ + Project Name: project_name + Name : file_name.c + Author : d-logic + Version : + Copyright : 2017. + Description : Hello World in C, Ansi-style + Dependencies: uFR firmware - min. version x.y.z + uFRCoder library - min. version x.y.z + ============================================================================ + */ + +/* includes: + * stdio.h & stdlib.h are included by default (for printf and LARGE_INTEGER.QuadPart (long long) use %lld or %016llx). + * inttypes.h, stdbool.h & string.h included for various type support and utilities. + * conio.h is included for windows(dos) console input functions. + * windows.h is needed for various timer functions (GetTickCount(), QueryPerformanceFrequency(), QueryPerformanceCounter()) + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "ini.h" +#include "uFR.h" +//------------------------------------------------------------------------------ + +void usage(void); +//------------------------------------------------------------------------------ +int main(void) { + bool card_in_field = false; + UFR_STATUS status; + + usage(); + printf( "__________________________________________________\n"); + printf( " Please wait while opening uFR NFC reader.\n"); + printf( "__________________________________________________\n"); + + status = ReaderOpen(); + if (status != UFR_OK) { + printf("Error while opening device, status is: 0x%08X\n", status); + getchar(); + return EXIT_FAILURE; + } + if (!CheckDependencies()) { + ReaderClose(); + getchar(); + return EXIT_FAILURE; + } + status = ReaderReset(); + if (status != UFR_OK) { + printf("Error while opening device, status is: 0x%08X\n", status); + getchar(); + return EXIT_FAILURE; + } + + printf( "__________________________________________________\n"); + printf( " uFR NFC reader successfully opened.\n"); + printf( "__________________________________________________\n"); + + + + return EXIT_SUCCESS; +} +//------------------------------------------------------------------------------ +void usage(void) +{ + printf( " ________________________________________________\n" + "| APDU usage with uFR example |\n" + "| version "APP_VERSION" |\n" + "|________________________________________________|\n"); + printf( "When You put ISO14443-4 tag in the reader field,\n" + "You will be prompted for appropriate APDU to send.\n"); + printf( "__________________________________________________\n"); +} +//------------------------------------------------------------------------------ diff --git a/src/uFR.c b/src/uFR.c new file mode 100644 index 0000000..5326c86 --- /dev/null +++ b/src/uFR.c @@ -0,0 +1,112 @@ +/* + * uFR.c + */ + +#include +#include +#include +#include +#include +#include "ini.h" +#include "uFR.h" + +//------------------------------------------------------------------------------ +bool CheckDependencies(void) { +#if defined(EXIT_ON_WRONG_FW_DEPENDENCY) || defined(EXIT_ON_WRONG_LIB_DEPENDENCY) + uint8_t version_major, version_minor, build; + bool wrong_version = false; +#endif + UFR_STATUS status; + +#ifdef EXIT_ON_WRONG_LIB_DEPENDENCY +#endif +#ifdef EXIT_ON_WRONG_FW_DEPENDENCY + wrong_version = false; + status = GetReaderFirmwareVersion(&version_major, &version_minor); + if (status != UFR_OK) { + ReaderClose(); + printf("Error while checking firmware version, status is: 0x%08X\n", status); + getchar(); + return EXIT_FAILURE; + } + status = GetBuildNumber(&build); + if (status != UFR_OK) { + ReaderClose(); + printf("Error while firmware version, status is: 0x%08X\n", status); + getchar(); + return EXIT_FAILURE; + } + if (version_major < MIN_DEPEND_FW_VER_MAJOR) { + wrong_version = true; + } else if (version_major == MIN_DEPEND_FW_VER_MAJOR && version_minor < MIN_DEPEND_FW_VER_MINOR) { + wrong_version = true; + } else if (version_minor == MIN_DEPEND_FW_VER_MINOR && build < MIN_DEPEND_FW_VER_BUILD) { + wrong_version = true; + } + + if (wrong_version) { + printf("Wrong uFR NFC reader firmware version (%d.%d.%d).\n" + "Please update uFR firmware to at last %d.%d.%d version.\n", + version_major, version_minor, build, + MIN_DEPEND_FW_VER_MAJOR, MIN_DEPEND_FW_VER_MINOR, MIN_DEPEND_FW_VER_BUILD); + return false; + } +#endif + return true; +} +//------------------------------------------------------------------------------ +sz_ptr GetDlTypeName(uint8_t dl_type_code) { + + switch (dl_type_code) { + case DL_MIFARE_ULTRALIGHT: + return "DL_MIFARE_ULTRALIGHT"; + case DL_MIFARE_ULTRALIGHT_EV1_11: + return "DL_MIFARE_ULTRALIGHT_EV1_11"; + case DL_MIFARE_ULTRALIGHT_EV1_21: + return "DL_MIFARE_ULTRALIGHT_EV1_21"; + case DL_MIFARE_ULTRALIGHT_C: + return "DL_MIFARE_ULTRALIGHT_C"; + case DL_NTAG_203: + return "DL_NTAG_203"; + case DL_NTAG_210: + return "DL_NTAG_210"; + case DL_NTAG_212: + return "DL_NTAG_212"; + case DL_NTAG_213: + return "DL_NTAG_213"; + case DL_NTAG_215: + return "DL_NTAG_215"; + case DL_NTAG_216: + return "DL_NTAG_216"; + case DL_MIKRON_MIK640D: + return "DL_MIKRON_MIK640D"; + case DL_MIFARE_MINI: + return "DL_MIFARE_MINI"; + case DL_MIFARE_CLASSIC_1K: + return "DL_MIFARE_CLASSIC_1K"; + case DL_MIFARE_CLASSIC_4K: + return "DL_MIFARE_CLASSIC_4K"; + case DL_MIFARE_PLUS_S_2K: + return "DL_MIFARE_PLUS_S_2K"; + case DL_MIFARE_PLUS_S_4K: + return "DL_MIFARE_PLUS_S_4K"; + case DL_MIFARE_PLUS_X_2K: + return "DL_MIFARE_PLUS_X_2K"; + case DL_MIFARE_PLUS_X_4K: + return "DL_MIFARE_PLUS_X_4K"; + case DL_MIFARE_DESFIRE: + return "DL_MIFARE_DESFIRE"; + case DL_MIFARE_DESFIRE_EV1_2K: + return "DL_MIFARE_DESFIRE_EV1_2K"; + case DL_MIFARE_DESFIRE_EV1_4K: + return "DL_MIFARE_DESFIRE_EV1_4K"; + case DL_MIFARE_DESFIRE_EV1_8K: + return "DL_MIFARE_DESFIRE_EV1_8K"; + case DL_UNKNOWN_ISO_14443_4: + return "DL_GENERIC_ISO_14443_4"; + case DL_IMEI_UID: + return "DL_IMEI_UID"; + } + return "UNSUPPORTED CARD"; +} +//------------------------------------------------------------------------------ diff --git a/src/uFR.h b/src/uFR.h new file mode 100644 index 0000000..ddd49a3 --- /dev/null +++ b/src/uFR.h @@ -0,0 +1,16 @@ +/* + * uFR.h + */ + +#ifndef UFR_H_ +#define UFR_H_ + +#include "ini.h" +//------------------------------------------------------------------------------ +typedef const char * sz_ptr; +//------------------------------------------------------------------------------ +bool CheckDependencies(void); +sz_ptr GetDlTypeName(uint8_t dl_type_code); +//------------------------------------------------------------------------------ + +#endif /* UFR_H_ */ diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..795757b --- /dev/null +++ b/src/utils.c @@ -0,0 +1,42 @@ +/* + * utils.c + */ + +#include +#include +#include +#include "ini.h" +#include "utils.h" + +//------------------------------------------------------------------------------ +void print_ln_len(char symbol, uint8_t cnt) { + + for (int i = 0; i < cnt; i++) + printf("%c", symbol); + + printf("\n"); +} +//------------------------------------------------------------------------------ +inline void print_ln(char symbol) { + + print_ln_len(symbol, DEFAULT_LINE_LEN); +} +//------------------------------------------------------------------------------ +void print_hex(const uint8_t *data, uint32_t len, const char *delimiter) { + + for (int i = 0; i < len; i++) { + printf("%02X", data[i]); + if ((delimiter != NULL) && (i < (len - 1))) + printf("%c", *delimiter); + } +} +//------------------------------------------------------------------------------ +void print_hex_ln(const uint8_t *data, uint32_t len, const char *delimiter) { + + print_hex(data, len, delimiter); + printf("\n"); +} +//============================================================================== + + + diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..f35685f --- /dev/null +++ b/src/utils.h @@ -0,0 +1,15 @@ +/* + * utils.h + */ + +#ifndef UTILS_H_ +#define UTILS_H_ + +#define DEFAULT_LINE_LEN 60 + +void print_ln_len(char symbol, uint8_t cnt); +void print_ln(char symbol); +void print_hex(const uint8_t *data, uint32_t len, const char *delimiter); +void print_hex_ln(const uint8_t *data, uint32_t len, const char *delimiter); + +#endif /* UTILS_H_ */ -- GitLab