Merge r499-510 from trunk.

This commit is contained in:
Romain Tartiere 2010-08-10 21:14:13 +00:00
commit dfb82f8893
15 changed files with 94 additions and 86 deletions

View file

@ -2,9 +2,9 @@
#include <string.h>
#include "chips/pn53x.h"
#include <nfc/nfc.h>
extern const byte_t pncmd_initiator_exchange_data [265];
#include "chips/pn53x.h"
/**
* @brief Execute a MIFARE Classic Command
@ -24,15 +24,13 @@ bool nfc_initiator_mifare_cmd(nfc_device_t* pnd, const mifare_cmd mc, const uint
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szParamLen;
byte_t abtCmd[sizeof(pncmd_initiator_exchange_data)];
memcpy(abtCmd,pncmd_initiator_exchange_data,sizeof(pncmd_initiator_exchange_data));
byte_t abtCmd[265];
// Make sure we are dealing with a active device
if (!pnd->bActive) return false;
abtCmd[2] = 0x01; // Use first target/card
abtCmd[3] = mc; // The MIFARE Classic command
abtCmd[4] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
abtCmd[0] = mc; // The MIFARE Classic command
abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
switch (mc)
{
@ -67,10 +65,10 @@ bool nfc_initiator_mifare_cmd(nfc_device_t* pnd, const mifare_cmd mc, const uint
}
// When available, copy the parameter bytes
if (szParamLen) memcpy(abtCmd+5,(byte_t*)pmp,szParamLen);
if (szParamLen) memcpy(abtCmd+2,(byte_t*)pmp,szParamLen);
// Fire the mifare command
if (!pn53x_transceive(pnd,abtCmd,5+szParamLen,abtRx,&szRxLen)) return false;
if (!nfc_initiator_transceive_dep_bytes(pnd,abtCmd,2+szParamLen,abtRx,&szRxLen)) return false;
// When we have executed a read command, copy the received bytes into the param
if (mc == MC_READ && szRxLen == 17) memcpy(pmp->mpd.abtData,abtRx+1,16);

View file

@ -56,12 +56,13 @@ int main(int argc, const char* argv[])
size_t szTargetFound;
size_t i;
nfc_target_info_t nti;
nfc_device_desc_t *pnddDevices;
// Display libnfc version
acLibnfcVersion = nfc_version();
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion);
nfc_device_desc_t *pnddDevices = parse_device_desc(argc, argv, &szDeviceFound);
pnddDevices = parse_device_desc(argc, argv, &szDeviceFound);
if (argc > 1 && szDeviceFound == 0) {
errx (1, "usage: %s [--device driver:port:speed]", argv[0]);
@ -106,6 +107,7 @@ int main(int argc, const char* argv[])
for (i = 0; i < szDeviceFound; i++)
{
nfc_target_info_t anti[MAX_TARGET_COUNT];
pnd = nfc_connect(&(pnddDevices[i]));
@ -131,10 +133,10 @@ int main(int argc, const char* argv[])
printf("Connected to NFC reader: %s\n",pnd->acName);
nfc_target_info_t anti[MAX_TARGET_COUNT];
if (nfc_initiator_list_passive_targets(pnd, NM_ISO14443A_106, anti, MAX_TARGET_COUNT, &szTargetFound )) {
size_t n;
printf("%zu ISO14443A passive targets was found:\n", szTargetFound);
for(size_t n=0; n<szTargetFound; n++) {
for(n=0; n<szTargetFound; n++) {
print_nfc_iso14443a_info (anti[n].nai);
printf("\n");
}

View file

@ -94,9 +94,11 @@ write_card (void)
uint32_t uiWritenPages = 0;
char buffer[BUFSIZ];
bool write_otp;
printf ("Write OTP bytes ? [yN] ");
fgets (buffer, BUFSIZ, stdin);
bool write_otp = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
write_otp = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
/* We need to skip 3 first pages. */
printf ("Writing %d pages |", uiBlocks + 1);

View file

@ -69,8 +69,17 @@ main (int argc, const char *argv[])
}
for (i = 0; i < szFound; i++) {
pnd = nfc_connect (&(pnddDevices[i]));
const byte_t btPollNr = 20;
const byte_t btPeriod = 2;
const nfc_target_type_t nttMifare = NTT_MIFARE;
const size_t szTargetTypes = 1;
nfc_target_t antTargets[2];
size_t szTargetFound;
bool res;
pnd = nfc_connect (&(pnddDevices[i]));
if (pnd == NULL) {
ERR ("%s", "Unable to connect to NFC device.");
@ -100,24 +109,17 @@ main (int argc, const char *argv[])
// bool (*transceive)(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
const byte_t btPollNr = 20;
const byte_t btPeriod = 2;
const nfc_target_type_t nttMifare = NTT_MIFARE;
const size_t szTargetTypes = 1;
nfc_target_t antTargets[2];
size_t szTargetFound;
if (pnd->nc == NC_PN531) {
// PN531 doesn't support hardware polling (InAutoPoll)
WARN ("%s", "PN531 doesn't support hardware polling.");
continue;
}
printf ("PN53x will poll during %ld ms\n", (unsigned long) btPollNr * szTargetTypes * btPeriod * 150);
bool res = nfc_initiator_poll_targets (pnd, &nttMifare, 1, btPollNr, btPeriod, antTargets, &szTargetFound);
res = nfc_initiator_poll_targets (pnd, &nttMifare, 1, btPollNr, btPeriod, antTargets, &szTargetFound);
if (res) {
uint8_t n;
printf ("%ld target(s) have been found.\n", (unsigned long) szTargetFound);
for (uint8_t n = 0; n < szTargetFound; n++) {
for (n = 0; n < szTargetFound; n++) {
printf ("T%d: targetType=%02x, ", n + 1, antTargets[n].ntt);
printf ("targetData:\n");
print_nfc_iso14443a_info (antTargets[n].nti.nai);

View file

@ -102,8 +102,8 @@ void print_nfc_iso14443a_info(const nfc_iso14443a_info_t nai)
nfc_device_desc_t* parse_device_desc(int argc, const char *argv[], size_t* szFound)
{
nfc_device_desc_t* pndd = 0;
*szFound = 0;
int arg;
*szFound = 0;
// Get commandline options
for (arg=1;arg<argc;arg++) {
@ -111,10 +111,10 @@ nfc_device_desc_t* parse_device_desc(int argc, const char *argv[], size_t* szFou
if (0 == strcmp(argv[arg], "--device")) {
if (argc > arg+1) {
char buffer[256];
pndd = malloc(sizeof(nfc_device_desc_t));
char buffer[256];
strncpy(buffer, argv[++arg], 256);
// Driver.