2011-10-03 11:19:08 +00:00
|
|
|
/*-
|
|
|
|
* Public platform independent Near Field Communication (NFC) library
|
2012-05-29 00:33:22 +00:00
|
|
|
*
|
2012-10-21 14:11:38 +00:00
|
|
|
* Copyright (C) 2011, 2012 Romuald Conty
|
2012-05-29 00:33:22 +00:00
|
|
|
*
|
2011-10-03 11:19:08 +00:00
|
|
|
* 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.
|
2012-05-29 00:33:22 +00:00
|
|
|
*
|
2011-10-03 11:19:08 +00:00
|
|
|
* 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/>
|
|
|
|
*/
|
|
|
|
|
2012-05-29 15:52:51 +00:00
|
|
|
/**
|
|
|
|
* @file nfc-internal.c
|
|
|
|
* @brief Provide some useful internal functions
|
|
|
|
*/
|
2011-10-03 11:19:08 +00:00
|
|
|
|
|
|
|
#include <nfc/nfc.h>
|
2012-05-13 13:01:06 +00:00
|
|
|
#include "nfc-internal.h"
|
2011-10-03 11:19:08 +00:00
|
|
|
|
2012-10-21 14:11:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static bool
|
|
|
|
string_as_boolean(const char* s)
|
|
|
|
{
|
|
|
|
if ((s) && (
|
|
|
|
(strcmp(s, "yes") == 0) ||
|
|
|
|
(strcmp(s, "true") == 0) ||
|
|
|
|
(strcmp(s, "1") == 0))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nfc_context *
|
|
|
|
nfc_context_new(void)
|
|
|
|
{
|
|
|
|
nfc_context *res = malloc(sizeof(*res));
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
err(EXIT_FAILURE, "nfc_context_new: malloc");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load "intrusive scan" option
|
|
|
|
// XXX: Load this option from configuration file too ?
|
|
|
|
char *envvar = getenv("LIBNFC_INTRUSIVE_SCAN");
|
|
|
|
res->allow_intrusive_scan = string_as_boolean(envvar);
|
|
|
|
log_put ("libnfc", NFC_PRIORITY_DEBUG, "allow_intrusive_scan is set to %s", (res->allow_intrusive_scan)?"true":"false");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfc_context_free(nfc_context *context)
|
|
|
|
{
|
|
|
|
free(context);
|
|
|
|
}
|
|
|
|
|
2012-05-29 00:33:22 +00:00
|
|
|
void
|
2012-05-29 15:55:35 +00:00
|
|
|
prepare_initiator_data(const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t *pszInitiatorData)
|
2011-10-03 11:19:08 +00:00
|
|
|
{
|
|
|
|
switch (nm.nmt) {
|
|
|
|
case NMT_ISO14443B: {
|
|
|
|
// Application Family Identifier (AFI) must equals 0x00 in order to wakeup all ISO14443-B PICCs (see ISO/IEC 14443-3)
|
2011-11-24 10:54:42 +00:00
|
|
|
*ppbtInitiatorData = (uint8_t *) "\x00";
|
2011-10-03 11:19:08 +00:00
|
|
|
*pszInitiatorData = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NMT_ISO14443BI: {
|
|
|
|
// APGEN
|
2011-11-24 10:54:42 +00:00
|
|
|
*ppbtInitiatorData = (uint8_t *) "\x01\x0b\x3f\x80";
|
2011-10-03 11:19:08 +00:00
|
|
|
*pszInitiatorData = 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NMT_ISO14443B2SR: {
|
|
|
|
// Get_UID
|
2011-11-24 10:54:42 +00:00
|
|
|
*ppbtInitiatorData = (uint8_t *) "\x0b";
|
2011-10-03 11:19:08 +00:00
|
|
|
*pszInitiatorData = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NMT_ISO14443B2CT: {
|
|
|
|
// SELECT-ALL
|
2011-11-24 10:54:42 +00:00
|
|
|
*ppbtInitiatorData = (uint8_t *) "\x9F\xFF\xFF";
|
2011-10-03 11:19:08 +00:00
|
|
|
*pszInitiatorData = 3;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NMT_FELICA: {
|
|
|
|
// polling payload must be present (see ISO/IEC 18092 11.2.2.5)
|
2011-11-24 10:54:42 +00:00
|
|
|
*ppbtInitiatorData = (uint8_t *) "\x00\xff\xff\x01\x00";
|
2011-10-03 11:19:08 +00:00
|
|
|
*pszInitiatorData = 5;
|
|
|
|
}
|
|
|
|
break;
|
2012-05-16 18:08:42 +00:00
|
|
|
case NMT_ISO14443A:
|
|
|
|
case NMT_JEWEL:
|
|
|
|
case NMT_DEP:
|
2011-10-03 11:19:08 +00:00
|
|
|
*ppbtInitiatorData = NULL;
|
|
|
|
*pszInitiatorData = 0;
|
2012-05-29 15:52:51 +00:00
|
|
|
break;
|
2011-10-03 11:19:08 +00:00
|
|
|
}
|
|
|
|
}
|