Massive code clean up: (Fixes Issue 161)
- Remove typedef from internal structs - Remove _t suffix from types - Fix tests using connstrings
This commit is contained in:
parent
55daa29a7c
commit
c718fafee7
47 changed files with 546 additions and 533 deletions
|
|
@ -48,7 +48,7 @@
|
|||
* 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 (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp)
|
||||
nfc_initiator_mifare_cmd (nfc_device * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp)
|
||||
{
|
||||
byte_t abtRx[265];
|
||||
size_t szRx = sizeof(abtRx);
|
||||
|
|
@ -69,19 +69,19 @@ nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t
|
|||
// Authenticate command
|
||||
case MC_AUTH_A:
|
||||
case MC_AUTH_B:
|
||||
szParamLen = sizeof (mifare_param_auth);
|
||||
szParamLen = sizeof (struct mifare_param_auth);
|
||||
break;
|
||||
|
||||
// Data command
|
||||
case MC_WRITE:
|
||||
szParamLen = sizeof (mifare_param_data);
|
||||
szParamLen = sizeof (struct mifare_param_data);
|
||||
break;
|
||||
|
||||
// Value command
|
||||
case MC_DECREMENT:
|
||||
case MC_INCREMENT:
|
||||
case MC_TRANSFER:
|
||||
szParamLen = sizeof (mifare_param_value);
|
||||
szParamLen = sizeof (struct mifare_param_value);
|
||||
break;
|
||||
|
||||
// Please fix your code, you never should reach this statement
|
||||
|
|
|
|||
|
|
@ -53,29 +53,29 @@ typedef enum {
|
|||
} mifare_cmd;
|
||||
|
||||
// MIFARE command params
|
||||
typedef struct {
|
||||
struct mifare_param_auth {
|
||||
byte_t abtKey[6];
|
||||
byte_t abtUid[4];
|
||||
} mifare_param_auth;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct mifare_param_data {
|
||||
byte_t abtData[16];
|
||||
} mifare_param_data;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct mifare_param_value {
|
||||
byte_t abtValue[4];
|
||||
} mifare_param_value;
|
||||
};
|
||||
|
||||
typedef union {
|
||||
mifare_param_auth mpa;
|
||||
mifare_param_data mpd;
|
||||
mifare_param_value mpv;
|
||||
struct mifare_param_auth mpa;
|
||||
struct mifare_param_data mpd;
|
||||
struct mifare_param_value mpv;
|
||||
} mifare_param;
|
||||
|
||||
// Reset struct alignment to default
|
||||
# pragma pack()
|
||||
|
||||
bool nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp);
|
||||
bool nfc_initiator_mifare_cmd (nfc_device * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp);
|
||||
|
||||
// Compiler directive, set struct alignment to 1 byte_t for compatibility
|
||||
# pragma pack(1)
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
#include "nfc-utils.h"
|
||||
|
||||
static nfc_device_t *pnd;
|
||||
static nfc_device *pnd;
|
||||
|
||||
void
|
||||
stop_emulation (int sig)
|
||||
|
|
@ -155,7 +155,7 @@ main(int argc, char *argv[])
|
|||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
nfc_target_t nt = {
|
||||
nfc_target nt = {
|
||||
.nm = {
|
||||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_UNDEFINED, // Will be updated by nfc_target_init()
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@
|
|||
|
||||
#include "nfc-utils.h"
|
||||
|
||||
static nfc_device_t *pnd;
|
||||
static nfc_device *pnd;
|
||||
static bool quiet_output = false;
|
||||
|
||||
#define SYMBOL_PARAM_fISO14443_4_PICC 0x20
|
||||
|
|
@ -289,7 +289,7 @@ usage (char *progname)
|
|||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
nfc_target_t nt = {
|
||||
nfc_target nt = {
|
||||
.nm = {
|
||||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_UNDEFINED, // Will be updated by nfc_target_init()
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
#define MAX_DEVICE_COUNT 16
|
||||
#define MAX_TARGET_COUNT 16
|
||||
|
||||
static nfc_device_t *pnd;
|
||||
static nfc_device *pnd;
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
|
|
@ -108,7 +108,7 @@ main (int argc, const char *argv[])
|
|||
}
|
||||
|
||||
for (i = 0; i < szDeviceFound; i++) {
|
||||
nfc_target_t ant[MAX_TARGET_COUNT];
|
||||
nfc_target ant[MAX_TARGET_COUNT];
|
||||
pnd = nfc_connect (connstrings[i]);
|
||||
|
||||
if (pnd == NULL) {
|
||||
|
|
@ -119,7 +119,7 @@ main (int argc, const char *argv[])
|
|||
|
||||
printf ("Connected to NFC device: %s\n", pnd->acName);
|
||||
|
||||
nfc_modulation_t nm;
|
||||
nfc_modulation nm;
|
||||
|
||||
nm.nmt = NMT_ISO14443A;
|
||||
nm.nbr = NBR_106;
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@
|
|||
#include "mifare.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
static nfc_device_t *pnd;
|
||||
static nfc_target_t nt;
|
||||
static nfc_device *pnd;
|
||||
static nfc_target nt;
|
||||
static mifare_param mp;
|
||||
static mifare_classic_tag mtKeys;
|
||||
static mifare_classic_tag mtDump;
|
||||
|
|
@ -72,7 +72,7 @@ static byte_t keys[] = {
|
|||
0xab, 0xcd, 0xef, 0x12, 0x34, 0x56
|
||||
};
|
||||
|
||||
static const nfc_modulation_t nmMifare = {
|
||||
static const nfc_modulation nmMifare = {
|
||||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ static byte_t abtSak;
|
|||
static byte_t abtAts[MAX_FRAME_LEN];
|
||||
static byte_t szAts = 0;
|
||||
static size_t szCL = 1;//Always start with Cascade Level 1 (CL1)
|
||||
static nfc_device_t *pnd;
|
||||
static nfc_device *pnd;
|
||||
|
||||
bool quiet_output = false;
|
||||
bool iso_ats_supported = false;
|
||||
|
|
|
|||
|
|
@ -51,13 +51,13 @@
|
|||
#include "nfc-utils.h"
|
||||
#include "mifare.h"
|
||||
|
||||
static nfc_device_t *pnd;
|
||||
static nfc_target_t nt;
|
||||
static nfc_device *pnd;
|
||||
static nfc_target nt;
|
||||
static mifare_param mp;
|
||||
static mifareul_tag mtDump;
|
||||
static uint32_t uiBlocks = 0xF;
|
||||
|
||||
static const nfc_modulation_t nmMifare = {
|
||||
static const nfc_modulation nmMifare = {
|
||||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
|
||||
#include "nfc-utils.h"
|
||||
|
||||
static nfc_device_t *pnd;
|
||||
static nfc_device *pnd;
|
||||
|
||||
void
|
||||
print_usage(char *progname)
|
||||
|
|
@ -77,7 +77,7 @@ void stop_select (int sig)
|
|||
}
|
||||
|
||||
void
|
||||
build_felica_frame(const nfc_felica_info_t nfi, const byte_t command, const byte_t* payload, const size_t payload_len, byte_t * frame, size_t * frame_len)
|
||||
build_felica_frame(const nfc_felica_info nfi, const byte_t command, const byte_t* payload, const size_t payload_len, byte_t * frame, size_t * frame_len)
|
||||
{
|
||||
frame[0] = 1 + 1 + 8 + payload_len;
|
||||
*frame_len = frame[0];
|
||||
|
|
@ -88,7 +88,7 @@ build_felica_frame(const nfc_felica_info_t nfi, const byte_t command, const byte
|
|||
|
||||
#define CHECK 0x06
|
||||
int
|
||||
nfc_forum_tag_type3_check (nfc_device_t *pnd, const nfc_target_t nt, const uint16_t block, const uint8_t block_count, byte_t * data, size_t * data_len)
|
||||
nfc_forum_tag_type3_check (nfc_device *pnd, const nfc_target nt, const uint16_t block, const uint8_t block_count, byte_t * data, size_t * data_len)
|
||||
{
|
||||
byte_t payload[1024] = {
|
||||
1, // Services
|
||||
|
|
@ -204,14 +204,14 @@ main(int argc, char *argv[])
|
|||
|
||||
fprintf (message_stream, "Connected to NFC device: %s\n", pnd->acName);
|
||||
|
||||
nfc_modulation_t nm = {
|
||||
nfc_modulation nm = {
|
||||
.nmt = NMT_FELICA,
|
||||
.nbr = NBR_212,
|
||||
};
|
||||
|
||||
signal (SIGINT, stop_select);
|
||||
|
||||
nfc_target_t nt;
|
||||
nfc_target nt;
|
||||
|
||||
nfc_initiator_init(pnd);
|
||||
fprintf (message_stream, "Place your NFC Forum Tag Type 3 in the field...\n");
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ static byte_t abtCapdu[MAX_FRAME_LEN];
|
|||
static size_t szCapduLen;
|
||||
static byte_t abtRapdu[MAX_FRAME_LEN];
|
||||
static size_t szRapduLen;
|
||||
static nfc_device_t *pndInitiator;
|
||||
static nfc_device_t *pndTarget;
|
||||
static nfc_device *pndInitiator;
|
||||
static nfc_device *pndTarget;
|
||||
static bool quitting = false;
|
||||
static bool quiet_output = false;
|
||||
static bool initiator_only_mode = false;
|
||||
|
|
@ -151,7 +151,7 @@ main (int argc, char *argv[])
|
|||
int arg;
|
||||
size_t szFound;
|
||||
const char *acLibnfcVersion = nfc_version ();
|
||||
nfc_target_t ntRealTarget;
|
||||
nfc_target ntRealTarget;
|
||||
|
||||
// Get commandline options
|
||||
for (arg = 1; arg < argc; arg++) {
|
||||
|
|
@ -236,7 +236,7 @@ main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Try to find a ISO 14443-4A tag
|
||||
nfc_modulation_t nm = {
|
||||
nfc_modulation nm = {
|
||||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
|
|
@ -279,7 +279,7 @@ main (int argc, char *argv[])
|
|||
printf ("Hint: tag <---> initiator (relay) <---> target (relay) <---> original reader\n\n");
|
||||
}
|
||||
if (!initiator_only_mode) {
|
||||
nfc_target_t ntEmulatedTarget = {
|
||||
nfc_target ntEmulatedTarget = {
|
||||
.nm = {
|
||||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ print_hex_par (const byte_t * pbtData, const size_t szBits, const byte_t * pbtDa
|
|||
#define SAK_ISO18092_COMPLIANT 0x40
|
||||
|
||||
void
|
||||
print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai, bool verbose)
|
||||
print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
|
||||
{
|
||||
printf (" ATQA (SENS_RES): ");
|
||||
print_hex (nai.abtAtqa, 2);
|
||||
|
|
@ -530,7 +530,7 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai, bool verbose)
|
|||
}
|
||||
|
||||
void
|
||||
print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose)
|
||||
print_nfc_felica_info (const nfc_felica_info nfi, bool verbose)
|
||||
{
|
||||
(void) verbose;
|
||||
printf (" ID (NFCID2): ");
|
||||
|
|
@ -542,7 +542,7 @@ print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose)
|
|||
}
|
||||
|
||||
void
|
||||
print_nfc_jewel_info (const nfc_jewel_info_t nji, bool verbose)
|
||||
print_nfc_jewel_info (const nfc_jewel_info nji, bool verbose)
|
||||
{
|
||||
(void) verbose;
|
||||
printf (" ATQA (SENS_RES): ");
|
||||
|
|
@ -555,7 +555,7 @@ print_nfc_jewel_info (const nfc_jewel_info_t nji, bool verbose)
|
|||
#define PI_NAD_SUPPORTED 0x01
|
||||
#define PI_CID_SUPPORTED 0x02
|
||||
void
|
||||
print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi, bool verbose)
|
||||
print_nfc_iso14443b_info (const nfc_iso14443b_info nbi, bool verbose)
|
||||
{
|
||||
const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 };
|
||||
printf (" PUPI: ");
|
||||
|
|
@ -610,7 +610,7 @@ print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi, bool verbose)
|
|||
}
|
||||
|
||||
void
|
||||
print_nfc_iso14443bi_info (const nfc_iso14443bi_info_t nii, bool verbose)
|
||||
print_nfc_iso14443bi_info (const nfc_iso14443bi_info nii, bool verbose)
|
||||
{
|
||||
printf (" DIV: ");
|
||||
print_hex (nii.abtDIV, 4);
|
||||
|
|
@ -634,7 +634,7 @@ print_nfc_iso14443bi_info (const nfc_iso14443bi_info_t nii, bool verbose)
|
|||
}
|
||||
|
||||
void
|
||||
print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info_t nsi, bool verbose)
|
||||
print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info nsi, bool verbose)
|
||||
{
|
||||
(void) verbose;
|
||||
printf (" UID: ");
|
||||
|
|
@ -642,7 +642,7 @@ print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info_t nsi, bool verbose)
|
|||
}
|
||||
|
||||
void
|
||||
print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info_t nci, bool verbose)
|
||||
print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info nci, bool verbose)
|
||||
{
|
||||
(void) verbose;
|
||||
uint32_t uid;
|
||||
|
|
@ -655,7 +655,7 @@ print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info_t nci, bool verbose)
|
|||
}
|
||||
|
||||
void
|
||||
print_nfc_dep_info (const nfc_dep_info_t ndi, bool verbose)
|
||||
print_nfc_dep_info (const nfc_dep_info ndi, bool verbose)
|
||||
{
|
||||
(void) verbose;
|
||||
printf (" NFCID3: ");
|
||||
|
|
@ -671,7 +671,7 @@ print_nfc_dep_info (const nfc_dep_info_t ndi, bool verbose)
|
|||
}
|
||||
|
||||
const char *
|
||||
str_nfc_baud_rate (const nfc_baud_rate_t nbr)
|
||||
str_nfc_baud_rate (const nfc_baud_rate nbr)
|
||||
{
|
||||
switch(nbr) {
|
||||
case NBR_UNDEFINED:
|
||||
|
|
@ -694,7 +694,7 @@ str_nfc_baud_rate (const nfc_baud_rate_t nbr)
|
|||
}
|
||||
|
||||
void
|
||||
print_nfc_target (const nfc_target_t nt, bool verbose)
|
||||
print_nfc_target (const nfc_target nt, bool verbose)
|
||||
{
|
||||
switch(nt.nm.nmt) {
|
||||
case NMT_ISO14443A:
|
||||
|
|
|
|||
|
|
@ -86,15 +86,15 @@ void print_hex (const byte_t * pbtData, const size_t szLen);
|
|||
void print_hex_bits (const byte_t * pbtData, const size_t szBits);
|
||||
void print_hex_par (const byte_t * pbtData, const size_t szBits, const byte_t * pbtDataPar);
|
||||
|
||||
void print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai, bool verbose);
|
||||
void print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi, bool verbose);
|
||||
void print_nfc_iso14443bi_info (const nfc_iso14443bi_info_t nii, bool verbose);
|
||||
void print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info_t nsi, bool verbose);
|
||||
void print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info_t nci, bool verbose);
|
||||
void print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose);
|
||||
void print_nfc_jewel_info (const nfc_jewel_info_t nji, bool verbose);
|
||||
void print_nfc_dep_info (const nfc_dep_info_t ndi, bool verbose);
|
||||
void print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose);
|
||||
void print_nfc_iso14443b_info (const nfc_iso14443b_info nbi, bool verbose);
|
||||
void print_nfc_iso14443bi_info (const nfc_iso14443bi_info nii, bool verbose);
|
||||
void print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info nsi, bool verbose);
|
||||
void print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info nci, bool verbose);
|
||||
void print_nfc_felica_info (const nfc_felica_info nfi, bool verbose);
|
||||
void print_nfc_jewel_info (const nfc_jewel_info nji, bool verbose);
|
||||
void print_nfc_dep_info (const nfc_dep_info ndi, bool verbose);
|
||||
|
||||
void print_nfc_target (const nfc_target_t nt, bool verbose);
|
||||
void print_nfc_target (const nfc_target nt, bool verbose);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue