Commit cb4f8450 by developer4

Alpha 0.1

Fixed PDOL parsing (for VISA Electron mostly)
parent e9bfd6a0
......@@ -28,7 +28,7 @@
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.444937224" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.mingw.exe.release.option.optimization.level.1687877395" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.release.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.c.compiler.mingw.exe.release.option.debugging.level.679385986" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<option id="gnu.c.compiler.option.dialect.std.2021408261" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c99" valueType="enumerated"/>
<option id="gnu.c.compiler.option.dialect.std.2021408261" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c11" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.1275126018" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../lib/include"/>
</option>
......@@ -84,7 +84,7 @@
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.118780202" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.mingw.exe.release.option.optimization.level.466879857" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.release.option.optimization.level" useByScannerDiscovery="false" value="gnu.c.optimization.level.none" valueType="enumerated"/>
<option id="gnu.c.compiler.mingw.exe.release.option.debugging.level.273265142" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.dialect.std.1335606875" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c99" valueType="enumerated"/>
<option id="gnu.c.compiler.option.dialect.std.1335606875" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c11" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.1506215541" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../lib/include"/>
</option>
......@@ -140,7 +140,7 @@
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.532804097" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.mingw.exe.release.option.optimization.level.575758007" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.release.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.c.compiler.mingw.exe.release.option.debugging.level.894887774" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<option id="gnu.c.compiler.option.dialect.std.1237723522" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c99" valueType="enumerated"/>
<option id="gnu.c.compiler.option.dialect.std.1237723522" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c11" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.1834072772" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../lib/include"/>
</option>
......@@ -153,7 +153,7 @@
<option id="gnu.c.link.option.libs.605495954" name="Libraries (-l)" superClass="gnu.c.link.option.libs" useByScannerDiscovery="false" valueType="libs">
<listOptionValue builtIn="false" value="uFCoder-x86"/>
</option>
<option id="gnu.c.link.option.ldflags.1921043637" superClass="gnu.c.link.option.ldflags" useByScannerDiscovery="false" value="-Wl,--enable-stdcall-fixup" valueType="string"/>
<option id="gnu.c.link.option.ldflags.1921043637" name="Linker flags" superClass="gnu.c.link.option.ldflags" useByScannerDiscovery="false" value="-Wl,--enable-stdcall-fixup" valueType="string"/>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1663107779" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
......@@ -197,7 +197,7 @@
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.1323467212" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.mingw.exe.release.option.optimization.level.1454390618" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.release.option.optimization.level" useByScannerDiscovery="false" value="gnu.c.optimization.level.none" valueType="enumerated"/>
<option id="gnu.c.compiler.mingw.exe.release.option.debugging.level.1840588658" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.dialect.std.1021040030" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c99" valueType="enumerated"/>
<option id="gnu.c.compiler.option.dialect.std.1021040030" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c11" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.1431165046" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../lib/include"/>
</option>
......@@ -210,7 +210,7 @@
<option id="gnu.c.link.option.libs.1566610575" name="Libraries (-l)" superClass="gnu.c.link.option.libs" useByScannerDiscovery="false" valueType="libs">
<listOptionValue builtIn="false" value="uFCoder-x86"/>
</option>
<option id="gnu.c.link.option.ldflags.1058073069" superClass="gnu.c.link.option.ldflags" useByScannerDiscovery="false" value="-Wl,--enable-stdcall-fixup" valueType="string"/>
<option id="gnu.c.link.option.ldflags.1058073069" name="Linker flags" superClass="gnu.c.link.option.ldflags" useByScannerDiscovery="false" value="-Wl,--enable-stdcall-fixup" valueType="string"/>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1107297146" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
......@@ -242,5 +242,18 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="win64_debug">
<resource resourceType="PROJECT" workspacePath="/ufr-apdu-credit_card_reader"/>
</configuration>
<configuration configurationName="win32_debug">
<resource resourceType="PROJECT" workspacePath="/ufr-apdu-credit_card_reader"/>
</configuration>
<configuration configurationName="win32_release">
<resource resourceType="PROJECT" workspacePath="/ufr-apdu-credit_card_reader"/>
</configuration>
<configuration configurationName="win64_release">
<resource resourceType="PROJECT" workspacePath="/ufr-apdu-credit_card_reader"/>
</configuration>
</storageModule>
</cproject>
......@@ -4,3 +4,7 @@ language.settings.xml
/win32_release/src/
/win64_debug/src/
/win64_release/src/
/win64_release/
/win32_debug/
/win32_release/
/win64_debug/
This diff is collapsed. Click to expand it.
/*
* emv.h
*
* Created on: 25.07.2017.
* Author: d-logic
*/
#ifndef EMV_H_
#define EMV_H_
//------------------------------------------------------------------------------
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
//------------------------------------------------------------------------------
#define MAX_TAG_LEN_BYTES 3
#define TAB_STEP 3
//==============================================================================
typedef enum E_TAG_TYPE {
STR = 10,
LANGUAGE_CODE_PAIRS,
BCD_4BY4,
DEC_UINT8,
DEC_UINT16,
DEC_UINT32,
ISO3166_COUNTRY,
ISO4217_CURRENCY,
DATE_YMD,
BIN_OR_STR,
BIN,
//-------------------
TL_LIST,
NODE,
//-------------------
} tag_type_t;
//------------------------------------------------------------------------------
typedef enum E_EMV_STATUS {
EMV_OK,
SYS_ERR_OUT_OF_MEMORY,
EMV_ERR_WRONG_INPUT_DATA,
EMV_ERR_MAX_TAG_LEN_BYTES_EXCEEDED,
EMV_ERR_TAG_NOT_FOUND,
EMV_ERR_TAG_WRONG_SIZE,
EMV_ERR_IN_CARD_READER,
EMV_ERR_READING_RECORD
} EMV_STATUS;
//==============================================================================
typedef uint32_t emv_tag_t;
typedef uint8_t emv_tag_index_t;
//------------------------------------------------------------------------------
typedef struct emv_tags_s {
emv_tag_t tag;
char *description;
tag_type_t tag_type;
uint8_t tag_id_len;
} emv_tags_t;
//------------------------------------------------------------------------------
typedef struct emv_tree_node_s emv_tree_node_t;
struct emv_tree_node_s {
emv_tag_t tag;
uint8_t tag_bytes;
char *description;
tag_type_t tag_type;
bool is_node_type;
uint8_t *value;
uint32_t value_len;
emv_tree_node_t *tl_list_format;
emv_tree_node_t *next;
emv_tree_node_t *subnode;
};
EMV_STATUS getSfi(emv_tree_node_t *tag_node, uint8_t *sfi);
EMV_STATUS getAID(emv_tree_node_t *tag_node, uint8_t *aid, uint8_t *aid_len);
void printEmvBranch(emv_tree_node_t *tag_node, int tabulator);
EMV_STATUS newEmvTag(emv_tree_node_t **head, uint8_t *input, int32_t input_bytes_left, bool is_list_format);
void emvTreeCleanup(emv_tree_node_t *head);
// emvReadRecord()
// uint8_t *r_apdu - minimum of the 256 bytes have to be allocated before call
EMV_STATUS emvReadRecord(uint8_t *r_apdu, uint32_t *Ne, uint8_t sfi, uint8_t record, uint8_t sw[2]);
//==============================================================================
#endif /* EMV_H_ */
......@@ -10,11 +10,11 @@
#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 39
#define MIN_DEPEND_FW_VER_BUILD 41
#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 26
#define MIN_DEPEND_LIB_VER_BUILD 27
#endif /* INI_H_ */
This diff is collapsed. Click to expand it.
/*
* iso3166.h
*
* Created on: 10.08.2017.
* Author: Zborac
*/
#ifndef ISO3166_H_
#define ISO3166_H_
#include <inttypes.h>
//==============================================================================
typedef struct iso3166_country_code_s {
uint16_t num_code;
char *alpha2_code;
char *alpha3_code;
char *country;
} iso3166_country_code_t;
//------------------------------------------------------------------------------
extern iso3166_country_code_t iso3166_country_codes[];
//------------------------------------------------------------------------------
int findCountryIndexByNumCode(uint16_t num_code);
//==============================================================================
#endif /* ISO3166_H_ */
/*
* iso4217_currency_codes.c
*
* Created on: 09.08.2017.
* Author: d-logic
*/
#include "iso4217.h"
iso4217_currency_code_t iso4217_currency_codes[] = {
{ 8, "ALL", "Albania Lek" },
{ 12, "DZD", "Algeria Dinar" },
{ 32, "ARS", "Argentina Peso" },
{ 36, "AUD", "Australia Dollar" },
{ 44, "BSD", "Bahamas Dollar" },
{ 48, "BHD", "Bahrain Dinar" },
{ 50, "BDT", "Bangladesh Taka" },
{ 51, "AMD", "Armenia Dram" },
{ 52, "BBD", "Barbados Dollar" },
{ 60, "BMD", "Bermuda Dollar" },
{ 64, "BTN", "Bhutan Ngultrum" },
{ 68, "BOB", "Bolivia Bolíviano" },
{ 72, "BWP", "Botswana Pula" },
{ 84, "BZD", "Belize Dollar" },
{ 90, "SBD", "Solomon Islands Dollar" },
{ 96, "BND", "Brunei Darussalam Dollar" },
{ 104, "MMK", "Myanmar (Burma) Kyat" },
{ 108, "BIF", "Burundi Franc" },
{ 116, "KHR", "Cambodia Riel" },
{ 124, "CAD", "Canada Dollar" },
{ 132, "CVE", "Cape Verde Escudo" },
{ 136, "KYD", "Cayman Islands Dollar" },
{ 144, "LKR", "Sri Lanka Rupee" },
{ 152, "CLP", "Chile Peso" },
{ 156, "CNY", "China Yuan Renminbi" },
{ 170, "COP", "Colombia Peso" },
{ 174, "KMF", "Comorian Franc" },
{ 188, "CRC", "Costa Rica Colon" },
{ 191, "HRK", "Croatia Kuna" },
{ 192, "CUP", "Cuba Peso" },
{ 203, "CZK", "Czech Republic Koruna" },
{ 208, "DKK", "Denmark Krone" },
{ 214, "DOP", "Dominican Republic Peso" },
{ 222, "SVC", "El Salvador Colon" },
{ 230, "ETB", "Ethiopia Birr" },
{ 232, "ERN", "Eritrea Nakfa" },
{ 238, "FKP", "Falkland Islands (Malvinas) Pound" },
{ 242, "FJD", "Fiji Dollar" },
{ 262, "DJF", "Djibouti Franc" },
{ 270, "GMD", "Gambia Dalasi" },
{ 292, "GIP", "Gibraltar Pound" },
{ 320, "GTQ", "Guatemala Quetzal" },
{ 324, "GNF", "Guinea Franc" },
{ 328, "GYD", "Guyana Dollar" },
{ 332, "HTG", "Haiti Gourde" },
{ 340, "HNL", "Honduras Lempira" },
{ 344, "HKD", "Hong Kong Dollar" },
{ 348, "HUF", "Hungary Forint" },
{ 352, "ISK", "Iceland Krona" },
{ 356, "INR", "India Rupee" },
{ 360, "IDR", "Indonesia Rupiah" },
{ 364, "IRR", "Iran Rial" },
{ 368, "IQD", "Iraq Dinar" },
{ 376, "ILS", "Israel Shekel" },
{ 388, "JMD", "Jamaica Dollar" },
{ 392, "JPY", "Japan Yen" },
{ 398, "KZT", "Kazakhstan Tenge" },
{ 400, "JOD", "Jordan Dinar" },
{ 404, "KES", "Kenya Shilling" },
{ 408, "KPW", "Korea (North) Won" },
{ 410, "KRW", "Korea (South) Won" },
{ 414, "KWD", "Kuwait Dinar" },
{ 417, "KGS", "Kyrgyzstan Som" },
{ 418, "LAK", "Laos Kip" },
{ 422, "LBP", "Lebanon Pound" },
{ 426, "LSL", "Lesotho Loti" },
{ 430, "LRD", "Liberia Dollar" },
{ 434, "LYD", "Libya Dinar" },
{ 446, "MOP", "Macau Pataca" },
{ 454, "MWK", "Malawi Kwacha" },
{ 458, "MYR", "Malaysia Ringgit" },
{ 462, "MVR", "Maldives (Maldive Islands) Rufiyaa" },
{ 478, "MRO", "Mauritania Ouguiya" },
{ 480, "MUR", "Mauritius Rupee" },
{ 484, "MXN", "Mexico Peso" },
{ 496, "MNT", "Mongolia Tughrik" },
{ 498, "MDL", "Moldova Leu" },
{ 504, "MAD", "Morocco Dirham" },
{ 512, "OMR", "Oman Rial" },
{ 516, "NAD", "Namibia Dollar" },
{ 524, "NPR", "Nepal Rupee" },
{ 532, "ANG", "Netherlands Antilles Guilder" },
{ 533, "AWG", "Aruba Guilder" },
{ 548, "VUV", "Vanuatu Vatu" },
{ 554, "NZD", "New Zealand Dollar" },
{ 558, "NIO", "Nicaragua Cordoba" },
{ 566, "NGN", "Nigeria Naira" },
{ 578, "NOK", "Norway Krone" },
{ 586, "PKR", "Pakistan Rupee" },
{ 590, "PAB", "Panama Balboa" },
{ 598, "PGK", "Papua New Guinea Kina" },
{ 600, "PYG", "Paraguay Guarani" },
{ 604, "PEN", "Peru Sol" },
{ 608, "PHP", "Philippines Peso" },
{ 634, "QAR", "Qatar Riyal" },
{ 643, "RUB", "Russia Ruble" },
{ 646, "RWF", "Rwanda Franc" },
{ 654, "SHP", "Saint Helena Pound" },
{ 678, "STD", "Sao Tome and Principe dobra" },
{ 682, "SAR", "Saudi Arabia Riyal" },
{ 690, "SCR", "Seychelles Rupee" },
{ 694, "SLL", "Sierra Leone Leone" },
{ 702, "SGD", "Singapore Dollar" },
{ 704, "VND", "Viet Nam Dong" },
{ 706, "SOS", "Somalia Shilling" },
{ 710, "ZAR", "South Africa Rand" },
{ 728, "SSP", "South Sudanese pound" },
{ 748, "SZL", "Swaziland Lilangeni" },
{ 752, "SEK", "Sweden Krona" },
{ 756, "CHF", "Switzerland Franc" },
{ 760, "SYP", "Syria Pound" },
{ 764, "THB", "Thailand Baht" },
{ 776, "TOP", "Tonga Pa‘anga" },
{ 780, "TTD", "Trinidad and Tobago Dollar" },
{ 784, "AED", "United Arab Emirates Dirham" },
{ 788, "TND", "Tunisia Dinar" },
{ 800, "UGX", "Uganda Shilling" },
{ 807, "MKD", "Macedonia Denar" },
{ 818, "EGP", "Egypt Pound" },
{ 826, "GBP", "United Kingdom Pound" },
{ 834, "TZS", "Tanzania Shilling" },
{ 840, "USD", "United States Dollar" },
{ 858, "UYU", "Uruguay Peso" },
{ 860, "UZS", "Uzbekistan Som" },
{ 882, "WST", "Samoa Tala" },
{ 886, "YER", "Yemen Rial" },
{ 901, "TWD", "Taiwan New Dollar" },
{ 931, "CUC", "Cuba Convertible Peso" },
{ 932, "ZWL", "Zimbabwe Dollar" },
{ 933, "BYN", "Belarus Ruble" },
{ 934, "TMT", "Turkmenistan Manat" },
{ 936, "GHS", "Ghana Cedi" },
{ 937, "VEF", "Venezuela Bolívar" },
{ 938, "SDG", "Sudan Pound" },
{ 941, "RSD", "Serbia Dinar" },
{ 943, "MZN", "Mozambique Metical" },
{ 944, "AZN", "Azerbaijan Manat" },
{ 946, "RON", "Romania Leu" },
{ 949, "TRY", "Turkey Lira" },
{ 950, "XAF", "CFA franc BEAC" },
{ 951, "XCD", "East Caribbean Dollar" },
{ 952, "XOF", "CFA franc BCEAO" },
{ 953, "XPF", "CFP franc (franc Pacifique)" },
{ 960, "XDR", "IMF Special Drawing Rights" },
{ 967, "ZMW", "Zambia Kwacha" },
{ 968, "SRD", "Suriname Dollar" },
{ 969, "MGA", "Madagascar Ariary" },
{ 971, "AFN", "Afghanistan Afghani" },
{ 972, "TJS", "Tajikistan Somoni" },
{ 973, "AOA", "Angola Kwanza" },
{ 975, "BGN", "Bulgaria Lev" },
{ 976, "CDF", "Congo/Kinshasa Franc" },
{ 977, "BAM", "Bosnia and Herzegovina Convertible Marka" },
{ 978, "EUR", "Euro" },
{ 980, "UAH", "Ukraine Hryvnia" },
{ 981, "GEL", "Georgia Lari" },
{ 985, "PLN", "Poland Zloty" },
{ 986, "BRL", "Brazil Real" },
{ 0, "---", "Unknown currency" }
};
//------------------------------------------------------------------------------
int findCurrencyIndexByNumCode(uint16_t num_code)
{
int i = 0;
do {
if (iso4217_currency_codes[i].num_code == num_code)
break;
i++;
} while (iso4217_currency_codes[i].num_code != 0);
return i;
}
//------------------------------------------------------------------------------
/*
* iso4217.h
*
* Created on: 09.08.2017.
* Author: d-logic
*/
#ifndef ISO4217_H_
#define ISO4217_H_
#include <inttypes.h>
//==============================================================================
typedef struct iso4217_currency_code_s {
uint16_t num_code;
char *alpha_code;
char *currency;
} iso4217_currency_code_t;
//------------------------------------------------------------------------------
extern iso4217_currency_code_t iso4217_currency_codes[];
//------------------------------------------------------------------------------
int findCurrencyIndexByNumCode(uint16_t num_code);
//==============================================================================
#endif /* ISO4217_H_ */
......@@ -6,52 +6,21 @@
#include <stdlib.h>
#include <inttypes.h>
#include <stdbool.h>
#include <windows.h>
#include <string.h>
#include <uFCoder.h>
#include "ini.h"
#include "uFR.h"
#include "utils.h"
//------------------------------------------------------------------------------
size_t hex2bin(uint8_t *dst, const char *src) {
size_t dst_len = 0;
char s_tmp[3];
s_tmp[2] = '\0';
while (*src) {
while (((char)*src < '0' || (char)*src > '9')
&& ((char)*src < 'a' || (char)*src > 'f')
&& ((char)*src < 'A' || (char)*src > 'F'))
src++; // skip delimiters, white spaces, etc.
s_tmp[0] = (char) *src++;
// Must be pair of the hex digits:
if (!(*src))
break;
// And again, must be pair of the hex digits:
if (((char)*src < '0' || (char)*src > '9')
&& ((char)*src < 'a' || (char)*src > 'f')
&& ((char)*src < 'A' || (char)*src > 'F'))
break;
s_tmp[1] = (char) *src++;
*dst++ = strtoul(s_tmp, NULL, 16);
dst_len++;
}
return dst_len;
}
//------------------------------------------------------------------------------
UFR_STATUS ApduCommand(sz_ptr apdu, char **response, uint8_t *sw) {
UFR_STATUS ApduCommand(const char *apdu, char **response, uint8_t *sw) {
UFR_STATUS status;
status = APDUHexStrTransceive(apdu, response);
if (status)
return status;
// printf("DEBUG >>> %d\n\n\n", (int)strlen(*response));
if (strlen(*response) % 2)
return UFR_PARAMETERS_ERROR;
......@@ -73,6 +42,32 @@ bool CheckDependencies(void) {
UFR_STATUS status;
#ifdef EXIT_ON_WRONG_LIB_DEPENDENCY
uint32_t dwDllVersion = 0;
dwDllVersion = GetDllVersion();
// "explode" the dll version:
version_major = LOBYTE(LOWORD(dwDllVersion));
version_minor = HIBYTE(LOWORD(dwDllVersion));
// Get the dll build number.
build = HIWORD(dwDllVersion);
if (version_major < MIN_DEPEND_LIB_VER_MAJOR) {
wrong_version = true;
} else if (version_major == MIN_DEPEND_LIB_VER_MAJOR && version_minor < MIN_DEPEND_LIB_VER_MINOR) {
wrong_version = true;
} else if (version_major == MIN_DEPEND_LIB_VER_MAJOR && version_minor == MIN_DEPEND_LIB_VER_MINOR && build < MIN_DEPEND_LIB_VER_BUILD) {
wrong_version = true;
}
if (wrong_version) {
printf("Wrong uFCoder library version (%d.%d.%d).\n"
"Please update uFCoder library to at last %d.%d.%d version.\n",
version_major, version_minor, build,
MIN_DEPEND_LIB_VER_MAJOR, MIN_DEPEND_LIB_VER_MINOR, MIN_DEPEND_LIB_VER_BUILD);
return false;
}
#endif
#ifdef EXIT_ON_WRONG_FW_DEPENDENCY
wrong_version = false;
......@@ -90,7 +85,7 @@ bool CheckDependencies(void) {
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) {
} else if (version_major == MIN_DEPEND_FW_VER_MAJOR && version_minor == MIN_DEPEND_FW_VER_MINOR && build < MIN_DEPEND_FW_VER_BUILD) {
wrong_version = true;
}
......@@ -104,7 +99,7 @@ bool CheckDependencies(void) {
return true;
}
//------------------------------------------------------------------------------
sz_ptr GetDlTypeName(uint8_t dl_type_code) {
const char *GetDlTypeName(uint8_t dl_type_code) {
switch (dl_type_code) {
case DL_MIFARE_ULTRALIGHT:
......
......@@ -5,15 +5,15 @@
#ifndef UFR_H_
#define UFR_H_
#include "inttypes.h"
#include "stdbool.h"
#include "ini.h"
#define MIN_APDU_HEX_STR_LEN 5
//------------------------------------------------------------------------------
typedef const char * sz_ptr;
//------------------------------------------------------------------------------
UFR_STATUS ApduCommand(sz_ptr apdu, char **response, uint8_t *sw);
size_t hex2bin(uint8_t *dst, const char *src);
UFR_STATUS ApduCommand(const char *apdu, char **response, uint8_t *sw);
bool CheckDependencies(void);
sz_ptr GetDlTypeName(uint8_t dl_type_code);
const char *GetDlTypeName(uint8_t dl_type_code);
//------------------------------------------------------------------------------
#endif /* UFR_H_ */
......@@ -5,6 +5,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdbool.h>
#include <ctype.h>
#include "ini.h"
#include "utils.h"
......@@ -36,5 +38,60 @@ void print_hex_ln(const uint8_t *data, uint32_t len, const char *delimiter) {
print_hex(data, len, delimiter);
printf("\n");
}
//------------------------------------------------------------------------------
int bin_bcd_to_i(const uint8_t *bin, uint32_t len) {
int result = 0, dec = 1;
for (int i = len; i > 0; i--) {
result += (bin[i - 1] & 0x0F) * dec;
dec *= 10;
result += (bin[i - 1] >> 4) * dec;
dec *= 10;
}
return result;
}
//------------------------------------------------------------------------------
bool isByteArrayPrintable(const uint8_t *arr, uint32_t len) {
for (int i = 0; i < len; i++) {
if (!isprint(arr[i])) {
return false;
}
}
return true;
}
//------------------------------------------------------------------------------
size_t hex2bin(uint8_t *dst, const char *src) {
size_t dst_len = 0;
char s_tmp[3];
s_tmp[2] = '\0';
while (*src) {
while (((char)*src < '0' || (char)*src > '9')
&& ((char)*src < 'a' || (char)*src > 'f')
&& ((char)*src < 'A' || (char)*src > 'F'))
src++; // skip delimiters, white spaces, etc.
s_tmp[0] = (char) *src++;
// Must be pair of the hex digits:
if (!(*src))
break;
// And again, must be pair of the hex digits:
if (((char)*src < '0' || (char)*src > '9')
&& ((char)*src < 'a' || (char)*src > 'f')
&& ((char)*src < 'A' || (char)*src > 'F'))
break;
s_tmp[1] = (char) *src++;
*dst++ = strtoul(s_tmp, NULL, 16);
dst_len++;
}
return dst_len;
}
//==============================================================================
......@@ -5,11 +5,16 @@
#ifndef UTILS_H_
#define UTILS_H_
#include <stdbool.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);
int bin_bcd_to_i(const uint8_t *bin, uint32_t len);
bool isByteArrayPrintable(const uint8_t *s, uint32_t len);
size_t hex2bin(uint8_t *dst, const char *src);
#endif /* UTILS_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment