Added draft of a new libnfc-based example: nfc-sam.
It tests the comunication with a connected SAM (Secure Access Module).
This commit is contained in:
parent
ec48f04dd8
commit
8e4bef9c90
4 changed files with 161 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
SET(EXAMPLES-SOURCES nfc-list nfc-mfclassic nfc-mfultralight nfcip-initiator nfcip-target nfc-anticol nfc-emulate nfc-relay)
|
||||
SET(EXAMPLES-SOURCES nfc-list nfc-mfclassic nfc-mfultralight nfcip-initiator nfcip-target nfc-anticol nfc-emulate nfc-relay nfc-sam)
|
||||
|
||||
# XXX: Examples should not use private API!
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libnfc)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
bin_PROGRAMS = nfc-anticol nfc-list nfc-mfclassic nfc-mfultralight nfc-relay nfc-emulate nfcip-target nfcip-initiator nfc-poll pn53x-diagnose
|
||||
bin_PROGRAMS = nfc-anticol nfc-list nfc-mfclassic nfc-mfultralight nfc-relay nfc-emulate nfcip-target nfcip-initiator nfc-poll pn53x-diagnose nfc-sam
|
||||
|
||||
# set the include path found by configure
|
||||
INCLUDES= $(all_includes) $(LIBNFC_CFLAGS)
|
||||
|
@ -46,6 +46,10 @@ pn53x_diagnose_SOURCES = pn53x-diagnose.c
|
|||
pn53x_diagnose_LDADD = $(top_builddir)/libnfc/libnfc.la \
|
||||
libnfcutils.la
|
||||
|
||||
dist_man_MANS = nfc-anticol.1 nfc-emulate.1 nfc-list.1 nfc-mfclassic.1 nfc-mfultralight.1 nfc-relay.1
|
||||
nfc_sam_SOURCES = nfc-sam.c
|
||||
nfc_sam_LDADD = $(top_builddir)/libnfc/libnfc.la \
|
||||
libnfcutils.la
|
||||
|
||||
dist_man_MANS = nfc-anticol.1 nfc-emulate.1 nfc-list.1 nfc-mfclassic.1 nfc-mfultralight.1 nfc-relay.1 nfc-sam.1
|
||||
|
||||
EXTRA_DIST = CMakeLists.txt
|
||||
|
|
24
examples/nfc-sam.1
Executable file
24
examples/nfc-sam.1
Executable file
|
@ -0,0 +1,24 @@
|
|||
.TH NFC-SAM 1 "June 15, 2010"
|
||||
.SH NAME
|
||||
nfc-sam \- NFC SAM comunication command line tool based on libnfc
|
||||
.SH SYNOPSIS
|
||||
.B nfc-sam
|
||||
.SH DESCRIPTION
|
||||
.B nfc-sam
|
||||
utility attempts to test a simple connection with a SAM (Secure Access Module) in several modes.
|
||||
|
||||
.SH BUGS
|
||||
Please report any bugs on the
|
||||
.B libnfc
|
||||
forum at
|
||||
.BR http://www.libnfc.org/community/ "."
|
||||
.SH LICENCE
|
||||
.B libnfc
|
||||
and
|
||||
.B nfc-tools
|
||||
are covered by the GNU Lesser General Public License (LGPL), version 3.
|
||||
.SH AUTHORS
|
||||
Roel Verdult <roel@libnfc.org>
|
||||
.PP
|
||||
This manual page was written by Emanuele Bertoldi <zuck@fastwebnet.it>.
|
||||
It is licensed under the terms of the GNU GPL (version 2 or later).
|
130
examples/nfc-sam.c
Executable file
130
examples/nfc-sam.c
Executable file
|
@ -0,0 +1,130 @@
|
|||
/*-
|
||||
* Public platform independent Near Field Communication (NFC) library
|
||||
*
|
||||
* Copyright (C) 2009, Roel Verdult
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file nfc-sam.c
|
||||
* @brief Configure the reader to comunicate with a SAM (Secure Access Module).
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "nfc-utils.h"
|
||||
|
||||
#define MAX_FRAME_LEN 264
|
||||
|
||||
#define VIRTUAL_CARD_MODE 2
|
||||
#define WIRED_CARD_MODE 3
|
||||
#define DUAL_CARD_MODE 4
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
nfc_device_t* pnd;
|
||||
|
||||
byte_t abtRx[MAX_FRAME_LEN];
|
||||
size_t szRxLen;
|
||||
|
||||
byte_t abtSAMConfig[] = { 0xD4,0x14,0x00,0x00 };
|
||||
|
||||
nfc_target_info_t nti;
|
||||
|
||||
// Display libnfc version
|
||||
const char* acLibnfcVersion = nfc_version();
|
||||
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
|
||||
// Connect using the first available NFC device
|
||||
pnd = nfc_connect(NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
printf("Unable to connect to NFC device.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Set connected NFC device to initiator mode
|
||||
nfc_initiator_init(pnd);
|
||||
|
||||
// Drop the field for a while
|
||||
nfc_configure(pnd,NDO_ACTIVATE_FIELD,false);
|
||||
|
||||
// Configure the CRC and Parity settings
|
||||
nfc_configure(pnd,NDO_HANDLE_CRC,false);
|
||||
nfc_configure(pnd,NDO_HANDLE_PARITY,true);
|
||||
|
||||
// Enable field so more power consuming cards can power themselves up
|
||||
nfc_configure(pnd,NDO_ACTIVATE_FIELD,true);
|
||||
|
||||
printf("Connected to NFC reader: %s\n",pnd->acName);
|
||||
|
||||
// Print the example's menu.
|
||||
printf("\nSelect the comunication mode:\n");
|
||||
printf("[1] Virtual card mode.\n");
|
||||
printf("[2] Wired card mode.\n");
|
||||
printf("[3] Dual card mode.\n");
|
||||
printf(">> ");
|
||||
|
||||
// Take user's choice.
|
||||
char input = getchar();
|
||||
int mode = input-'0'+1;
|
||||
printf("\n");
|
||||
if (mode <= 1 || mode >= 5)
|
||||
return 1;
|
||||
|
||||
abtSAMConfig[2] = mode;
|
||||
|
||||
// Connect with the SAM.
|
||||
pnd->pdc->transceive(pnd->nds,abtSAMConfig,sizeof(abtSAMConfig),abtRx,&szRxLen);
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case VIRTUAL_CARD_MODE:
|
||||
{
|
||||
printf("Now the SAM is readable from an external reader.\n");
|
||||
// TODO.
|
||||
}
|
||||
break;
|
||||
|
||||
case WIRED_CARD_MODE:
|
||||
{
|
||||
// Read the SAM's ATS (ATR).
|
||||
if (nfc_initiator_select_tag(pnd,NM_ISO14443A_106,NULL,0,&nti))
|
||||
{
|
||||
printf("The following (NFC) ISO14443A tag was found:\n\n");
|
||||
print_nfc_iso14443a_info (nti.nai);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DUAL_CARD_MODE:
|
||||
{
|
||||
// TODO.
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Disconnect from NFC device
|
||||
nfc_disconnect(pnd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Add table
Reference in a new issue