Introduce experimental FeliCa Lite API.
This commit is contained in:
parent
4016405214
commit
6049acaf5a
15 changed files with 726 additions and 21 deletions
|
|
@ -11,6 +11,7 @@ TESTS = run-test.sh
|
|||
TESTS_ENVIRONMENT = NO_MAKE=yes CUTTER="$(CUTTER)"
|
||||
|
||||
cutter_unit_test_libs = \
|
||||
test_felica.la \
|
||||
test_mad.la \
|
||||
test_mifare_application.la \
|
||||
test_mifare_classic.la \
|
||||
|
|
@ -33,6 +34,11 @@ endif
|
|||
|
||||
AM_LDFLAGS = -module -rpath $(libdir) -avoid-version -no-undefined
|
||||
|
||||
test_felica_la_SOURCES = test_felica.c \
|
||||
felica_fixture.c \
|
||||
felica_fixture.h
|
||||
test_felica_la_LIBADD = $(top_builddir)/libfreefare/libfreefare.la
|
||||
|
||||
test_mad_la_SOURCES = test_mad.c
|
||||
test_mad_la_LIBADD = $(top_builddir)/libfreefare/libfreefare.la
|
||||
|
||||
|
|
|
|||
82
test/felica_fixture.c
Normal file
82
test/felica_fixture.c
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/*-
|
||||
* Copyright (C) 2015, Romain Tartiere
|
||||
*
|
||||
* 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/>
|
||||
*/
|
||||
|
||||
#include <cutter.h>
|
||||
#include <freefare.h>
|
||||
|
||||
#include "felica_fixture.h"
|
||||
|
||||
static nfc_context *context;
|
||||
static nfc_device *device = NULL;
|
||||
static FreefareTag *tags = NULL;
|
||||
FreefareTag tag = NULL;
|
||||
|
||||
void
|
||||
cut_setup (void)
|
||||
{
|
||||
int res;
|
||||
nfc_connstring devices[8];
|
||||
size_t device_count;
|
||||
|
||||
nfc_init (&context);
|
||||
cut_assert_not_null (context, cut_message ("Unable to init libnfc (malloc)"));
|
||||
|
||||
device_count = nfc_list_devices (context, devices, 8);
|
||||
if (device_count <= 0)
|
||||
cut_omit ("No device found");
|
||||
|
||||
for (size_t i = 0; i < device_count; i++) {
|
||||
device = nfc_open (context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit ("nfc_open() failed.");
|
||||
|
||||
tags = freefare_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
|
||||
|
||||
tag = NULL;
|
||||
for (int i=0; tags[i]; i++) {
|
||||
if (freefare_get_tag_type(tags[i]) == FELICA) {
|
||||
tag = tags[i];
|
||||
res = felica_connect (tag);
|
||||
cut_assert_equal_int (0, res, cut_message ("felica_connect() failed"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
nfc_close (device);
|
||||
device = NULL;
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
}
|
||||
cut_omit ("No FeliCa tag on NFC device");
|
||||
}
|
||||
|
||||
void
|
||||
cut_teardown (void)
|
||||
{
|
||||
if (tag)
|
||||
mifare_classic_disconnect (tag);
|
||||
|
||||
if (tags) {
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
}
|
||||
|
||||
if (device)
|
||||
nfc_close (device);
|
||||
|
||||
nfc_exit (context);
|
||||
}
|
||||
18
test/felica_fixture.h
Normal file
18
test/felica_fixture.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/*-
|
||||
* Copyright (C) 2015, Romain Tartiere.
|
||||
*
|
||||
* 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/>
|
||||
*/
|
||||
|
||||
extern FreefareTag tag;
|
||||
38
test/test_felica.c
Normal file
38
test/test_felica.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include <cutter.h>
|
||||
|
||||
#include <freefare.h>
|
||||
|
||||
#include "felica_fixture.h"
|
||||
|
||||
void
|
||||
test_felica_read_without_encryption (void)
|
||||
{
|
||||
uint8_t buffer[64];
|
||||
|
||||
int res = felica_read (tag, FELICA_SC_RO, 0x00, buffer, 16);
|
||||
cut_assert_equal_int (16, res);
|
||||
|
||||
uint8_t blocks[] = {
|
||||
0x02,
|
||||
0x03,
|
||||
0x04,
|
||||
};
|
||||
|
||||
res = felica_read_ex (tag, FELICA_SC_RO, 3, blocks, buffer, 3 * 16);
|
||||
cut_assert_equal_int (3 * 16, res);
|
||||
}
|
||||
|
||||
void
|
||||
test_felica_write_without_encryption (void)
|
||||
{
|
||||
uint8_t buffer[16] = {
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x03, 0x04, 0x05, 0x06,
|
||||
0x07, 0x08, 0x09, 0x0a,
|
||||
0x0b, 0x0c, 0x0d, 0x0e,
|
||||
};
|
||||
|
||||
int res = felica_write (tag, FELICA_SC_RW, 0x0a, buffer, sizeof (buffer));
|
||||
|
||||
cut_assert_equal_int (0, res);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue