Skip to content

Commit

Permalink
Update to use libnfc 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
neomilium committed Nov 10, 2011
1 parent 06d5d78 commit f95ec4b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 73 deletions.
7 changes: 5 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT(nfc-eventd, 0.1.4, rconty@il4p.fr)
AC_INIT(nfc-eventd, 0.1.5, rconty@il4p.fr)

AC_CONFIG_HEADER(config.h)

Expand Down Expand Up @@ -71,7 +71,7 @@ AC_MSG_RESULT($enable_dbus)
AC_PATH_PROG(PKG_CONFIG, pkg-config, [AC_MSG_ERROR([pkg-config not found.])])

## libnfc
LIBNFC_REQUIRED_VERSION="1.4.0"
LIBNFC_REQUIRED_VERSION="1.5.1"
PKG_CHECK_MODULES([LIBNFC], [libnfc >= $LIBNFC_REQUIRED_VERSION], [], [AC_MSG_ERROR([libnfc >= $LIBNFC_REQUIRED_VERSION is mandatory.])])

AC_SUBST(LIBNFC_LIBS)
Expand All @@ -96,6 +96,9 @@ LIBNFCCONF="\${top_builddir}/src/nfcconf/libnfcconf.la"
# Set C standard to C99
CFLAGS="$CFLAGS -std=c99"

# Help us to write great code ;-)
CFLAGS="$CFLAGS -Wall -pedantic -Wextra"

nemdir="\${pkglibdir}/modules"
AC_SUBST(nemdir)

Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
nfc-eventd (0.1.5-0) unstable; urgency=low

* New upstream release

-- Romuald Conty <rconty@il4p.fr> Thu, 10 Nov 2011 11:42:42 +0100

nfc-eventd (0.1.1-0) unstable; urgency=low

* New upstream release
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Homepage: http://code.google.com/p/nfc-tools/

Package: nfc-eventd
Architecture: any
Depends: ${shlibs:Depends}, libnfc0 (>= 1.2.1), libdbus-1-3, libdbus-glib-1-2
Depends: ${shlibs:Depends}, libnfc2 (>= 1.5.1), libdbus-1-3, libdbus-glib-1-2
Description: NFC event daemon
nfc-eventd is a daemon that looks for tags insertions/removes from NFC device.
It is provided with two NEM (Nfc Eventd Modules) which allow many kind of
Expand Down
2 changes: 2 additions & 0 deletions src/debug/nfc-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose)
print_hex (nfi.abtId, 8);
printf (" Parameter (PAD): ");
print_hex (nfi.abtPad, 8);
printf (" System Code (SC): ");
print_hex (nfi.abtSysCode, 2);
}

void
Expand Down
25 changes: 8 additions & 17 deletions src/modules/nem_dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,19 @@ static nfcconf_block* _nem_dbus_config_block;
static char * _tag_uid = NULL;

void
tag_get_uid(const nfc_device_t* nfc_device, const nfc_target_t* tag, char **dest) {
tag_get_uid(nfc_device_t* nfc_device, const nfc_target_t* tag, char **dest) {
DBG("tag_get_uid(%08x, %08x, %08x)", nfc_device, tag, dest);

nfc_target_info_t ti;
nfc_target_t target;
debug_print_tag(tag);
/// @TODO We don't need to reselect tag to get his UID: nfc_target_t contains this data.
// Poll for a ISO14443A (MIFARE) tag
if ( nfc_initiator_select_passive_target ( nfc_device, tag->modulation, tag->ti.nai.abtUid, tag->ti.nai.szUidLen, &ti ) ) {
/*
printf ( "The following (NFC) ISO14443A tag was found:\n\n" );
printf ( " ATQA (SENS_RES): " ); print_hex ( ti.nai.abtAtqa,2 );
printf ( " UID (NFCID%c): ", ( ti.nai.abtUid[0]==0x08?'3':'1' ) ); print_hex ( ti.nai.abtUid,ti.nai.szUidLen );
printf ( " SAK (SEL_RES): " ); print_hex ( &ti.nai.btSak,1 );
if ( ti.nai.uiAtsLen )
{
printf ( " ATS (ATR): " );
print_hex ( ti.nai.abtAts,ti.nai.uiAtsLen );
}
*/
*dest = malloc(ti.nai.szUidLen*sizeof(char));
if ( nfc_initiator_select_passive_target ( nfc_device, tag->nm, tag->nti.nai.abtUid, tag->nti.nai.szUidLen, &target ) ) {
*dest = malloc(target.nti.nai.szUidLen*sizeof(char));
size_t szPos;
char *pcUid = *dest;
for (szPos=0; szPos < ti.nai.szUidLen; szPos++) {
sprintf(pcUid, "%02x",ti.nai.abtUid[szPos]);
for (szPos=0; szPos < target.nti.nai.szUidLen; szPos++) {
sprintf(pcUid, "%02x",target.nti.nai.abtUid[szPos]);
pcUid += 2;
}
pcUid[0]='\0';
Expand Down Expand Up @@ -127,6 +116,7 @@ gboolean nfc_object_emit_hello_signal (NfcObject *obj, GError **error);
static void
nfc_object_init (NfcObject *obj)
{
(void) obj;
}

static void
Expand All @@ -153,6 +143,7 @@ nfc_object_class_init (NfcObjectClass *klass)
gboolean
nfc_object_emit_hello_signal (NfcObject *obj, GError **error)
{
(void) error;
g_signal_emit (obj, signals[TAG_INSERTED], 0, "deadbeef");
return TRUE;
}
Expand Down
78 changes: 25 additions & 53 deletions src/nfc-eventd.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,62 +304,34 @@ typedef enum {
nfc_target_t*
ned_poll_for_tag(nfc_device_t* nfc_device, nfc_target_t* tag)
{
static nfc_poll_mode mode = NFC_POLL_SOFTWARE;

/*
// With libnfc 1.6 serie, we could not check the internal chip any more.
// BTW, "Capabilities" have to be introduced in libnfc, once it will be available we could switch again to a conditional statement
// http://code.google.com/p/libnfc/issues/detail?id=165
if((mode == NFC_POLL_HARDWARE) && (nfc_device->nc == NC_PN531)) {
DBG("%s doesn't support hardware polling, falling back to software polling", nfc_device->acName);
mode = NFC_POLL_SOFTWARE;
uint8_t uiPollNr;
const uint8_t uiPeriod = 2; /* 2 x 150 ms = 300 ms */
const nfc_modulation_t nm[1] = { { .nmt = NMT_ISO14443A, .nbr = NBR_106 } };

if( tag != NULL ) {
/* We are looking for a previous tag */
/* In this case, to prevent for intensive polling we add a sleeping time */
sleep ( polling_time );
uiPollNr = 3; /* Polling duration : btPollNr * szTargetTypes * btPeriod * 150 = btPollNr * 300 = 900 */
} else {
/* We are looking for any tag */
uiPollNr = 0xff; /* We endless poll for a new tag */
}
*/

switch(mode) {
case NFC_POLL_SOFTWARE:
sleep ( polling_time );
return ned_select_tag(nfc_device, tag);
break;
case NFC_POLL_HARDWARE: {
byte_t btPollNr;
const byte_t btPeriod = 2; /* 2 x 150 ms = 300 ms */
const nfc_modulation_t nm[1] = { { .nmt = NMT_ISO14443A, .nbr = NBR_106 } };

if( tag != NULL ) {
/* We are looking for a previous tag */
/* In this case, to prevent for intensive polling we add a sleeping time */
sleep ( polling_time );
btPollNr = 3; /* Polling duration : btPollNr * szTargetTypes * btPeriod * 150 = btPollNr * 300 = 900 */
} else {
/* We are looking for any tag */
btPollNr = 0xff; /* We endless poll for a new tag */
}
nfc_target_t antTargets[2];
size_t szTargetFound;

bool res = nfc_initiator_poll_targets (nfc_device, nm, 1, btPollNr, btPeriod, antTargets, &szTargetFound);
if (res) {
DBG ("%ld target(s) have been found.\n", (unsigned long) szTargetFound);
if( szTargetFound < 1 ) {
return NULL;
} else {
if ( (tag != NULL) && (0 == memcmp(tag->nti.nai.abtUid, antTargets[0].nti.nai.abtUid, antTargets[0].nti.nai.szUidLen)) ) {
return tag;
} else {
nfc_target_t* rv = malloc(sizeof(nfc_target_t));
memcpy(rv, &antTargets[0], sizeof(nfc_target_t));
nfc_initiator_deselect_target ( nfc_device );
return rv;
}
}
} else {
ERR ("%s", "Polling failed.");
}

nfc_target_t target;
bool res = nfc_initiator_poll_target (nfc_device, nm, 1, uiPollNr, uiPeriod, &target);
if (res) {
if ( (tag != NULL) && (0 == memcmp(tag->nti.nai.abtUid, target.nti.nai.abtUid, target.nti.nai.szUidLen)) ) {
return tag;
} else {
nfc_target_t* rv = malloc(sizeof(nfc_target_t));
memcpy(rv, &target, sizeof(nfc_target_t));
nfc_initiator_deselect_target ( nfc_device );
return rv;
}
break;
} else {
return NULL;
}
return NULL;
}

int
Expand Down

0 comments on commit f95ec4b

Please sign in to comment.