Skip to content

Commit

Permalink
Updates source code to use libnfc 1.7.0
Browse files Browse the repository at this point in the history
This commit also fix some warnings.
  • Loading branch information
[email protected] committed Jan 20, 2013
1 parent 41a5a30 commit 8521f43
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([mfcuk], [0.3.4], [[email protected]])
AC_INIT([mfcuk], [0.3.5], [[email protected]])

AC_CONFIG_MACRO_DIR([m4])

Expand All @@ -11,7 +11,7 @@ AM_INIT_AUTOMAKE
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])

# Checks for pkg-config modules.
LIBNFC_REQUIRED_VERSION=1.6.0
LIBNFC_REQUIRED_VERSION=1.7.0
PKG_CHECK_MODULES([libnfc], [libnfc >= $LIBNFC_REQUIRED_VERSION], [], [AC_MSG_ERROR([libnfc >= $LIBNFC_REQUIRED_VERSION is mandatory.])])

PKG_CONFIG_REQUIRES="libnfc"
Expand Down
35 changes: 18 additions & 17 deletions src/mfcuk.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
# define ERR(...) warnx ("ERROR: " __VA_ARGS__ )
#endif

uint32_t bswap_32_pu8(uint8_t *pu8)
static uint32_t bswap_32_pu8(uint8_t *pu8)
{
uint32_t u32;
memcpy(&u32, pu8, sizeof(uint32_t));
Expand All @@ -231,7 +231,7 @@ static const nfc_modulation nmMifare = {
.nbr = NBR_106,
};

int compareTagNonces (const void * a, const void * b)
static int compareTagNonces (const void * a, const void * b)
{
// TODO: test the improvement (especially corner cases, over/under-flows) "return ( (*(uint32_t*)a) - (*(uint32_t*)b) );
if ( *(uint32_t*)a > *(uint32_t*)b ) return 1;
Expand All @@ -242,7 +242,7 @@ int compareTagNonces (const void * a, const void * b)
}

// TODO: combine mfcuk_verify_key_block() with mfcuk_recover_key_block(), since a lot of code is duplicate
uint32_t mfcuk_verify_key_block(nfc_device* pnd, uint32_t uiUID, uint64_t ui64Key, mifare_key_type bKeyType, uint8_t bTagType, uint32_t uiBlock)
static uint32_t mfcuk_verify_key_block(nfc_device* pnd, uint32_t uiUID, uint64_t ui64Key, mifare_key_type bKeyType, uint8_t bTagType, uint32_t uiBlock)
{
uint32_t pos;

Expand Down Expand Up @@ -354,7 +354,7 @@ uint32_t mfcuk_verify_key_block(nfc_device* pnd, uint32_t uiUID, uint64_t ui64Ke
}

int res;
if ( 0 > (res = nfc_initiator_transceive_bits(pnd,abtArEnc,64,abtArEncPar,abtRx,abtRxPar)) )
if ( 0 > (res = nfc_initiator_transceive_bits(pnd,abtArEnc,64,abtArEncPar,abtRx,sizeof(abtRx),abtRxPar)) )
{
return MFCUK_FAIL_AUTH;
}
Expand Down Expand Up @@ -394,7 +394,7 @@ uint32_t mfcuk_verify_key_block(nfc_device* pnd, uint32_t uiUID, uint64_t ui64Ke
return MFCUK_SUCCESS;
}

uint32_t mfcuk_key_recovery_block(nfc_device* pnd, uint32_t uiUID, uint64_t ui64Key, mifare_key_type bKeyType, uint8_t bTagType, uint32_t uiBlock, uint64_t *ui64KeyRecovered)
static uint32_t mfcuk_key_recovery_block(nfc_device* pnd, uint32_t uiUID, uint64_t ui64Key, mifare_key_type bKeyType, uint8_t bTagType, uint32_t uiBlock, uint64_t *ui64KeyRecovered)
{
// Communication variables
uint32_t pos, pos2, nt;
Expand Down Expand Up @@ -639,7 +639,7 @@ uint32_t mfcuk_key_recovery_block(nfc_device* pnd, uint32_t uiUID, uint64_t ui64
//print_hex_par(abtArEnc,64,abtArEncPar);

int res;
if (0 > (res=nfc_initiator_transceive_bits(pnd,abtArEnc,64,abtArEncPar,abtRx,abtRxPar)))
if (0 > (res=nfc_initiator_transceive_bits(pnd,abtArEnc,64,abtArEncPar,abtRx,sizeof(abtRx),abtRxPar)))
{
if (sendSpoofAr)
{
Expand Down Expand Up @@ -751,7 +751,7 @@ uint32_t mfcuk_key_recovery_block(nfc_device* pnd, uint32_t uiUID, uint64_t ui64
-m max_iterations - stop everything after so many iterations, default is infinite until all keys found
-T max_elapsed_time - stop after time elapsed
*/
void print_usage(FILE *fp, const char * prog_name)
static void print_usage(FILE *fp, const char * prog_name)
{
fprintf(fp, "Usage:\n");
fprintf(fp, "-C - require explicit connection to the reader. Without this option, the connection is not made and recovery will not occur\n");
Expand Down Expand Up @@ -787,15 +787,15 @@ void print_usage(FILE *fp, const char * prog_name)
return;
}

void print_identification(void)
static void print_identification(void)
{
fprintf(stdout, "%s - %s\n", PACKAGE_NAME, PACKAGE_VERSION);
fprintf(stdout, "%s - %s\n", BUILD_NAME, BUILD_VERSION);
fprintf(stdout, "by %s\n", BUILD_AUTHOR);
fprintf(stdout, "\n");
}

void print_mifare_classic_tag_actions(const char *title, mifare_classic_tag *tag)
static void print_mifare_classic_tag_actions(const char *title, mifare_classic_tag *tag)
{
uint32_t i, max_blocks, trailer_block;
uint8_t bTagType;
Expand Down Expand Up @@ -866,7 +866,7 @@ void print_mifare_classic_tag_actions(const char *title, mifare_classic_tag *tag
return;
}

bool mfcuk_darkside_reset_advanced(nfc_device *pnd)
static bool mfcuk_darkside_reset_advanced(nfc_device *pnd)
{
if ( 0 > nfc_device_set_property_bool(pnd,NP_HANDLE_CRC,true) )
{
Expand All @@ -883,7 +883,7 @@ bool mfcuk_darkside_reset_advanced(nfc_device *pnd)
return true;
}

bool mfcuk_darkside_select_tag(nfc_device *pnd, int iSleepAtFieldOFF, int iSleepAfterFieldON, nfc_target_info *ti)
static bool mfcuk_darkside_select_tag(nfc_device *pnd, int iSleepAtFieldOFF, int iSleepAfterFieldON, nfc_target_info *ti)
{
nfc_target ti_tmp;

Expand Down Expand Up @@ -965,11 +965,12 @@ int main(int argc, char* argv[])
int iSleepAfterFieldON = SLEEP_AFTER_FIELD_ON; // modified with argument -s

char *token = NULL;
char *sep = ":";
const char *sep = ":";
char *str = NULL;
int iter = 0;

// libnfc related
nfc_context *context;
nfc_device* pnd;
nfc_target ti;

Expand Down Expand Up @@ -1591,8 +1592,8 @@ int main(int argc, char* argv[])

// READER INITIALIZATION BLOCK
// Try to open the NFC reader
nfc_init(NULL);
pnd = nfc_open(NULL, NULL);
nfc_init(&context);
pnd = nfc_open (context, NULL);

if (pnd == NULL)
{
Expand Down Expand Up @@ -1794,7 +1795,7 @@ int main(int argc, char* argv[])
nfc_close(pnd);

// Try to open the NFC reader
pnd = nfc_open(NULL, NULL);
pnd = nfc_open (context, NULL);

if (pnd == NULL)
{
Expand Down Expand Up @@ -1876,7 +1877,7 @@ int main(int argc, char* argv[])

// Clean up and release device
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit (context);

// TODO: think which tag to output and make sure it contains all the retreived data
// TODO: make this as a function and call it after each key is verified or recovered (because of reader-locking bug)
Expand Down Expand Up @@ -1913,6 +1914,6 @@ int main(int argc, char* argv[])

error:
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit (context);
return EXIT_FAILURE;
}
4 changes: 2 additions & 2 deletions src/mfcuk_finger.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ typedef int (*mfcuk_finger_decoder) (mifare_classic_tag *dump);
// Naive implementation of a self-contained fingerprint database entry
typedef struct _mfcuk_finger_tmpl_entry_
{
char *tmpl_filename;
char *tmpl_name;
const char *tmpl_filename;
const char *tmpl_name;
mfcuk_finger_comparator tmpl_comparison_func;
mfcuk_finger_decoder tmpl_decoder_func;
mfcuk_finger_template *tmpl_data;
Expand Down

0 comments on commit 8521f43

Please sign in to comment.