diff options
author | Jussi Laako <jussi.laako@linux.intel.com> | 2014-05-19 15:33:46 +0300 |
---|---|---|
committer | Jussi Laako <jussi.laako@linux.intel.com> | 2014-05-19 15:33:46 +0300 |
commit | 0557bb8a7f90347a3a0e49a12db0259500794d1e (patch) | |
tree | 4bb5cfc8ee3d4c1de8317af929b988de59fb2bb0 /src | |
download | libtlm-nfc-master.tar.gz libtlm-nfc-master.tar.bz2 libtlm-nfc-master.zip |
Initial package importHEADsubmit/tizen/20140519.123501master
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 17 | ||||
-rw-r--r-- | src/Makefile.in | 666 | ||||
-rw-r--r-- | src/gtlm-nfc.c | 846 | ||||
-rw-r--r-- | src/gtlm-nfc.h | 72 |
4 files changed, 1601 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..ee79084 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,17 @@ +NULL= +lib_LTLIBRARIES = libtlm-nfc.la + +libtlm_nfc_la_SOURCES = \ + gtlm-nfc.c \ + gtlm-nfc.h + +libtlm_nfc_la_CPPFLAGS = \ + -I$(top_builddir) \ + -I$(top_srcdir)/src \ + -I. \ + $(TLM_NFC_CFLAGS) \ + $(NULL) + +libtlm_nfc_la_LIBADD = \ + $(TLM_NFC_LIBS) \ + $(NULL) diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..76a549f --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,666 @@ +# Makefile.in generated by automake 1.14.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2013 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ + $(top_srcdir)/build-aux/depcomp +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/gtk-doc.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(libdir)" +LTLIBRARIES = $(lib_LTLIBRARIES) +am__DEPENDENCIES_1 = +libtlm_nfc_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_libtlm_nfc_la_OBJECTS = libtlm_nfc_la-gtlm-nfc.lo +libtlm_nfc_la_OBJECTS = $(am_libtlm_nfc_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libtlm_nfc_la_SOURCES) +DIST_SOURCES = $(libtlm_nfc_la_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CHECK_CFLAGS = @CHECK_CFLAGS@ +CHECK_LIBS = @CHECK_LIBS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +GTKDOC_CHECK = @GTKDOC_CHECK@ +GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@ +GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ +GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ +GTKDOC_MKPDF = @GTKDOC_MKPDF@ +GTKDOC_REBASE = @GTKDOC_REBASE@ +HTML_DIR = @HTML_DIR@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TLM_NFC_CFLAGS = @TLM_NFC_CFLAGS@ +TLM_NFC_LIBS = @TLM_NFC_LIBS@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +NULL = +lib_LTLIBRARIES = libtlm-nfc.la +libtlm_nfc_la_SOURCES = \ + gtlm-nfc.c \ + gtlm-nfc.h + +libtlm_nfc_la_CPPFLAGS = \ + -I$(top_builddir) \ + -I$(top_srcdir)/src \ + -I. \ + $(TLM_NFC_CFLAGS) \ + $(NULL) + +libtlm_nfc_la_LIBADD = \ + $(TLM_NFC_LIBS) \ + $(NULL) + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ + } + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +libtlm-nfc.la: $(libtlm_nfc_la_OBJECTS) $(libtlm_nfc_la_DEPENDENCIES) $(EXTRA_libtlm_nfc_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) -rpath $(libdir) $(libtlm_nfc_la_OBJECTS) $(libtlm_nfc_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtlm_nfc_la-gtlm-nfc.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +libtlm_nfc_la-gtlm-nfc.lo: gtlm-nfc.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtlm_nfc_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtlm_nfc_la-gtlm-nfc.lo -MD -MP -MF $(DEPDIR)/libtlm_nfc_la-gtlm-nfc.Tpo -c -o libtlm_nfc_la-gtlm-nfc.lo `test -f 'gtlm-nfc.c' || echo '$(srcdir)/'`gtlm-nfc.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libtlm_nfc_la-gtlm-nfc.Tpo $(DEPDIR)/libtlm_nfc_la-gtlm-nfc.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gtlm-nfc.c' object='libtlm_nfc_la-gtlm-nfc.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtlm_nfc_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtlm_nfc_la-gtlm-nfc.lo `test -f 'gtlm-nfc.c' || echo '$(srcdir)/'`gtlm-nfc.c + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(libdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-libLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool cscopelist-am ctags \ + ctags-am distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-libLTLIBRARIES install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/gtlm-nfc.c b/src/gtlm-nfc.c new file mode 100644 index 0000000..c1a20e5 --- /dev/null +++ b/src/gtlm-nfc.c @@ -0,0 +1,846 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of gtlm-nfc + * + * Copyright (C) 2013 Intel Corporation. + * + * Contact: Alexander Kanavin <alex.kanavin@gmail.com> + * + * This library 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 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "gtlm-nfc.h" +#include <gio/gio.h> + +GQuark +gtlm_nfc_error_quark (void) +{ + return g_quark_from_static_string ("gtlm-nfc"); +} + +#define GTLM_NFC_ERROR (gtlm_nfc_error_quark()) + +/** + * SECTION:gtlm-nfc + * @short_description: a helper object that provides NFC functionality to user management code + * @include: gtlm-nfc.h + * + * #GTlmNfc is used by Tizen user and login management to access NFC tags + * and authenticate users through them. It provides signals to listen for tags + * appearing and disappearing, and for reading and writing username/password pairs + * to tags. + */ +/** + * GTlmNfcError: + * @GTLM_NFC_ERROR_NONE: No error + * @GTLM_NFC_ERROR_NO_TAG: Issued when attempting to write to an absent tag + * + * This enum provides a list of errors that libtlm-nfc returns. + * + */ + +/** + * GTlmNfc: + * + * Opaque #GTlmNfc data structure. + */ +/** + * GTlmNfcClass: + * @parent_class: the parent class structure + * + * Opaque #GTlmNfcClass data structure. + */ + +G_DEFINE_TYPE_WITH_CODE (GTlmNfc, gtlm_nfc, + G_TYPE_OBJECT, + ); + +enum +{ + PROP_0 + +}; + +enum { + SIG_TAG_FOUND, + SIG_TAG_LOST, + SIG_RECORD_FOUND, + SIG_NO_RECORD_FOUND, + + SIG_MAX +}; + +static guint signals[SIG_MAX]; + + +static gchar* _encode_username_password(const gchar* username, const gchar* password) +{ + GVariant* v = g_variant_new("(msms)", username, password); + + gchar* out = g_base64_encode(g_variant_get_data(v), g_variant_get_size(v)); + g_variant_unref(v); + return out; +} + +/** + * gtlm_nfc_write_username_password: + * @tlm_nfc: an instance of GTlmNfc object + * @nfc_tag_path: an identificator of the nfc tag (returned by #GTlmNfc::tag-found) + * @username: username to write + * @password: password to write + * @error: if non-NULL, set to an error, if one occurs + * + * This function is used to write a username and password to a tag. The tag path + * can be obtained by listening to #GTlmNfc::tag-found signals). @error is set to + * @GTLM_NFC_ERROR_NO_TAG if no such tag exists. + */ +void gtlm_nfc_write_username_password(GTlmNfc* tlm_nfc, + const gchar* nfc_tag_path, + const gchar* username, + const gchar* password, + GError** error) +{ + if (nfc_tag_path == NULL) { + *error = g_error_new(GTLM_NFC_ERROR, GTLM_NFC_ERROR_NO_TAG, "No tag is present"); + return; + } + + GDBusProxy* tag = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, /* GDBusInterfaceInfo */ + "org.neard", + nfc_tag_path, + "org.neard.Tag", + NULL, /* GCancellable */ + error); + if (tag == NULL) { + g_debug ("Error creating tag proxy: %s", (*error)->message); + return; + } + + //gchar binary_data[] = {0x41, 0x42, 0x43, 0x44}; + gchar* binary_data = _encode_username_password(username, password); + GVariant* payload = g_variant_new_bytestring(binary_data); + g_free(binary_data); + + GVariant* arguments = g_variant_new_parsed ("({'Type': <'MIME'>, 'MIME': <'application/gtlm-nfc'>, 'Payload' : %v },)", payload); + + GVariant *result = g_dbus_proxy_call_sync (tag, + "Write", + arguments, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + error); + + if (result == NULL) { + g_debug ("Error writing to tag: %s", (*error)->message); + g_object_unref(tag); + return; + } + + g_variant_unref(result); + g_object_unref(tag); +} + +static void _decode_username_password(GTlmNfc* self, const gchar* data) +{ + gsize variant_s_size = 0; + guchar* variant_s = g_base64_decode(data, &variant_s_size); + + GVariantType* v_t = g_variant_type_new("(msms)"); + GVariant* v = g_variant_new_from_data(v_t, variant_s, variant_s_size, FALSE, NULL, NULL); + + if (v == NULL) { + g_debug("Couldn't decode Payload data to variant"); + g_variant_type_free(v_t); + g_free(variant_s); + g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0); + return; + } + + gchar* username = NULL; + gchar* password = NULL; + g_variant_get(v, "(msms)", &username, &password); + + g_signal_emit(self, signals[SIG_RECORD_FOUND], 0, username, password); + + g_free(username); + g_free(password); + g_variant_unref(v); + g_variant_type_free(v_t); + g_free(variant_s); +} + +static void +_handle_agent_method_call (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + GTlmNfc* self = GTLM_NFC(user_data); + gchar *parameters_str; + + parameters_str = g_variant_print (parameters, TRUE); + g_debug ("Agent received method call: %s\n\tParameters: %s\n\tSender: %s\n\tObject path: %s\n\tInteface name: %s", + method_name, parameters_str, sender, object_path, interface_name); + g_free (parameters_str); + + if (g_strcmp0(method_name, "GetNDEF") != 0) { + goto out; + } + + GVariant* parameters_dict = g_variant_get_child_value(parameters, 0); + if (parameters_dict == NULL) + { + g_debug ("Error getting parameters dict"); + g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0); + goto out; + } + + gchar* payload_data; + + if (g_variant_lookup(parameters_dict, "Payload", "^ay", &payload_data) == FALSE) { + g_debug ("Error getting raw Payload data"); + g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0); + g_variant_unref(parameters_dict); + goto out; + } + g_variant_unref(parameters_dict); + + _decode_username_password(self, payload_data); + g_free(payload_data); + +out: + g_dbus_method_invocation_return_value (invocation, NULL); +} + +static GVariant * +_handle_agent_get_property (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error, + gpointer user_data) +{ + return NULL; +} + +static gboolean +_handle_agent_set_property (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error, + gpointer user_data) +{ + return FALSE; +} + +static void +_setup_nfc_adapter(GTlmNfc *self, GDBusProxy *nfc_adapter) +{ + GError* error = NULL; + gboolean powered; + gboolean polling; + + // for some reason the cached properties aren't updated, so we request them directly + //GVariant* powered_v = g_dbus_proxy_get_cached_property(nfc_adapter, "Powered"); + GVariant* powered_resp = g_dbus_connection_call_sync (self->system_bus, + "org.neard", + g_dbus_proxy_get_object_path(nfc_adapter) , + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new("(ss)", + g_dbus_proxy_get_interface_name(nfc_adapter), + "Powered" + ), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (powered_resp == NULL) { + g_debug("Powered property is absent on an adapter: %s", error->message); + g_error_free (error); + return; + } + + GVariant* powered_v; + g_variant_get_child(powered_resp, 0, "v", &powered_v); + + if (powered_v == NULL || !g_variant_is_of_type(powered_v, G_VARIANT_TYPE_BOOLEAN)) { + g_debug("Error retrieving powered property"); + return; + } + + powered = g_variant_get_boolean(powered_v); + g_variant_unref(powered_resp); + + //GVariant* polling_v = g_dbus_proxy_get_cached_property(nfc_adapter, "Polling"); + GVariant* polling_resp = g_dbus_connection_call_sync (self->system_bus, + "org.neard", + g_dbus_proxy_get_object_path(nfc_adapter) , + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new("(ss)", + g_dbus_proxy_get_interface_name(nfc_adapter), + "Polling" + ), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (polling_resp == NULL) { + g_debug("Polling property is absent on an adapter: %s", error->message); + g_error_free (error); + return; + } + + GVariant* polling_v; + g_variant_get_child(polling_resp, 0, "v", &polling_v); + + if (polling_v == NULL || !g_variant_is_of_type(polling_v, G_VARIANT_TYPE_BOOLEAN)) { + g_debug("Error retrieving polling property"); + return; + } + + polling = g_variant_get_boolean(polling_v); + g_variant_unref(polling_resp); + + + GVariant* response; + if (powered == FALSE) { + // switch power on + + response = g_dbus_connection_call_sync (self->system_bus, + "org.neard", + g_dbus_proxy_get_object_path(nfc_adapter) , + "org.freedesktop.DBus.Properties", + "Set", + g_variant_new("(ssv)", + g_dbus_proxy_get_interface_name(nfc_adapter), + "Powered", + g_variant_new_boolean(TRUE) + ), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (response == NULL ) { + g_debug("Error swithing NFC adapter on: %s", error->message); + g_error_free (error); + return; + } + g_variant_unref(response); + g_debug("Switched NFC adapter on"); + } else + g_debug("Adapter already switched on"); + + if (polling == FALSE) { + // start polling + response = g_dbus_proxy_call_sync (nfc_adapter, + "StartPollLoop", + g_variant_new("(s)", "Initiator"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (response == NULL) + { + g_debug("Error starting NFC poll loop: %s", error->message); + g_error_free (error); + return; + } + g_variant_unref(response); + g_debug("Started NFC poll loop"); + + } else + g_debug("Adapter already in polling mode"); + + +} + + +void _on_interface_added(GDBusObjectManager *manager, + GDBusObject *object, + GDBusInterface *interface, + gpointer user_data) +{ + GTlmNfc* self = GTLM_NFC(user_data); + GDBusProxy* proxy = G_DBUS_PROXY(interface); + g_debug("Object %s added interface %s", + g_dbus_object_get_object_path (object), + g_dbus_proxy_get_interface_name (proxy)); + + if (g_strcmp0(g_dbus_proxy_get_interface_name (proxy), + "org.neard.Adapter") == 0) { + _setup_nfc_adapter(self, proxy); + return; + } + if (g_strcmp0(g_dbus_proxy_get_interface_name (proxy), + "org.neard.Tag") == 0) { + g_signal_emit(self, signals[SIG_TAG_FOUND], 0, g_dbus_object_get_object_path (object)); + return; + } + + if (g_strcmp0(g_dbus_proxy_get_interface_name (proxy), + "org.neard.Record") == 0) { + GVariant* type_v = g_dbus_proxy_get_cached_property(proxy, "Type"); + if (type_v == NULL || !g_variant_is_of_type(type_v, G_VARIANT_TYPE_STRING)) { + g_debug("Type property is absent on a record"); + g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0); + return; + } + const gchar* type = g_variant_get_string(type_v, NULL); + g_debug("Record has type %s", type); + if (g_strcmp0(type, "MIME") != 0) { + g_variant_unref(type_v); + g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0); + return; + } + g_variant_unref(type_v); + + GVariant* mimetype_v = g_dbus_proxy_get_cached_property(proxy, "MIME"); + if (mimetype_v == NULL || !g_variant_is_of_type(type_v, G_VARIANT_TYPE_STRING)) { + g_debug("MIME property is absent on a record"); + g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0); + return; + } + const gchar* mimetype = g_variant_get_string(mimetype_v, NULL); + g_debug("Record has MIME type %s", mimetype); + if (g_strcmp0(mimetype, "application/gtlm-nfc") != 0) { + g_variant_unref(mimetype_v); + g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0); + return; + } + g_variant_unref(mimetype_v); + } +} + +static void +_setup_nfc_adapters(GTlmNfc *self) +{ + GList* objects = g_dbus_object_manager_get_objects(self->neard_manager); + GList* objects_iter = objects; + + while (objects_iter != NULL) { + GList* interfaces = g_dbus_object_get_interfaces(objects_iter->data); + GList* interfaces_iter = interfaces; + while (interfaces_iter != NULL) { + g_debug("Checking managed object %s, interface %s", + g_dbus_object_get_object_path (objects_iter->data), + g_dbus_proxy_get_interface_name (interfaces_iter->data)); + if (g_strcmp0(g_dbus_proxy_get_interface_name (interfaces_iter->data), + "org.neard.Adapter") == 0) { + _setup_nfc_adapter(self, interfaces_iter->data); + } + g_object_unref(interfaces_iter->data); + interfaces_iter = interfaces_iter->next; + } + g_list_free(interfaces); + g_object_unref(objects_iter->data); + objects_iter = objects_iter->next; + } + g_list_free(objects); + +} + + + +void _on_interface_removed(GDBusObjectManager *manager, + GDBusObject *object, + GDBusInterface *interface, + gpointer user_data) +{ + GTlmNfc* self = GTLM_NFC(user_data); + GDBusProxy* proxy = G_DBUS_PROXY(interface); + g_debug("Object %s removed interface %s", + g_dbus_object_get_object_path (object), + g_dbus_proxy_get_interface_name (proxy)); + + if (g_strcmp0(g_dbus_proxy_get_interface_name (proxy), + "org.neard.Tag") == 0) { + g_signal_emit(self, signals[SIG_TAG_LOST], 0, g_dbus_object_get_object_path (object)); + + GVariant* adapter_v = g_dbus_proxy_get_cached_property(proxy, "Adapter"); + if (adapter_v == NULL || !g_variant_is_of_type(adapter_v, G_VARIANT_TYPE_OBJECT_PATH)) { + g_debug("Adapter property is absent on a tag"); + return; + } + const gchar* adapter_path = g_variant_get_string(adapter_v, NULL); + g_debug("Tag belongs to adapter %s", adapter_path); + GError* error = NULL; + GDBusProxy* adapter = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, /* GDBusInterfaceInfo */ + "org.neard", + adapter_path, + "org.neard.Adapter", + NULL, /* GCancellable */ + &error); + if (adapter == NULL) { + g_debug ("Error creating adapter proxy: %s", error->message); + g_error_free(error); + g_variant_unref(adapter_v); + return; + } + // start polling on an adapter + _setup_nfc_adapter(self, adapter); + g_object_unref(adapter); + g_variant_unref(adapter_v); + return; + } + + +} + + +void _on_object_added(GDBusObjectManager *manager, + GDBusObject *object, + gpointer user_data) +{ + //GTlmNfc* self = GTLM_NFC(user_data); + g_debug("Object %s added", + g_dbus_object_get_object_path (object)); + + GList* interfaces = g_dbus_object_get_interfaces(object); + GList* interfaces_iter = interfaces; + while (interfaces_iter != NULL) { + _on_interface_added(manager, object, interfaces_iter->data, user_data); + g_object_unref(interfaces_iter->data); + interfaces_iter = interfaces_iter->next; + } + g_list_free(interfaces); + g_debug("Finished checking interfaces"); +} + +void _on_object_removed(GDBusObjectManager *manager, + GDBusObject *object, + gpointer user_data) +{ + //GTlmNfc* self = GTLM_NFC(user_data); + g_debug("Object %s removed", + g_dbus_object_get_object_path (object)); + + GList* interfaces = g_dbus_object_get_interfaces(object); + GList* interfaces_iter = interfaces; + while (interfaces_iter != NULL) { + _on_interface_removed(manager, object, interfaces_iter->data, user_data); + g_object_unref(interfaces_iter->data); + interfaces_iter = interfaces_iter->next; + } + g_list_free(interfaces); + g_debug("Finished checking interfaces"); +} + +void _on_property_changed (GDBusObjectManagerClient *manager, + GDBusObjectProxy *object_proxy, + GDBusProxy *interface_proxy, + GVariant *changed_properties, + GStrv invalidated_properties, + gpointer user_data) +{ + gchar *parameters_str; + + parameters_str = g_variant_print (changed_properties, TRUE); + g_debug("Property of object %s changed:\n%s", + g_dbus_object_get_object_path(G_DBUS_OBJECT(object_proxy)), parameters_str); + g_debug("Invalidated properties:"); + while (*invalidated_properties != NULL) { + g_print(*invalidated_properties); + invalidated_properties++; + } + g_free(parameters_str); +} + +static void _setup_agent_and_adapters(GTlmNfc* self) +{ + GError *error = NULL; + + /* Introspection data for the agent object we are exporting */ + const gchar introspection_xml[] = + "<node>" + " <interface name='org.neard.NDEFAgent'>" + " <method name='GetNDEF'>" + " <arg type='a{sv}' name='values' direction='in'/>" + " </method>" + " <method name='Release'>" + " </method>" + " </interface>" + "</node>"; + + const GDBusInterfaceVTable interface_vtable = + { + _handle_agent_method_call, + _handle_agent_get_property, + _handle_agent_set_property + }; + + self->system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + + if (self->system_bus == NULL) { + g_debug ("Error getting a system bus: %s", error->message); + g_error_free (error); + return; + } + + GDBusNodeInfo *introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); + + self->agent_registration_id = g_dbus_connection_register_object (self->system_bus, + "/org/tlmnfc/agent", + introspection_data->interfaces[0], + &interface_vtable, + self, + NULL, + &error); + + if (self->agent_registration_id <= 0) { + g_debug ("Error registering an agent object: %s", error->message); + g_dbus_node_info_unref (introspection_data); + g_error_free (error); + return; + } + g_dbus_node_info_unref (introspection_data); + + GVariant* agent_register_response = g_dbus_connection_call_sync (self->system_bus, + "org.neard", + "/org/neard", + "org.neard.AgentManager", + "RegisterNDEFAgent", + g_variant_new("(os)", + "/org/tlmnfc/agent", + "application/gtlm-nfc"), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (agent_register_response == NULL) { + g_debug ("Error registering an agent with neard: %s", error->message); + g_error_free (error); + return; + } + g_variant_unref(agent_register_response); + + + self->neard_manager = g_dbus_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, + "org.neard", + "/", + NULL, NULL, NULL, NULL, + &error); + if (self->neard_manager == NULL) + { + g_debug ("Error creating neard object manager: %s", error->message); + g_error_free (error); + return ; + } + + // subscribe to interface added/removed signals + g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), + "interface-added", + G_CALLBACK (_on_interface_added), + self); + g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), + "interface-removed", + G_CALLBACK (_on_interface_removed), + self); + g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), + "object-added", + G_CALLBACK (_on_object_added), + self); + g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), + "object-removed", + G_CALLBACK (_on_object_removed), + self); + + + g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), + "interface-proxy-properties-changed", + G_CALLBACK (_on_property_changed), + self); + + + + _setup_nfc_adapters(self); + return; +} + + +static void +gtlm_nfc_init (GTlmNfc *self) +{ + + _setup_agent_and_adapters(self); +} + +static void +gtlm_nfc_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gtlm_nfc_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GTlmNfc *tlm_nfc = GTLM_NFC (object); + (void) tlm_nfc; + switch (prop_id) + { + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void gtlm_nfc_dispose(GObject *object) +{ + GTlmNfc* self = GTLM_NFC (object); + + if (self->system_bus) { + GError* error = NULL; + GVariant* agent_register_response = g_dbus_connection_call_sync (self->system_bus, + "org.neard", + "/org/neard", + "org.neard.AgentManager", + "UnregisterNDEFAgent", + g_variant_new("(os)", + "/org/tlmnfc/agent", + "application/gtlm-nfc"), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (agent_register_response == NULL) { + g_debug ("Error unregistering an agent with neard: %s", error->message); + g_error_free (error); + } + g_variant_unref(agent_register_response); + } + if (self->agent_registration_id > 0) + if (g_dbus_connection_unregister_object(self->system_bus, self->agent_registration_id) == FALSE) + g_debug("Error unregistering agent object"); + + + if (self->neard_manager) { + g_object_unref(self->neard_manager); + self->neard_manager = NULL; + } + if (self->system_bus) { + g_object_unref(self->system_bus); + self->system_bus = NULL; + } + + G_OBJECT_CLASS (gtlm_nfc_parent_class)->dispose (object); +} + +static void gtlm_nfc_finalize(GObject *object) +{ + //GTlmNfc* self = GTLM_NFC (object); + + + G_OBJECT_CLASS (gtlm_nfc_parent_class)->finalize (object); +} + +static void +gtlm_nfc_class_init (GTlmNfcClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->set_property = gtlm_nfc_set_property; + gobject_class->get_property = gtlm_nfc_get_property; + gobject_class->dispose = gtlm_nfc_dispose; + gobject_class->finalize = gtlm_nfc_finalize; + + + /** + * GTlmNfc::tag-found: + * @tlm_nfc: the object which emitted the signal + * @nfc_tag_path: an identifier of the tag (use in gtlm_nfc_write_username_password()) + * + * This signal is issued by #GTlmNfc object when a tag has been found. + */ + signals[SIG_TAG_FOUND] = g_signal_new ("tag-found", + G_TYPE_TLM_NFC, + G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, + 1, G_TYPE_STRING); + //2, G_TYPE_STRING, G_TYPE_STRING); + + /** + * GTlmNfc::tag-lost: + * @tlm_nfc: the object which emitted the signal + * @nfc_tag_path: an identifier of the tag + * + * This signal is issued by #GTlmNfc object when a tag has been lost. + */ + signals[SIG_TAG_LOST] = g_signal_new ("tag-lost", + G_TYPE_TLM_NFC, + G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, + 1, G_TYPE_STRING); + + /** + * GTlmNfc::record-found: + * @tlm_nfc: the object which emitted the signal + * @username: the username on the tag + * @password: the password on the tag + * + * This signal is issued by #GTlmNfc object when a username and password pair + * has been found on a tag. + */ + signals[SIG_RECORD_FOUND] = g_signal_new ("record-found", + G_TYPE_TLM_NFC, + G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, + 2, G_TYPE_STRING, G_TYPE_STRING); + + /** + * GTlmNfc::no-record-found: + * @tlm_nfc: the object which emitted the signal + * + * This signal is issued by #GTlmNfc object when a username and password pair + * has not been found on a tag + */ + signals[SIG_NO_RECORD_FOUND] = g_signal_new ("no-record-found", + G_TYPE_TLM_NFC, + G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, + 0); + +} diff --git a/src/gtlm-nfc.h b/src/gtlm-nfc.h new file mode 100644 index 0000000..361525e --- /dev/null +++ b/src/gtlm-nfc.h @@ -0,0 +1,72 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libtlm-nfc + * + * Copyright (C) 2013 Intel Corporation. + * + * Contact: Alexander Kanavin <alex.kanavin@gmail.com> + * + * This library 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 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef __GTLM_NFC_H__ +#define __GTLM_NFC_H__ + +#include <glib-object.h> +#include <gio/gio.h> + +typedef enum { + GTLM_NFC_ERROR_NONE, + + GTLM_NFC_ERROR_NO_TAG = 1 + +} GTlmNfcError; + +#define G_TYPE_TLM_NFC (gtlm_nfc_get_type ()) +#define GTLM_NFC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_TLM_NFC, GTlmNfc)) +#define G_IS_TLM_NFC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_TLM_NFC)) +#define GTLM_NFC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G_TYPE_TLM_NFC, GTlmNfcClass)) +#define G_IS_TLM_NFC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G_TYPE_TLM_NFC)) +#define GTLM_NFC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_TYPE_TLM_NFC, GTlmNfcClass)) + + +typedef struct _GTlmNfc GTlmNfc; +typedef struct _GTlmNfcClass GTlmNfcClass; + +struct _GTlmNfc +{ + GObject parent_instance; + + GDBusObjectManager* neard_manager; + GDBusConnection* system_bus; + guint agent_registration_id; +}; + +struct _GTlmNfcClass +{ + GObjectClass parent_class; +}; + +GType gtlm_nfc_get_type (void); + +void gtlm_nfc_write_username_password(GTlmNfc* tlm_nfc, + const gchar* nfc_tag_path, + const gchar* username, + const gchar* password, + GError** error); + +#endif /* __GTLM_NFC_H__ */
\ No newline at end of file |