p2p: Initial plugin implementation
authorSamuel Ortiz <sameo@linux.intel.com>
Mon, 14 Nov 2011 10:52:15 +0000 (11:52 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 14 Nov 2011 10:52:15 +0000 (11:52 +0100)
A skeleton for now.

Makefile.plugins
bootstrap-configure
configure.ac
plugins/p2p.c [new file with mode: 0644]

index 92ceff6..6d88b47 100644 (file)
@@ -50,3 +50,15 @@ plugins_nfctype4_la_CFLAGS = $(plugin_cflags)
 plugins_nfctype4_la_LDFLAGS = $(plugin_ldflags)
 endif
 endif
+
+if P2P
+if P2P_BUILTIN
+builtin_modules += p2p
+builtin_sources += plugins/p2p.c
+else
+plugin_LTLIBRARIES += plugins/p2p.la
+plugin_objects += $(plugins_p2p_la_OBJECTS)
+plugins_p2p_la_CFLAGS = $(plugin_cflags)
+plugins_p2p_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
index 509e3f7..04d3c77 100755 (executable)
@@ -11,4 +11,5 @@ fi
                --enable-nfctype2=builtin \
                --enable-nfctype3=builtin \
                --enable-nfctype4=builtin \
+               --enable-p2p=builtin \
                --prefix=/usr $*
index d0b73c3..4637c84 100644 (file)
@@ -115,4 +115,10 @@ AC_ARG_ENABLE(nfctype4,
 AM_CONDITIONAL(NFCTYPE4, test "${enable_nfctype4}" != "no")
 AM_CONDITIONAL(NFCTYPE4_BUILTIN, test "${enable_nfctype4}" = "builtin")
 
+AC_ARG_ENABLE(p2p,
+       AC_HELP_STRING([--enable-p2p], [enable NFC peer to peer support]),
+                       [enable_p2p=${enableval}], [enable_p2p="no"])
+AM_CONDITIONAL(P2P, test "${enable_p2p}" != "no")
+AM_CONDITIONAL(P2P_BUILTIN, test "${enable_p2p}" = "builtin")
+
 AC_OUTPUT(Makefile include/version.h)
diff --git a/plugins/p2p.c b/plugins/p2p.c
new file mode 100644 (file)
index 0000000..e60f183
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ *
+ *  neard - Near Field Communication manager
+ *
+ *  Copyright (C) 2011  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  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 General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdint.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/socket.h>
+
+#include <linux/socket.h>
+#include <linux/nfc.h>
+
+#include <near/plugin.h>
+#include <near/log.h>
+#include <near/types.h>
+#include <near/adapter.h>
+#include <near/target.h>
+#include <near/tag.h>
+#include <near/ndef.h>
+#include <near/tlv.h>
+
+static int p2p_read(uint32_t adapter_idx,
+               uint32_t target_idx, near_tag_read_cb cb)
+{
+       int err;
+
+       DBG("");
+
+       err = near_adapter_connect(adapter_idx, target_idx, NFC_PROTO_NFC_DEP);
+       if (err < 0) {
+               near_error("Could not connect %d", err);
+
+               return err;
+       }
+
+       return 0;
+}
+
+static struct near_tag_driver p2p_driver = {
+               .type     = NEAR_TAG_NFC_DEP,
+               .read_tag = p2p_read,
+};
+
+static int p2p_init(void)
+{
+       DBG("");
+
+       return near_tag_driver_register(&p2p_driver);
+}
+
+static void p2p_exit(void)
+{
+       DBG("");
+
+       near_tag_driver_unregister(&p2p_driver);
+}
+
+NEAR_PLUGIN_DEFINE(p2p, "NFC Forum peer to peer mode support", VERSION,
+               NEAR_PLUGIN_PRIORITY_HIGH, p2p_init, p2p_exit)