mirror of
https://github.com/nfc-tools/mfcuk.git
synced 2026-02-18 02:55:49 +00:00
mfcuk now compiles again libnfc's development version (1.5.1)
This commit is contained in:
parent
b67f50f281
commit
de55e33177
@ -29,7 +29,7 @@ fi
|
|||||||
AC_PATH_PROG(PKG_CONFIG, pkg-config, [AC_MSG_WARN([pkg-config not found.])])
|
AC_PATH_PROG(PKG_CONFIG, pkg-config, [AC_MSG_WARN([pkg-config not found.])])
|
||||||
if test x"$WITH_NFC" = "x0"; then
|
if test x"$WITH_NFC" = "x0"; then
|
||||||
if test x"$PKG_CONFIG" != "x"; then
|
if test x"$PKG_CONFIG" != "x"; then
|
||||||
LIBNFC_REQUIRED_VERSION=1.5.0
|
LIBNFC_REQUIRED_VERSION=1.5.1
|
||||||
PKG_CHECK_MODULES([LIBNFC], [libnfc >= $LIBNFC_REQUIRED_VERSION], [WITH_NFC=1], [WITH_NFC=0])
|
PKG_CHECK_MODULES([LIBNFC], [libnfc >= $LIBNFC_REQUIRED_VERSION], [WITH_NFC=1], [WITH_NFC=0])
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -262,7 +262,7 @@ uint32_t mfcuk_verify_key_block(nfc_device_t* pnd, uint32_t uiUID, uint64_t ui64
|
|||||||
nfc_configure (pnd, NDO_EASY_FRAMING, false);
|
nfc_configure (pnd, NDO_EASY_FRAMING, false);
|
||||||
|
|
||||||
// Request plain tag-nonce
|
// Request plain tag-nonce
|
||||||
if (!nfc_initiator_transceive_bytes(pnd,abtAuth,4,abtRx,&szRx))
|
if (!nfc_initiator_transceive_bytes(pnd,abtAuth,4,abtRx,&szRx, NULL))
|
||||||
{
|
{
|
||||||
return MFCUK_FAIL_COMM;
|
return MFCUK_FAIL_COMM;
|
||||||
}
|
}
|
||||||
@ -414,7 +414,7 @@ uint32_t mfcuk_key_recovery_block(nfc_device_t* pnd, uint32_t uiUID, uint64_t ui
|
|||||||
|
|
||||||
// Request plain tag-nonce
|
// Request plain tag-nonce
|
||||||
//printf("Nt: ");
|
//printf("Nt: ");
|
||||||
if (!nfc_initiator_transceive_bytes(pnd,abtAuth,4,abtRx,&szRx))
|
if (!nfc_initiator_transceive_bytes(pnd,abtAuth,4,abtRx,&szRx, NULL))
|
||||||
{
|
{
|
||||||
//printf("\n\nFAILURE - Failed to get TAG NONCE!!!\n\n");
|
//printf("\n\nFAILURE - Failed to get TAG NONCE!!!\n\n");
|
||||||
return MFCUK_FAIL_COMM;
|
return MFCUK_FAIL_COMM;
|
||||||
|
|||||||
109
src/mifare.c
109
src/mifare.c
@ -1,3 +1,33 @@
|
|||||||
|
/*-
|
||||||
|
* Public platform independent Near Field Communication (NFC) library examples
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009, Roel Verdult
|
||||||
|
* Copyright (C) 2010, Romuald Conty, Romain Tartière
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* 1) Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2 )Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* Note that this license only applies on the examples, NFC library itself is under LGPL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "mifare.h"
|
#include "mifare.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -17,69 +47,84 @@
|
|||||||
* After a successful authentication it will be possible to execute other commands (e.g. Read/Write).
|
* 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.
|
* 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)
|
bool
|
||||||
|
nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp)
|
||||||
{
|
{
|
||||||
byte_t abtRx[265];
|
byte_t abtRx[265];
|
||||||
size_t szRxLen;
|
size_t szRx = sizeof(abtRx);
|
||||||
size_t szParamLen;
|
size_t szParamLen;
|
||||||
byte_t abtCmd[265];
|
byte_t abtCmd[265];
|
||||||
|
bool bEasyFraming;
|
||||||
|
|
||||||
// Make sure we are dealing with a active device
|
abtCmd[0] = mc; // The MIFARE Classic command
|
||||||
if (pnd == NULL) return false;
|
abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
|
||||||
|
|
||||||
abtCmd[0] = mc; // The MIFARE Classic command
|
switch (mc) {
|
||||||
abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
|
|
||||||
|
|
||||||
switch (mc)
|
|
||||||
{
|
|
||||||
// Read and store command have no parameter
|
// Read and store command have no parameter
|
||||||
case MC_READ:
|
case MC_READ:
|
||||||
case MC_STORE:
|
case MC_STORE:
|
||||||
szParamLen = 0;
|
szParamLen = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Authenticate command
|
// Authenticate command
|
||||||
case MC_AUTH_A:
|
case MC_AUTH_A:
|
||||||
case MC_AUTH_B:
|
case MC_AUTH_B:
|
||||||
szParamLen = sizeof(mifare_param_auth);
|
szParamLen = sizeof (mifare_param_auth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Data command
|
// Data command
|
||||||
case MC_WRITE:
|
case MC_WRITE:
|
||||||
szParamLen = sizeof(mifare_param_data);
|
szParamLen = sizeof (mifare_param_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Value command
|
// Value command
|
||||||
case MC_DECREMENT:
|
case MC_DECREMENT:
|
||||||
case MC_INCREMENT:
|
case MC_INCREMENT:
|
||||||
case MC_TRANSFER:
|
case MC_TRANSFER:
|
||||||
szParamLen = sizeof(mifare_param_value);
|
szParamLen = sizeof (mifare_param_value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Please fix your code, you never should reach this statement
|
// Please fix your code, you never should reach this statement
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When available, copy the parameter bytes
|
// When available, copy the parameter bytes
|
||||||
if (szParamLen) memcpy(abtCmd+2,(byte_t*)pmp,szParamLen);
|
if (szParamLen)
|
||||||
|
memcpy (abtCmd + 2, (byte_t *) pmp, szParamLen);
|
||||||
|
|
||||||
|
bEasyFraming = pnd->bEasyFraming;
|
||||||
|
if (!nfc_configure (pnd, NDO_EASY_FRAMING, true)) {
|
||||||
|
nfc_perror (pnd, "nfc_configure");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Fire the mifare command
|
// Fire the mifare command
|
||||||
if (!nfc_initiator_transceive_bytes(pnd,abtCmd,2+szParamLen,abtRx,&szRxLen)) {
|
if (!nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRx, NULL)) {
|
||||||
nfc_perror (pnd, "nfc_initiator_transceive_bytes");
|
if (pnd->iLastError == EINVRXFRAM) {
|
||||||
|
// "Invalid received frame" AKA EINVRXFRAM, usual means we are
|
||||||
|
// authenticated on a sector but the requested MIFARE cmd (read, write)
|
||||||
|
// is not permitted by current acces bytes;
|
||||||
|
// So there is nothing to do here.
|
||||||
|
} else {
|
||||||
|
nfc_perror (pnd, "nfc_initiator_transceive_bytes");
|
||||||
|
}
|
||||||
|
nfc_configure (pnd, NDO_EASY_FRAMING, bEasyFraming);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!nfc_configure (pnd, NDO_EASY_FRAMING, bEasyFraming)) {
|
||||||
|
nfc_perror (pnd, "nfc_configure");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When we have executed a read command, copy the received bytes into the param
|
// When we have executed a read command, copy the received bytes into the param
|
||||||
if (mc == MC_READ) {
|
if (mc == MC_READ) {
|
||||||
if(szRxLen == 16) {
|
if (szRx == 16) {
|
||||||
memcpy(pmp->mpd.abtData,abtRx,16);
|
memcpy (pmp->mpd.abtData, abtRx, 16);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command succesfully executed
|
// Command succesfully executed
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user