[-]
[+]
|
Changed |
_service:tar_git:nfcd.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,7 +2,7 @@
<service name="tar_git">
<param name="url">https://git.sailfishos.org/mer-core/nfcd.git</param>
<param name="branch">master</param>
- <param name="revision">1.0.35</param>
+ <param name="revision">1.1.2</param>
<param name="token"/>
<param name="debian">N</param>
<param name="dumb">N</param>
|
[-]
[+]
|
Deleted |
_service:tar_git:nfcd-1.0.35.tar.bz2/plugins/dbus_log/README
^
|
@@ -1,4 +0,0 @@
-dbus_log
-========
-
-Provides access to nfcd logs over D-Bus
|
[-]
[+]
|
Deleted |
_service:tar_git:nfcd-1.0.35.tar.bz2/plugins/dbus_log/dbus_log_plugin.c
^
|
@@ -1,350 +0,0 @@
-/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
- *
- * You may use this file under the terms of BSD license as follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "plugin.h"
-
-#include <nfc_manager.h>
-#include <nfc_plugin_impl.h>
-
-#include <dbuslog_server_gio.h>
-#include <dbuslog_util.h>
-
-#define GLOG_MODULE_NAME dbus_log_log
-#include <gutil_log.h>
-
-GLOG_MODULE_DEFINE("dbus-log");
-
-enum {
- DBUSLOG_EVENT_CATEGORY_ENABLED,
- DBUSLOG_EVENT_CATEGORY_DISABLED,
- DBUSLOG_EVENT_CATEGORY_LEVEL_CHANGED,
- DBUSLOG_EVENT_DEFAULT_LEVEL_CHANGED,
- DBUSLOG_EVENT_COUNT
-};
-
-/* Hold a reference to the plugin while we are using its GLogModule */
-typedef struct dbus_log_plugin_category {
- NfcPlugin* plugin;
- GLogModule* log;
-} DBusLogPluginCategory;
-
-typedef NfcPluginClass DBusLogPluginClass;
-typedef struct dbus_log_plugin {
- NfcPlugin parent;
- DBusLogServer* logserver;
- gulong event_id[DBUSLOG_EVENT_COUNT];
- GLogProc2 default_func;
- GHashTable* log_modules;
-} DBusLogPlugin;
-
-G_DEFINE_TYPE(DBusLogPlugin, dbus_log_plugin, NFC_TYPE_PLUGIN)
-#define DBUS_LOG_TYPE_PLUGIN (dbus_log_plugin_get_type())
-#define DBUS_LOG_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
- DBUS_LOG_TYPE_PLUGIN, DBusLogPlugin))
-
-static DBusLogPlugin* dbus_log_plugin_active;
-
-static
-DBusLogPluginCategory*
-dbus_log_plugin_category_new(
- NfcPlugin* plugin,
- GLogModule* log)
-{
- DBusLogPluginCategory* cat = g_new(DBusLogPluginCategory, 1);
-
- cat->plugin = nfc_plugin_ref(plugin);
- cat->log = log;
- return cat;
-}
-
-static
-void
-dbus_log_plugin_category_free(
- gpointer data)
-{
- DBusLogPluginCategory* cat = data;
-
- nfc_plugin_unref(cat->plugin);
- g_free(cat);
-}
-
-static
-void
-dbus_log_plugin_func(
- DBusLogPlugin* self,
- const GLogModule* log,
- int level,
- const char* format,
- va_list va)
-{
- va_list va2;
-
- va_copy(va2, va);
- dbus_log_server_logv(self->logserver, dbus_log_level_from_gutil(level),
- log->name, format, va2);
- va_end(va2);
- if (self->default_func) {
- self->default_func(log, level, format, va);
- }
-}
-
-static
-void
-dbus_log_plugin_hook(
- const GLogModule* log,
- int level,
- const char* format,
- va_list va)
-{
- GASSERT(dbus_log_plugin_active);
- if (dbus_log_plugin_active) {
- dbus_log_plugin_func(dbus_log_plugin_active, log, level, format, va);
- }
-}
-
-static
-void
-dbus_log_plugin_add_category(
- DBusLogPlugin* self,
- NfcPlugin* plugin,
- GLogModule* log)
-{
- gulong flags = 0;
-
- GDEBUG("Adding \"%s\"", log->name);
- g_hash_table_replace(self->log_modules, g_strdup(log->name),
- dbus_log_plugin_category_new(plugin, log));
- if (!(log->flags & GLOG_FLAG_DISABLE)) {
- flags |= (DBUSLOG_CATEGORY_FLAG_ENABLED |
- DBUSLOG_CATEGORY_FLAG_ENABLED_BY_DEFAULT);
- }
- if (log->flags & GLOG_FLAG_HIDE_NAME) {
- flags |= DBUSLOG_CATEGORY_FLAG_HIDE_NAME;
- }
- dbus_log_server_add_category(self->logserver, log->name,
- dbus_log_level_from_gutil(log->level), flags);
-}
-
-/*==========================================================================*
- * Events
- *==========================================================================*/
-
-static
-void
-dbus_log_plugin_category_enabled(
- DBusLogServer* server,
- const char* name,
- gpointer user_data)
-{
- DBusLogPlugin* self = DBUS_LOG_PLUGIN(user_data);
- DBusLogPluginCategory* cat = g_hash_table_lookup(self->log_modules, name);
-
- GASSERT(cat);
- if (cat) {
- cat->log->flags &= ~GLOG_FLAG_DISABLE;
- }
-}
-
-static
-void
-dbus_log_plugin_category_disabled(
- DBusLogServer* server,
- const char* name,
- gpointer user_data)
-{
- DBusLogPlugin* self = DBUS_LOG_PLUGIN(user_data);
- DBusLogPluginCategory* cat = g_hash_table_lookup(self->log_modules, name);
-
- GASSERT(cat);
- if (cat) {
- cat->log->flags |= GLOG_FLAG_DISABLE;
- }
-}
-
-static
-void
-dbus_log_plugin_category_level_changed(
- DBusLogServer* server,
- const char* name,
- DBUSLOG_LEVEL dbus_level,
- gpointer user_data)
|
[-]
[+]
|
Deleted |
_service:tar_git:nfcd-1.0.35.tar.bz2/plugins/dbus_log/plugin.h
^
|
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2018 Jolla Ltd.
- * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
- *
- * You may use this file under the terms of BSD license as follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef DBUS_LOG_PLUGIN_H
-#define DBUS_LOG_PLUGIN_H
-
-#include <nfc_plugin.h>
-
-NFC_PLUGIN_DECLARE(dbus_log)
-
-#endif /* DBUS_LOG_PLUGIN_H */
-
-/*
- * Local Variables:
- * mode: C
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/LICENSE
^
|
@@ -1,4 +1,5 @@
-Copyright (C) 2018-2020 Jolla Ltd.
+Copyright (C) 2018-2021 Jolla Ltd.
+Copyright (C) 2020 Open Mobile Platform LLC.
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/Makefile
^
|
@@ -8,7 +8,7 @@
# Required packages
#
-PKGS = libglibutil glib-2.0 gobject-2.0
+PKGS = libglibutil glib-2.0 gobject-2.0 gio-2.0 gio-unix-2.0
#
# Default target
@@ -32,14 +32,28 @@
nfc_adapter.c \
nfc_crc.c \
nfc_core.c \
+ nfc_initiator.c \
+ nfc_llc.c \
+ nfc_llc_io.c \
+ nfc_llc_io_initiator.c \
+ nfc_llc_io_target.c \
+ nfc_llc_param.c \
nfc_locale.c \
nfc_manager.c \
nfc_ndef_rec.c \
nfc_ndef_rec_sp.c \
nfc_ndef_rec_u.c \
nfc_ndef_rec_t.c \
+ nfc_peer.c \
+ nfc_peer_connection.c \
+ nfc_peer_initiator.c \
+ nfc_peer_service.c \
+ nfc_peer_services.c \
+ nfc_peer_socket.c \
+ nfc_peer_target.c \
nfc_plugins.c \
nfc_plugin.c \
+ nfc_snep_server.c \
nfc_tag.c \
nfc_tag_t2.c \
nfc_tag_t4.c \
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_adapter.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -54,10 +54,10 @@
NFC_MODE supported_modes;
NFC_MODE mode_requested;
NFC_MODE mode;
- gboolean target_present;
+ gboolean target_present; /* Presence of anything, actually */
};
-GType nfc_adapter_get_type(void);
+GType nfc_adapter_get_type(void) NFCD_EXPORT;
#define NFC_TYPE_ADAPTER (nfc_adapter_get_type())
#define NFC_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_ADAPTER, NfcAdapter))
@@ -75,124 +75,203 @@
NfcTag* tag,
void* user_data);
+typedef
+void
+(*NfcAdapterPeerFunc)(
+ NfcAdapter* adapter,
+ NfcPeer* peer,
+ void* user_data); /* Since 1.1.0 */
+
NfcAdapter*
nfc_adapter_ref(
- NfcAdapter* adapter);
+ NfcAdapter* adapter)
+ NFCD_EXPORT;
void
nfc_adapter_unref(
- NfcAdapter* adapter);
-
-void
-nfc_adapter_set_enabled(
- NfcAdapter* adapter,
- gboolean enabled);
+ NfcAdapter* adapter)
+ NFCD_EXPORT;
void
nfc_adapter_request_power(
NfcAdapter* adapter,
- gboolean on);
+ gboolean on)
+ NFCD_EXPORT;
gboolean
nfc_adapter_request_mode(
NfcAdapter* adapter,
- NFC_MODE mode);
+ NFC_MODE mode)
+ NFCD_EXPORT;
+
+NfcPeer**
+nfc_adapter_peers(
+ NfcAdapter* adapter) /* Since 1.1.0 */
+ NFCD_EXPORT;
NfcTag*
nfc_adapter_add_tag_t2(
NfcAdapter* adapter,
NfcTarget* target,
- const NfcTagParamT2* params);
+ const NfcTagParamT2* params)
+ NFCD_EXPORT;
NfcTag*
nfc_adapter_add_tag_t4a(
NfcAdapter* adapter,
NfcTarget* target,
const NfcParamPollA* poll_a,
- const NfcParamIsoDepPollA* iso_dep_param); /* Since 1.0.20 */
+ const NfcParamIsoDepPollA* iso_dep_param) /* Since 1.0.20 */
+ NFCD_EXPORT;
NfcTag*
nfc_adapter_add_tag_t4b(
NfcAdapter* adapter,
NfcTarget* target,
const NfcParamPollB* poll_b,
- const NfcParamIsoDepPollB* iso_dep_param); /* Since 1.0.20 */
+ const NfcParamIsoDepPollB* iso_dep_param) /* Since 1.0.20 */
+ NFCD_EXPORT;
NfcTag*
nfc_adapter_add_other_tag(
NfcAdapter* adapter,
NfcTarget* target)
- G_GNUC_DEPRECATED_FOR(nfc_adapter_add_other_tag2);
+ G_GNUC_DEPRECATED_FOR(nfc_adapter_add_other_tag2)
+ NFCD_EXPORT;
NfcTag*
nfc_adapter_add_other_tag2(
NfcAdapter* adapter,
NfcTarget* target,
- const NfcParamPoll* poll); /* Since 1.0.33 */
+ const NfcParamPoll* poll) /* Since 1.0.33 */
+ NFCD_EXPORT;
void
nfc_adapter_remove_tag(
NfcAdapter* adapter,
- const char* name);
+ const char* name)
+ NFCD_EXPORT;
+
+NfcPeer*
+nfc_adapter_add_peer_initiator_a(
+ NfcAdapter* adapter,
+ NfcTarget* target,
+ const NfcParamPollA* tech_param,
+ const NfcParamNfcDepInitiator* nfc_dep_param) /* Since 1.1.0 */
+ NFCD_EXPORT;
+
+NfcPeer*
+nfc_adapter_add_peer_initiator_f(
+ NfcAdapter* adapter,
+ NfcTarget* target,
+ const NfcParamPollF* tech_param,
+ const NfcParamNfcDepInitiator* nfc_dep_param) /* Since 1.1.0 */
+ NFCD_EXPORT;
+
+NfcPeer*
+nfc_adapter_add_peer_target_a(
+ NfcAdapter* adapter,
+ NfcInitiator* initiator,
+ const NfcParamListenA* tech_param,
+ const NfcParamNfcDepTarget* nfc_dep_param) /* Since 1.1.0 */
+ NFCD_EXPORT;
+
+NfcPeer*
+nfc_adapter_add_peer_target_f(
+ NfcAdapter* adapter,
+ NfcInitiator* initiator,
+ const NfcParamListenF* tech_param,
+ const NfcParamNfcDepTarget* nfc_dep_param) /* Since 1.1.0 */
+ NFCD_EXPORT;
+
+void
+nfc_adapter_remove_peer(
+ NfcAdapter* adapter,
+ const char* name) /* Since 1.1.0 */
+ NFCD_EXPORT;
gulong
nfc_adapter_add_target_presence_handler(
NfcAdapter* adapter,
NfcAdapterFunc func,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
gulong
nfc_adapter_add_tag_added_handler(
NfcAdapter* adapter,
NfcAdapterTagFunc func,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
gulong
nfc_adapter_add_tag_removed_handler(
NfcAdapter* adapter,
NfcAdapterTagFunc func,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
+
+gulong
+nfc_adapter_add_peer_added_handler(
+ NfcAdapter* adapter,
+ NfcAdapterPeerFunc func,
+ void* user_data) /* Since 1.1.0 */
+ NFCD_EXPORT;
+
+gulong
+nfc_adapter_add_peer_removed_handler(
+ NfcAdapter* adapter,
+ NfcAdapterPeerFunc func,
+ void* user_data) /* Since 1.1.0 */
+ NFCD_EXPORT;
gulong
nfc_adapter_add_powered_changed_handler(
NfcAdapter* adapter,
NfcAdapterFunc func,
- void* user_data);
+ void* user_data)
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_adapter_impl.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -69,18 +69,21 @@
nfc_adapter_mode_notify(
NfcAdapter* adapter,
NFC_MODE mode,
- gboolean requested);
+ gboolean requested)
+ NFCD_EXPORT;
void
nfc_adapter_power_notify(
NfcAdapter* adapter,
gboolean on,
- gboolean requested);
+ gboolean requested)
+ NFCD_EXPORT;
void
nfc_adapter_target_notify(
NfcAdapter* adapter,
- gboolean present);
+ gboolean present)
+ NFCD_EXPORT;
G_END_DECLS
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_core.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -41,7 +41,8 @@
guint
nfc_core_version(
- void); /* Since 1.0.26 */
+ void) /* Since 1.0.26 */
+ NFCD_EXPORT;
G_END_DECLS
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_crc.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -14,8 +14,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -47,47 +47,55 @@
nfc_crc_append_le16(
NfcCrc16Func fn,
guint8* data,
- gsize size);
+ gsize size)
+ NFCD_EXPORT;
gboolean
nfc_crc_check_le16_tail(
NfcCrc16Func fn,
const guint8* data,
- gsize len);
+ gsize len)
+ NFCD_EXPORT;
/* CRC_A [ISO/IEC_13239] */
guint16
nfc_crc_a(
const guint8* data,
- gsize len);
+ gsize len)
+ NFCD_EXPORT;
void
nfc_crc_a_append(
guint8* data,
- gsize size);
+ gsize size)
+ NFCD_EXPORT;
gboolean
nfc_crc_a_check_tail(
const guint8* data,
- gsize len);
+ gsize len)
+ NFCD_EXPORT;
/* CRC_B [ISO/IEC_13239] */
guint16
nfc_crc_b(
const guint8* data,
- gsize len);
+ gsize len)
+ NFCD_EXPORT;
void
nfc_crc_b_append(
guint8* data,
- gsize size);
+ gsize size)
+ NFCD_EXPORT;
gboolean
nfc_crc_b_check_tail(
const guint8* data,
- gsize len);
+ gsize len)
+ NFCD_EXPORT;
G_END_DECLS
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_initiator.h
^
|
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_INITIATOR_H
+#define NFC_INITIATOR_H
+
+#include "nfc_types.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Since 1.1.0 */
+
+typedef struct nfc_initiator_priv NfcInitiatorPriv;
+
+struct nfc_initiator {
+ GObject object;
+ NfcInitiatorPriv* priv;
+ NFC_TECHNOLOGY technology;
+ NFC_PROTOCOL protocol;
+ /* This one-way flag is set to FALSE when peer goes away. */
+ gboolean present;
+};
+
+GType nfc_initiator_get_type(void) NFCD_EXPORT;
+#define NFC_TYPE_INITIATOR (nfc_initiator_get_type())
+#define NFC_INITIATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ NFC_TYPE_INITIATOR, NfcInitiator))
+
+NfcInitiator*
+nfc_initiator_ref(
+ NfcInitiator* initiator)
+ NFCD_EXPORT;
+
+void
+nfc_initiator_unref(
+ NfcInitiator* initiator)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_INITIATOR_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_initiator_impl.h
^
|
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_INITIATOR_IMPL_H
+#define NFC_INITIATOR_IMPL_H
+
+#include "nfc_initiator.h"
+
+/* Internal API for use by NfcInitiator implemenations */
+
+G_BEGIN_DECLS
+
+/* Since 1.1.0 */
+
+typedef struct nfc_initiator_class {
+ GObjectClass parent;
+
+ /* Base class makes sure that there are no overlapping responses.
+ * When transmission completes, nfc_initiator_response_sent() is called
+ * by the derived class. */
+ gboolean (*respond)(NfcInitiator* initiator, const void* data, guint len);
+
+ /* This should deactivate the initiator. When the initiator gets
+ * deactivated, subclass calls nfc_initiator_gone() to update the
+ * 'present' flag. */
+ void (*deactivate)(NfcInitiator* initiator);
+
+ /* These base implementation emits signal, must always be called. */
+ void (*gone)(NfcInitiator* initiator);
+
+ /* Padding for future expansion */
+ void (*_reserved1)(void);
+ void (*_reserved2)(void);
+ void (*_reserved3)(void);
+ void (*_reserved4)(void);
+ void (*_reserved5)(void);
+ void (*_reserved6)(void);
+ void (*_reserved7)(void);
+ void (*_reserved8)(void);
+ void (*_reserved9)(void);
+ void (*_reserved10)(void);
+} NfcInitiatorClass;
+
+#define NFC_INITIATOR_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
+ NFC_TYPE_INITIATOR, NfcInitiatorClass)
+
+/*
+ * Normally it goes like this:
+ *
+ * 1. Data is coming in. Derived class calls nfc_initiator_transmit()
+ * 2. Base class issues a signal passing in NfcTransmission object
+ * 3. Transmission handler does whatever and calls nfc_transmission_respond()
+ * That translates into respond() call to the derived class.
+ * 4. Derived class calls nfc_initiator_response_sent() when response is sent.
+ * 5. At this point initiator is ready to receive a new portion of data.
+ *
+ * Now, if anything goes wrong... Basically, if anything goes wrong,
+ * RF interface is deactivated by invoking deactivate() callback of the
+ * derived class. Here is what can go wrong:
+
+ * a. No one responds to the signal at step 2.
+ * b. nfc_transmission_unref() is called before nfc_transmission_respond()
+ * in other words, transmission is received but dropped with no reply
+ * provided.
+ * c. nfc_initiator_response_sent() receives an error status at step 4.
+ *
+ * It's not quite clear what to do when the next portion of data arrives
+ * before we have sent a response to the previous one. Even though it
+ * shouldn't happen in real life, lower level APIs (e.g. NCI) often
+ * allow it. Currently it's being treated as an error (or was treated
+ * at the time of this writing). Let's see how it goes.
+ */
+
+void
+nfc_initiator_transmit(
+ NfcInitiator* initiator,
+ const void* data,
+ guint len)
+ NFCD_EXPORT;
+
+void
+nfc_initiator_response_sent(
+ NfcInitiator* initiator,
+ NFC_TRANSMIT_STATUS status)
+ NFCD_EXPORT;
+
+void
+nfc_initiator_gone(
+ NfcInitiator* initiator)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_INITIATOR_IMPL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_manager.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -14,8 +14,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -48,9 +48,14 @@
gboolean enabled;
gboolean stopped;
int error;
+ /* Since 1.1.0 */
+ NFC_MODE mode;
+ /* Since 1.1.1 */
+ NFC_LLCP_VERSION llcp_version;
+ NfcPeerService* const* services;
};
-GType nfc_manager_get_type();
+GType nfc_manager_get_type() NFCD_EXPORT;
#define NFC_TYPE_MANAGER (nfc_manager_get_type())
#define NFC_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_MANAGER, NfcManager))
@@ -71,91 +76,170 @@
NfcAdapter* adapter,
void* user_data);
+typedef
+void
+(*NfcManagerServiceFunc)(
+ NfcManager* manager,
+ NfcPeerService* service,
+ void* user_data);
+
NfcManager*
nfc_manager_ref(
- NfcManager* manager);
+ NfcManager* manager)
+ NFCD_EXPORT;
void
nfc_manager_unref(
- NfcManager* manager);
+ NfcManager* manager)
+ NFCD_EXPORT;
NfcPlugin* const*
nfc_manager_plugins(
- NfcManager* manager);
+ NfcManager* manager)
+ NFCD_EXPORT;
NfcAdapter*
nfc_manager_get_adapter(
NfcManager* manager,
- const char* name);
+ const char* name)
+ NFCD_EXPORT;
const char*
nfc_manager_add_adapter(
NfcManager* manager,
- NfcAdapter* adapter);
+ NfcAdapter* adapter)
+ NFCD_EXPORT;
void
nfc_manager_remove_adapter(
NfcManager* manager,
- const char* name);
+ const char* name)
+ NFCD_EXPORT;
void
nfc_manager_stop(
NfcManager* manager,
- int error);
+ int error)
+ NFCD_EXPORT;
void
nfc_manager_set_enabled(
NfcManager* manager,
- gboolean enabled);
+ gboolean enabled)
+ NFCD_EXPORT;
void
nfc_manager_request_power(
NfcManager* manager,
- gboolean on);
+ gboolean on)
+ NFCD_EXPORT;
+
+gboolean
+nfc_manager_register_service(
+ NfcManager* manager,
+ NfcPeerService* service) /* Since 1.1.0 */
+ NFCD_EXPORT;
void
-nfc_manager_request_mode(
+nfc_manager_unregister_service(
NfcManager* manager,
- NFC_MODE mode);
+ NfcPeerService* service) /* Since 1.1.0 */
+ NFCD_EXPORT;
gulong
nfc_manager_add_adapter_added_handler(
NfcManager* manager,
NfcManagerAdapterFunc func,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
gulong
nfc_manager_add_adapter_removed_handler(
NfcManager* manager,
NfcManagerAdapterFunc func,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
gulong
nfc_manager_add_enabled_changed_handler(
NfcManager* manager,
NfcManagerFunc func,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
gulong
nfc_manager_add_stopped_handler(
NfcManager* manager,
NfcManagerFunc func,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
+
+gulong
+nfc_manager_add_mode_changed_handler(
+ NfcManager* manager,
+ NfcManagerFunc func,
+ void* user_data) /* Since 1.1.0 */
+ NFCD_EXPORT;
+
+gulong
+nfc_manager_add_service_registered_handler(
+ NfcManager* manager,
+ NfcManagerServiceFunc func,
+ void* user_data) /* Since 1.1.1 */
+ NFCD_EXPORT;
+
+gulong
+nfc_manager_add_service_unregistered_handler(
+ NfcManager* manager,
+ NfcManagerServiceFunc func,
+ void* user_data) /* Since 1.1.1 */
+ NFCD_EXPORT;
void
nfc_manager_remove_handler(
NfcManager* manager,
- gulong id);
+ gulong id)
+ NFCD_EXPORT;
void
nfc_manager_remove_handlers(
NfcManager* manager,
gulong* ids,
- guint count);
+ guint count)
+ NFCD_EXPORT;
#define nfc_manager_remove_all_handlers(manager,ids) \
nfc_manager_remove_handlers(manager, ids, G_N_ELEMENTS(ids))
+/*
+ * Plugins can ask NfcManager to enable and/or disable certain NFC modes.
+ * The last submitted request takes precedence, i.e. if first a request
+ * is submitted to enable certain mode and then another another request
+ * to disable the same mode, the mode remains enabled until the first
+ * request is dropped.
+ *
+ * If the same bits are set in both enable and disable masks, the enabling
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_ndef.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -79,26 +79,30 @@
GUtilData payload;
};
-GType nfc_ndef_rec_get_type(void);
+GType nfc_ndef_rec_get_type(void) NFCD_EXPORT;
#define NFC_TYPE_NDEF_REC (nfc_ndef_rec_get_type())
#define NFC_NDEF_REC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_NDEF_REC, NfcNdefRec))
NfcNdefRec*
nfc_ndef_rec_new(
- const GUtilData* block);
+ const GUtilData* block)
+ NFCD_EXPORT;
NfcNdefRec*
nfc_ndef_rec_new_tlv(
- const GUtilData* tlv);
+ const GUtilData* tlv)
+ NFCD_EXPORT;
NfcNdefRec*
nfc_ndef_rec_ref(
- NfcNdefRec* rec);
+ NfcNdefRec* rec)
+ NFCD_EXPORT;
void
nfc_ndef_rec_unref(
- NfcNdefRec* rec);
+ NfcNdefRec* rec)
+ NFCD_EXPORT;
/* URI */
@@ -110,7 +114,7 @@
const char* uri;
} NfcNdefRecU;
-GType nfc_ndef_rec_u_get_type(void);
+GType nfc_ndef_rec_u_get_type(void) NFCD_EXPORT;
#define NFC_TYPE_NDEF_REC_U (nfc_ndef_rec_u_get_type())
#define NFC_NDEF_REC_U(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_NDEF_REC_U, NfcNdefRecU))
@@ -119,7 +123,8 @@
NfcNdefRecU*
nfc_ndef_rec_u_new(
- const char* uri);
+ const char* uri)
+ NFCD_EXPORT;
/* Text */
@@ -132,7 +137,7 @@
const char* text;
} NfcNdefRecT;
-GType nfc_ndef_rec_t_get_type(void);
+GType nfc_ndef_rec_t_get_type(void) NFCD_EXPORT;
#define NFC_TYPE_NDEF_REC_T (nfc_ndef_rec_t_get_type())
#define NFC_NDEF_REC_T(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_NDEF_REC_T, NfcNdefRecT))
@@ -156,7 +161,8 @@
nfc_ndef_rec_t_new_enc(
const char* text,
const char* lang,
- NFC_NDEF_REC_T_ENC enc);
+ NFC_NDEF_REC_T_ENC enc)
+ NFCD_EXPORT;
#define nfc_ndef_rec_t_new(text, lang) \
nfc_ndef_rec_t_new_enc(text, lang, NFC_NDEF_REC_T_ENC_UTF8)
@@ -164,13 +170,15 @@
NFC_LANG_MATCH
nfc_ndef_rec_t_lang_match(
NfcNdefRecT* rec,
- const NfcLanguage* lang); /* Since 1.0.15 */
+ const NfcLanguage* lang) /* Since 1.0.15 */
+ NFCD_EXPORT;
gint
nfc_ndef_rec_t_lang_compare(
gconstpointer a, /* NfcNdefRecT* */
gconstpointer b, /* NfcNdefRecT* */
- gpointer user_data /* NfcLanguage* */); /* Since 1.0.18 */
+ gpointer user_data /* NfcLanguage* */) /* Since 1.0.18 */
+ NFCD_EXPORT;
/* Smart poster */
@@ -200,7 +208,7 @@
const NfcNdefMedia* icon;
} NfcNdefRecSp;
-GType nfc_ndef_rec_sp_get_type(void);
+GType nfc_ndef_rec_sp_get_type(void) NFCD_EXPORT;
#define NFC_TYPE_NDEF_REC_SP (nfc_ndef_rec_sp_get_type())
#define NFC_NDEF_REC_SP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_NDEF_REC_SP, NfcNdefRecSp))
@@ -215,14 +223,16 @@
const char* type,
guint size,
NFC_NDEF_SP_ACT act,
- const NfcNdefMedia* icon); /* Since 1.0.18 */
+ const NfcNdefMedia* icon) /* Since 1.0.18 */
+ NFCD_EXPORT;
/* Utilities */
gboolean
nfc_ndef_valid_mediatype(
const GUtilData* type,
- gboolean wildcard); /* Since 1.0.18 */
+ gboolean wildcard) /* Since 1.0.18 */
+ NFCD_EXPORT;
/* These are not yet implemented: */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_peer.h
^
|
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_H
+#define NFC_PEER_H
+
+#include "nfc_types.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Since 1.1.0 */
+
+typedef struct nfc_peer_priv NfcPeerPriv;
+
+typedef enum nfc_peer_flags {
+ NFC_PEER_FLAGS_NONE = 0x00,
+ NFC_PEER_FLAG_INITIALIZED = 0x01,
+ NFC_PEER_FLAG_INITIATOR = 0x02
+} NFC_PEER_FLAGS;
+
+struct nfc_peer {
+ GObject object;
+ NfcPeerPriv* priv;
+ const char* name;
+ gboolean present;
+ NFC_TECHNOLOGY technology;
+ NFC_PEER_FLAGS flags;
+ guint wks; /* Remote Well-Known Services (mask) */
+ NfcNdefRec* ndef; /* Received via SNEP */
+};
+
+GType nfc_peer_get_type(void) NFCD_EXPORT;
+#define NFC_TYPE_PEER (nfc_peer_get_type())
+#define NFC_IS_PEER(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, NFC_TYPE_PEER)
+#define NFC_PEER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NFC_TYPE_PEER, \
+ NfcPeer))
+
+/*
+ * NFC-DEP Initiator and Target parameters.
+ * Contain relevant parts of ATR_RES/ATR_REQ (General bytes, what else?).
+ *
+ * NFCForum-TS-LLCP_1.1
+ * 6.2.3.1 Link Activation procedure for the Initiator
+ * 6.2.3.2 Link Activation procedure for the Target
+ */
+struct nfc_param_nfc_dep_initator {
+ GUtilData atr_res_g; /* ATR_RES General Bytes */
+};
+
+struct nfc_param_nfc_dep_target {
+ GUtilData atr_req_g; /* ATR_REQ General Bytes */
+};
+
+typedef
+void
+(*NfcPeerFunc)(
+ NfcPeer* peer,
+ void* user_data);
+
+gulong
+nfc_peer_add_initialized_handler(
+ NfcPeer* peer,
+ NfcPeerFunc func,
+ void* user_data)
+ NFCD_EXPORT;
+
+NfcPeer*
+nfc_peer_ref(
+ NfcPeer* peer)
+ NFCD_EXPORT;
+
+void
+nfc_peer_unref(
+ NfcPeer* peer)
+ NFCD_EXPORT;
+
+void
+nfc_peer_deactivate(
+ NfcPeer* peer)
+ NFCD_EXPORT;
+
+gulong
+nfc_peer_add_wks_changed_handler(
+ NfcPeer* peer,
+ NfcPeerFunc func,
+ void* user_data)
+ NFCD_EXPORT;
+
+gulong
+nfc_peer_add_ndef_changed_handler(
+ NfcPeer* peer,
+ NfcPeerFunc func,
+ void* user_data)
+ NFCD_EXPORT;
+
+gulong
+nfc_peer_add_initialized_handler(
+ NfcPeer* peer,
+ NfcPeerFunc func,
+ void* user_data)
+ NFCD_EXPORT;
+
+gulong
+nfc_peer_add_gone_handler(
+ NfcPeer* peer,
+ NfcPeerFunc func,
+ void* user_data)
+ NFCD_EXPORT;
+
+void
+nfc_peer_remove_handler(
+ NfcPeer* peer,
+ gulong id)
+ NFCD_EXPORT;
+
+void
+nfc_peer_remove_handlers(
+ NfcPeer* peer,
+ gulong* ids,
+ guint count)
+ NFCD_EXPORT;
+
+#define nfc_peer_remove_all_handlers(peer,ids) \
+ nfc_peer_remove_handlers(peer, ids, G_N_ELEMENTS(ids))
+
+gboolean
+nfc_peer_register_service(
+ NfcPeer* peer,
+ NfcPeerService* service)
+ NFCD_EXPORT;
+
+void
+nfc_peer_unregister_service(
+ NfcPeer* peer,
+ NfcPeerService* service)
+ NFCD_EXPORT;
+
+/*
+ * Functions below return a NfcPeerConnection pointer, not a reference.
+ * In other words, if the caller needs to keep this pointer, it needs
+ * to add its own reference. If is only guaranteed that this pointer
+ * stays alive until return to the event loop, or until the next call
+ * to NFC core, whichever happens first.
+ */
+
+typedef
+void
+(*NfcPeerConnectFunc)(
+ NfcPeer* peer,
+ NfcPeerConnection* connection,
+ NFC_PEER_CONNECT_RESULT result,
+ void* user_data);
+
+NfcPeerConnection*
+nfc_peer_connect(
+ NfcPeer* peer,
+ NfcPeerService* service,
+ guint rsap,
+ NfcPeerConnectFunc complete,
+ GDestroyNotify destroy,
+ void* user_data)
+ NFCD_EXPORT;
+
+NfcPeerConnection*
+nfc_peer_connect_sn(
+ NfcPeer* peer,
+ NfcPeerService* service,
+ const char* sn,
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_peer_connection.h
^
|
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_CONNECTION_H
+#define NFC_PEER_CONNECTION_H
+
+#include "nfc_types.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Since 1.1.0 */
+
+typedef enum nfc_llc_co_state {
+ NFC_LLC_CO_CONNECTING, /* CONNECT sent, waiting for CC */
+ NFC_LLC_CO_ACCEPTING, /* CONNECT received, CC not sent */
+ NFC_LLC_CO_ABANDONED, /* CONNECT sent, will disconnect */
+ NFC_LLC_CO_ACTIVE, /* Connection established */
+ NFC_LLC_CO_DISCONNECTING, /* DISC sent, waiting for DM */
+ NFC_LLC_CO_DEAD /* Final state */
+} NFC_LLC_CO_STATE;
+
+typedef struct nfc_peer_connection_priv NfcPeerConnectionPriv;
+struct nfc_peer_connection {
+ GObject object;
+ NfcPeerConnectionPriv* priv;
+ NfcPeerService* service; /* Local service */
+ NFC_LLC_CO_STATE state; /* Connection state */
+ const char* name; /* Remote service name, if known */
+ gsize bytes_queued; /* Bytes currently queued */
+ guint64 bytes_sent; /* Bytes sent (passed to LLCP level) */
+ guint64 bytes_received; /* Bytes received */
+ guint8 rsap; /* Remote SAP */
+};
+
+GType nfc_peer_connection_get_type(void) NFCD_EXPORT;
+#define NFC_TYPE_PEER_CONNECTION (nfc_peer_connection_get_type())
+#define NFC_PEER_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ NFC_TYPE_PEER_CONNECTION, NfcPeerConnection))
+
+typedef
+void
+(*NfcPeerConnectionFunc)(
+ NfcPeerConnection* pc,
+ void* user_data);
+
+NfcPeerConnection*
+nfc_peer_connection_ref(
+ NfcPeerConnection* pc)
+ NFCD_EXPORT;
+
+void
+nfc_peer_connection_unref(
+ NfcPeerConnection* pc)
+ NFCD_EXPORT;
+
+guint
+nfc_peer_connection_rmiu(
+ NfcPeerConnection* pc)
+ NFCD_EXPORT;
+
+gboolean
+nfc_peer_connection_send(
+ NfcPeerConnection* pc,
+ GBytes* bytes)
+ NFCD_EXPORT;
+
+void
+nfc_peer_connection_disconnect(
+ NfcPeerConnection* pc)
+ NFCD_EXPORT;
+
+gboolean
+nfc_peer_connection_cancel(
+ NfcPeerConnection* pc)
+ NFCD_EXPORT;
+
+gulong
+nfc_peer_connection_add_state_changed_handler(
+ NfcPeerConnection* pc,
+ NfcPeerConnectionFunc func,
+ void* user_data);
+ NFCD_EXPORT
+
+void
+nfc_peer_connection_remove_handler(
+ NfcPeerConnection* pc,
+ gulong id)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_PEER_CONNECTION_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_peer_connection_impl.h
^
|
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_CONNECTION_IMPL_H
+#define NFC_PEER_CONNECTION_IMPL_H
+
+#include "nfc_peer_connection.h"
+
+G_BEGIN_DECLS
+
+/* Since 1.1.0 */
+
+/* Internal API for use by classes derived from NfcPeerConnection */
+
+typedef struct nfc_peer_connection_class {
+ GObjectClass parent;
+
+ void (*accept)(NfcPeerConnection* conn);
+ void (*accept_cancelled)(NfcPeerConnection* conn);
+ void (*state_changed)(NfcPeerConnection* conn);
+ void (*data_received)(NfcPeerConnection* conn, const void* data, guint len);
+ void (*data_dequeued)(NfcPeerConnection* conn);
+
+ /* Padding for future expansion */
+ void (*_reserved1)(void);
+ void (*_reserved2)(void);
+ void (*_reserved3)(void);
+ void (*_reserved4)(void);
+ void (*_reserved5)(void);
+ void (*_reserved6)(void);
+ void (*_reserved7)(void);
+ void (*_reserved8)(void);
+ void (*_reserved9)(void);
+ void (*_reserved10)(void);
+} NfcPeerConnectionClass;
+
+#define NFC_PEER_CONNECTION_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
+ NFC_TYPE_PEER_CONNECTION, NfcPeerConnectionClass)
+
+void
+nfc_peer_connection_init_connect(
+ NfcPeerConnection* pc,
+ NfcPeerService* ps,
+ guint8 rsap,
+ const char* name)
+ NFCD_EXPORT;
+
+void
+nfc_peer_connection_init_accept(
+ NfcPeerConnection* pc,
+ NfcPeerService* ps,
+ guint8 rsap)
+ NFCD_EXPORT;
+
+/* ACCEPTING => ACTIVE */
+void
+nfc_peer_connection_accepted(
+ NfcPeerConnection* pc)
+ NFCD_EXPORT;
+
+/* ACCEPTING => DEAD */
+void
+nfc_peer_connection_rejected(
+ NfcPeerConnection* pc)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_PEER_CONNECTION_IMPL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_peer_service.h
^
|
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_SERVICE_H
+#define NFC_PEER_SERVICE_H
+
+#include "nfc_types.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Since 1.1.0 */
+
+typedef struct nfc_peer_service_priv NfcPeerServicePriv;
+struct nfc_peer_service {
+ GObject object;
+ NfcPeerServicePriv* priv;
+ const char* name;
+ guint8 sap;
+};
+
+/* Well-known LLCP SAP values */
+#define NFC_LLC_SAP_SDP (0x01) /* urn:nfc:sn:sdp */
+#define NFC_LLC_SAP_SNEP (0x04) /* urn:nfc:sn:snep */
+
+/* Well-known names */
+#define NFC_LLC_NAME_SDP "urn:nfc:sn:sdp"
+#define NFC_LLC_NAME_SNEP "urn:nfc:sn:snep"
+
+GType nfc_peer_service_get_type(void) NFCD_EXPORT;
+#define NFC_TYPE_PEER_SERVICE (nfc_peer_service_get_type())
+#define NFC_PEER_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ NFC_TYPE_PEER_SERVICE, NfcPeerService))
+
+NfcPeerService*
+nfc_peer_service_ref(
+ NfcPeerService* service)
+ NFCD_EXPORT;
+
+void
+nfc_peer_service_unref(
+ NfcPeerService* service)
+ NFCD_EXPORT;
+
+void
+nfc_peer_service_disconnect_all(
+ NfcPeerService* service)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_PEER_SERVICE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_peer_service_impl.h
^
|
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_SERVICE_IMPL_H
+#define NFC_PEER_SERVICE_IMPL_H
+
+#include "nfc_peer_service.h"
+
+G_BEGIN_DECLS
+
+/* Since 1.1.0 */
+
+/* Internal API for use by NfcPeerService implemenations */
+
+typedef struct nfc_peer_service_class {
+ GObjectClass parent;
+
+ void (*peer_arrived)(NfcPeerService* service, NfcPeer* peer);
+ void (*peer_left)(NfcPeerService* service, NfcPeer* peer);
+ NfcPeerConnection* (*new_connect)(NfcPeerService* service, guint8 rsap,
+ const char* name);
+ NfcPeerConnection* (*new_accept)(NfcPeerService* service, guint8 rsap);
+ void (*datagram_received)(NfcPeerService* service, guint8 ssap,
+ const void* data, guint len);
+
+ /* Padding for future expansion */
+ void (*_reserved1)(void);
+ void (*_reserved2)(void);
+ void (*_reserved3)(void);
+ void (*_reserved4)(void);
+ void (*_reserved5)(void);
+ void (*_reserved6)(void);
+ void (*_reserved7)(void);
+ void (*_reserved8)(void);
+ void (*_reserved9)(void);
+ void (*_reserved10)(void);
+} NfcPeerServiceClass;
+
+#define NFC_PEER_SERVICE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
+ NFC_TYPE_PEER_SERVICE, NfcPeerServiceClass)
+
+void
+nfc_peer_service_init_base(
+ NfcPeerService* service,
+ const char* name)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_PEER_SERVICE_IMPL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_peer_socket.h
^
|
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_SOCKET_H
+#define NFC_PEER_SOCKET_H
+
+#include "nfc_peer_connection.h"
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+/* Since 1.1.0 */
+
+/*
+ * NfcPeerSocket essentially provides two ways of writing the data.
+ * Calling nfc_peer_connection_send() will work, and writing data
+ * to public file descriptor will also work. File descriptor
+ * writes will be internally (and asynchronously) translated
+ * into nfc_peer_connection_send() calls.
+ *
+ * The file descritor is exposed as a ref-countable GUnixFDList.
+ * That list always contains exactly one descriptor.
+ *
+ * It doesn't make sense to use both methods though, because chunks
+ * of data will end up being unpredictably mixed up with each other.
+ * The preferred way of writing the data and preserving the integrity
+ * of the stream is to use the file descriptor.
+ *
+ * Note that max_send_queue is not a hard limit, the actual amount of
+ * data buffered at NfcPeerService level may exceed the limit by one MIU.
+ * That's in addition to buffering happening in other places down the stack.
+ */
+typedef struct nfc_peer_socket_priv NfcPeerSocketPriv;
+struct nfc_peer_socket {
+ NfcPeerConnection connection;
+ NfcPeerSocketPriv* priv;
+ GUnixFDList* fdl;
+ gsize max_send_queue;
+};
+
+GType nfc_peer_socket_get_type(void) NFCD_EXPORT;
+#define NFC_TYPE_PEER_SOCKET (nfc_peer_socket_get_type())
+#define NFC_PEER_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ NFC_TYPE_PEER_SOCKET, NfcPeerSocket))
+
+NfcPeerSocket*
+nfc_peer_socket_new_connect(
+ NfcPeerService* service,
+ guint8 rsap,
+ const char* name)
+ G_GNUC_WARN_UNUSED_RESULT
+ NFCD_EXPORT;
+
+NfcPeerSocket*
+nfc_peer_socket_new_accept(
+ NfcPeerService* service,
+ guint8 rsap)
+ G_GNUC_WARN_UNUSED_RESULT
+ NFCD_EXPORT;
+
+int
+nfc_peer_socket_fd(
+ NfcPeerSocket* socket)
+ NFCD_EXPORT;
+
+void
+nfc_peer_socket_set_max_send_queue(
+ NfcPeerSocket* socket,
+ gsize max_send_queue)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_PEER_SOCKET_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_peer_socket_impl.h
^
|
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_SOCKET_IMPL_H
+#define NFC_PEER_SOCKET_IMPL_H
+
+#include "nfc_peer_connection_impl.h"
+#include "nfc_peer_socket.h"
+
+G_BEGIN_DECLS
+
+/* Since 1.1.0 */
+
+/* Internal API for use by classes derived from NfcPeerSocket */
+
+typedef struct nfc_peer_socket_class {
+ NfcPeerConnectionClass parent;
+
+ /* Padding for future expansion */
+ void (*_reserved1)(void);
+ void (*_reserved2)(void);
+ void (*_reserved3)(void);
+ void (*_reserved4)(void);
+ void (*_reserved5)(void);
+} NfcPeerSocketClass;
+
+#define NFC_PEER_SOCKET_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
+ NFC_TYPE_PEER_SOCKET, NfcPeerSocketClass)
+
+gboolean
+nfc_peer_socket_init_connect(
+ NfcPeerSocket* socket,
+ NfcPeerService* service,
+ guint8 rsap,
+ const char* name)
+ NFCD_EXPORT;
+
+gboolean
+nfc_peer_socket_init_accept(
+ NfcPeerSocket* socket,
+ NfcPeerService* service,
+ guint8 rsap)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_PEER_SOCKET_IMPL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_plugin.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -62,13 +62,20 @@
const NfcPluginDesc* desc;
};
+GType nfc_plugin_get_type(void) NFCD_EXPORT;
+#define NFC_TYPE_PLUGIN (nfc_plugin_get_type())
+#define NFC_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ NFC_TYPE_PLUGIN, NfcPlugin))
+
NfcPlugin*
nfc_plugin_ref(
- NfcPlugin* plugin);
+ NfcPlugin* plugin)
+ NFCD_EXPORT;
void
nfc_plugin_unref(
- NfcPlugin* plugin);
+ NfcPlugin* plugin)
+ NFCD_EXPORT;
/*
* NFC_PLUGIN_DECLARE - declares NfcPluginDesc in a way compatible with
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_plugin_impl.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -54,11 +54,6 @@
void (*_reserved5)(void);
} NfcPluginClass;
-GType nfc_plugin_get_type(void);
-#define NFC_TYPE_PLUGIN (nfc_plugin_get_type())
-#define NFC_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
- NFC_TYPE_PLUGIN, NfcPlugin))
-
/*
* NFC_PLUGIN_DEFINE - simple way to define NfcPluginDesc with a single
* or no log module, and no flags.
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_system.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -14,8 +14,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -49,7 +49,8 @@
NfcLanguage*
nfc_system_language(
- void); /* Since 1.0.15 */
+ void) /* Since 1.0.15 */
+ NFCD_EXPORT;
#endif /* NFC_SYSTEM_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_tag.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -57,7 +57,7 @@
NfcNdefRec* ndef; /* Valid only when initialized */
};
-GType nfc_tag_get_type(void);
+GType nfc_tag_get_type(void) NFCD_EXPORT;
#define NFC_TYPE_TAG (nfc_tag_get_type())
#define NFC_TAG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_TAG, NfcTag))
@@ -70,42 +70,50 @@
NfcTag*
nfc_tag_ref(
- NfcTag* tag);
+ NfcTag* tag)
+ NFCD_EXPORT;
void
nfc_tag_unref(
- NfcTag* tag);
+ NfcTag* tag)
+ NFCD_EXPORT;
const NfcParamPoll*
nfc_tag_param(
- NfcTag* tag); /* Since 1.0.33 */
+ NfcTag* tag) /* Since 1.0.33 */
+ NFCD_EXPORT;
void
nfc_tag_deactivate(
- NfcTag* tag);
+ NfcTag* tag)
+ NFCD_EXPORT;
gulong
nfc_tag_add_gone_handler(
NfcTag* tag,
NfcTagFunc func,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
gulong
nfc_tag_add_initialized_handler(
NfcTag* tag,
NfcTagFunc func,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
void
nfc_tag_remove_handler(
NfcTag* tag,
- gulong id);
+ gulong id)
+ NFCD_EXPORT;
void
nfc_tag_remove_handlers(
NfcTag* tag,
gulong* ids,
- guint count);
+ guint count)
+ NFCD_EXPORT;
#define nfc_tag_remove_all_handlers(tag,ids) \
nfc_tag_remove_handlers(tag, ids, G_N_ELEMENTS(ids))
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_tag_t2.h
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -54,10 +55,10 @@
NFC_TAG_T2_FLAGS t2flags;
guint block_size; /* Valid only when initialized */
guint data_size; /* Valid only when initialized */
- GUtilData serial; /* Valid only when initialized */
+ GUtilData serial; /* Same as UID (nfcid1) */
};
-GType nfc_tag_t2_get_type();
+GType nfc_tag_t2_get_type() NFCD_EXPORT;
#define NFC_TYPE_TAG_T2 (nfc_tag_t2_get_type())
#define NFC_TAG_T2(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_TAG_T2, NfcTagType2))
@@ -90,7 +91,8 @@
guint block,
NfcTagType2ReadFunc resp,
GDestroyNotify destroy,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
guint
nfc_tag_t2_write(
@@ -100,7 +102,8 @@
GBytes* bytes,
NfcTagType2WriteFunc complete,
GDestroyNotify destroy,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
guint
nfc_tag_t2_write_seq(
@@ -111,7 +114,8 @@
NfcTargetSequence* seq,
NfcTagType2WriteFunc complete,
GDestroyNotify destroy,
- void* user_data); /* Since 1.0.17 */
+ void* user_data) /* Since 1.0.17 */
+ NFCD_EXPORT;
/*
* The methods belows read only the data part of the chip's memory,
@@ -153,7 +157,8 @@
guint maxbytes,
NfcTagType2ReadDataFunc resp,
GDestroyNotify destroy,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
guint
nfc_tag_t2_read_data_seq(
@@ -163,14 +168,16 @@
NfcTargetSequence* seq,
NfcTagType2ReadDataFunc resp,
GDestroyNotify destroy,
- void* user_data); /* Since 1.0.17 */
+ void* user_data) /* Since 1.0.17 */
+ NFCD_EXPORT;
NFC_TAG_T2_IO_STATUS
nfc_tag_t2_read_data_sync(
NfcTagType2* tag,
guint offset,
guint nbytes,
- void* buffer);
+ void* buffer)
+ NFCD_EXPORT;
guint
nfc_tag_t2_write_data(
@@ -179,7 +186,8 @@
GBytes* bytes,
NfcTagType2WriteDataFunc complete,
GDestroyNotify destroy,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
guint
nfc_tag_t2_write_data_seq(
@@ -189,7 +197,8 @@
NfcTargetSequence* seq,
NfcTagType2WriteDataFunc complete,
GDestroyNotify destroy,
- void* user_data); /* Since 1.0.17 */
+ void* user_data) /* Since 1.0.17 */
+ NFCD_EXPORT;
G_END_DECLS
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_tag_t4.h
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -42,30 +43,28 @@
G_BEGIN_DECLS
typedef struct nfc_tag_t4_priv NfcTagType4Priv;
+typedef union nfc_param_iso_dep NfcParamIsoDep;
struct nfc_tag_t4 {
NfcTag tag;
NfcTagType4Priv* priv;
+ /* Since 1.0.39 */
+ const NfcParamIsoDep* iso_dep;
};
-struct nfc_param_iso_dep_poll_a {
- guint fsc; /* FSC (FSDI converted to bytes) */
- GUtilData t1; /* T1 to Tk (aka historical bytes) */
-};
-
-GType nfc_tag_t4_get_type();
+GType nfc_tag_t4_get_type() NFCD_EXPORT;
#define NFC_TYPE_TAG_T4 (nfc_tag_t4_get_type())
#define NFC_IS_TAG_T4(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, NFC_TYPE_TAG_T4)
#define NFC_TAG_T4(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NFC_TYPE_TAG_T4, \
NfcTagType4))
-GType nfc_tag_t4a_get_type();
+GType nfc_tag_t4a_get_type() NFCD_EXPORT;
#define NFC_TYPE_TAG_T4A (nfc_tag_t4a_get_type())
#define NFC_IS_TAG_T4A(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, NFC_TYPE_TAG_T4A)
#define NFC_TAG_T4A(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NFC_TYPE_TAG_T4A, \
NfcTagType4a))
-GType nfc_tag_t4b_get_type();
+GType nfc_tag_t4b_get_type() NFCD_EXPORT;
#define NFC_TYPE_TAG_T4B (nfc_tag_t4b_get_type())
#define NFC_IS_TAG_T4B(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, NFC_TYPE_TAG_T4B)
#define NFC_TAG_T4B(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NFC_TYPE_TAG_T4B, \
@@ -83,6 +82,41 @@
*/
#define ISO_SW_IO_ERR (0)
+/* ISO-DEP activation parameter */
+
+typedef struct nfc_param_iso_dep_poll_a {
+ guint fsc; /* FSC (FSDI converted to bytes) */
+ GUtilData t1; /* T1 to Tk (aka historical bytes) */
+ /* Since 1.0.39 */
+ guint8 t0; /* Format byte T0 */
+
+ /*
+ * NFC-Forum-TS-DigitalProtocol 1.0
+ * Table 65: Coding of Format Byte T0
+ *
+ * Presence of interface bytes within NFC-A/ISO-DEP Poll activation
+ * parameter is determined with bits of Format Byte set to '1'
+ */
+#define NFC_PARAM_ISODEP_T0_A (0x10) /* TA is transmitted */
+#define NFC_PARAM_ISODEP_T0_B (0x20) /* TB is transmitted */
+#define NFC_PARAM_ISODEP_T0_C (0x40) /* TC is transmitted */
+
+ guint8 ta; /* Interface byte TA (optional) */
+ guint8 tb; /* Interface byte TB (optional) */
+ guint8 tc; /* Interface byte TC (optional) */
+} NfcParamIsoDepPollA; /* Since 1.0.20 */
+
+typedef struct nfc_param_iso_dep_poll_b {
+ guint mbli; /* Maximum buffer length index */
+ guint did; /* Device ID */
+ GUtilData hlr; /* Higher Layer Response */
+} NfcParamIsoDepPollB; /* Since 1.0.39 */
+
+union nfc_param_iso_dep {
+ NfcParamIsoDepPollA a;
+ NfcParamIsoDepPollB b;
+}; /* Since 1.0.39 */
+
typedef
void
(*NfcTagType4ResponseFunc)(
@@ -92,6 +126,13 @@
guint len,
void* user_data);
+typedef
+void
+(*NfcTagType4ResetRespFunc)(
+ NfcTagType4* tag,
+ gboolean ok,
+ void* user_data);
+
guint
nfc_isodep_transmit(
NfcTagType4* tag,
@@ -104,7 +145,17 @@
NfcTargetSequence* seq,
NfcTagType4ResponseFunc resp,
GDestroyNotify destroy,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
+
+gboolean
+nfc_isodep_reset(
+ NfcTagType4* tag,
+ NfcTargetSequence* seq,
+ NfcTagType4ResetRespFunc resp,
+ GDestroyNotify destroy,
+ void* user_data) /* Since 1.0.44 */
+ NFCD_EXPORT;
G_END_DECLS
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_target.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -60,7 +60,7 @@
NfcTargetSequence* sequence;
};
-GType nfc_target_get_type(void);
+GType nfc_target_get_type(void) NFCD_EXPORT;
#define NFC_TYPE_TARGET (nfc_target_get_type())
#define NFC_TARGET(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_TARGET, NfcTarget))
@@ -82,28 +82,44 @@
NfcTarget*
nfc_target_ref(
- NfcTarget* target);
+ NfcTarget* target)
+ NFCD_EXPORT;
void
nfc_target_unref(
- NfcTarget* target);
+ NfcTarget* target)
+ NFCD_EXPORT;
+
+/*
+ * -1: Use default timeout
+ * 0: No timeout at all
+ * >0: Transmision timeout in milliseconds
+ */
+void
+nfc_target_set_transmit_timeout(
+ NfcTarget* target,
+ int ms) /* Since 1.0.37 */
+ NFCD_EXPORT;
gulong
nfc_target_add_sequence_handler(
NfcTarget* target,
NfcTargetFunc func,
- void* user_data); /* Since 1.0.17 */
+ void* user_data) /* Since 1.0.17 */
+ NFCD_EXPORT;
void
nfc_target_remove_handler(
NfcTarget* target,
- gulong id); /* Since 1.0.17 */
+ gulong id) /* Since 1.0.17 */
+ NFCD_EXPORT;
void
nfc_target_remove_handlers(
NfcTarget* target,
gulong* ids,
- guint count); /* Since 1.0.17 */
+ guint count) /* Since 1.0.17 */
+ NFCD_EXPORT;
#define nfc_target_remove_all_handlers(target,ids) \
nfc_target_remove_handlers(target, ids, G_N_ELEMENTS(ids))
@@ -118,11 +134,13 @@
NfcTargetSequence*
nfc_target_sequence_new(
- NfcTarget* target); /* Since 1.0.17 */
+ NfcTarget* target) /* Since 1.0.17 */
+ NFCD_EXPORT;
void
nfc_target_sequence_free(
- NfcTargetSequence* seq); /* Since 1.0.17 */
+ NfcTargetSequence* seq) /* Since 1.0.17 */
+ NFCD_EXPORT;
/*
* These functions can be used for sending internal requests (e.g. presence
@@ -137,12 +155,14 @@
NfcTargetSequence* seq,
NfcTargetTransmitFunc complete,
GDestroyNotify destroy,
- void* user_data);
+ void* user_data)
+ NFCD_EXPORT;
gboolean
nfc_target_cancel_transmit(
NfcTarget* target,
- guint id);
+ guint id)
+ NFCD_EXPORT;
G_END_DECLS
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_target_impl.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -83,15 +83,18 @@
NfcTarget* target,
NFC_TRANSMIT_STATUS status,
const void* data,
- guint len);
+ guint len)
+ NFCD_EXPORT;
void
nfc_target_reactivated(
- NfcTarget* target); /* Since 1.0.27 */
+ NfcTarget* target) /* Since 1.0.27 */
+ NFCD_EXPORT;
void
nfc_target_gone(
- NfcTarget* target);
+ NfcTarget* target)
+ NFCD_EXPORT;
G_END_DECLS
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_types.h
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -40,9 +41,14 @@
/* Types */
typedef struct nfc_adapter NfcAdapter;
-typedef struct nfc_language NfcLanguage; /* Since 1.0.15 */
+typedef struct nfc_initiator NfcInitiator; /* Since 1.1.0 */
+typedef struct nfc_language NfcLanguage; /* Since 1.0.15 */
+typedef struct nfc_peer_connection NfcPeerConnection; /* Since 1.1.0 */
+typedef struct nfc_peer_service NfcPeerService; /* Since 1.1.0 */
+typedef struct nfc_peer_socket NfcPeerSocket; /* Since 1.1.0 */
typedef struct nfc_ndef_rec NfcNdefRec;
typedef struct nfc_manager NfcManager;
+typedef struct nfc_peer NfcPeer; /* Since 1.1.0 */
typedef struct nfc_plugin NfcPlugin;
typedef struct nfc_plugin_desc NfcPluginDesc;
typedef struct nfc_tag NfcTag;
@@ -53,8 +59,11 @@
typedef struct nfc_target NfcTarget;
typedef struct nfc_target_sequence NfcTargetSequence;
+typedef struct nfc_param_listen_a NfcParamListenA; /* Since 1.1.0 */
typedef struct nfc_param_iso_dep_poll_a NfcParamIsoDepPollA; /* Since 1.0.20 */
typedef struct nfc_param_iso_dep_poll_b NfcParamIsoDepPollB; /* Since 1.0.20 */
+typedef struct nfc_param_nfc_dep_initator NfcParamNfcDepInitiator; /* 1.1.0 */
+typedef struct nfc_param_nfc_dep_target NfcParamNfcDepTarget; /* 1.1.0 */
/* Constants */
@@ -68,6 +77,11 @@
NFC_MODE_CARD_EMILATION = 0x08
} NFC_MODE;
+/* Combined modes (since 1.1.0) */
+#define NFC_MODES_P2P (NFC_MODE_P2P_INITIATOR | NFC_MODE_P2P_TARGET)
+#define NFC_MODES_ALL (NFC_MODE_P2P_INITIATOR | NFC_MODE_P2P_TARGET | \
+ NFC_MODE_READER_WRITER | NFC_MODE_CARD_EMILATION)
+
typedef enum nfc_technology {
NFC_TECHNOLOGY_UNKNOWN = 0x00,
NFC_TECHNOLOGY_A = 0x01, /* NFC-A */
@@ -100,6 +114,21 @@
NFC_TRANSMIT_STATUS_TIMEOUT /* No response from NFCC */
} NFC_TRANSMIT_STATUS;
+typedef enum nfc_peer_connect_result {
+ NFC_PEER_CONNECT_OK, /* Connection was successful */
+ NFC_PEER_CONNECT_DUP, /* Duplicate connection */
+ NFC_PEER_CONNECT_CANCELLED, /* Connection cancelled */
+ NFC_PEER_CONNECT_NO_SERVICE, /* Service not found */
+ NFC_PEER_CONNECT_REJECTED, /* Connection rejected */
+ NFC_PEER_CONNECT_FAILED /* I/O or protocol error */
+} NFC_PEER_CONNECT_RESULT;
+
+typedef enum nfc_llcp_version {
+ NFC_LLCP_VERSION_1_0 = 0x10,
+ NFC_LLCP_VERSION_1_1 = 0x11,
+ NFC_LLCP_VERSION_1_2 = 0x12
+} NFC_LLCP_VERSION; /* Since 1.1.1 */
+
/* RF technology specific parameters */
typedef struct nfc_param_poll_a {
@@ -111,16 +140,44 @@
typedef struct nfc_param_poll_b {
guint fsc; /* FSC (FSCI converted to bytes) */
GUtilData nfcid0;
+ /* Since 1.0.40 */
+ /*
+ * NFCForum-TS-DigitalProtocol-1.0
+ * Table 25: SENSB_RES Format
+ */
+ guint8 app_data[4];
+ GUtilData prot_info;
} NfcParamPollB; /* Since 1.0.20 */
+typedef struct nfc_param_poll_f {
+ guint bitrate; /* In kbps, zero if unknown */
+ GUtilData nfcid2; /* Bytes 2-9 of SENSF_RES */
+} NfcParamPollF; /* Since 1.1.0 */
+
+typedef struct nfc_param_listen_f {
+ GUtilData nfcid2; /* NFCID2 generated by the Local NFCC */
+} NfcParamListenF; /* Since 1.1.0 */
+
typedef union nfc_param_poll {
NfcParamPollA a;
NfcParamPollB b;
+ NfcParamPollF f;
} NfcParamPoll; /* Since 1.0.33 */
+/* Mark functions exported to plugins as weak */
+#ifndef NFCD_EXPORT
+# define NFCD_EXPORT __attribute__((weak))
+#endif
+
/* Logging */
#define NFC_CORE_LOG_MODULE nfc_core_log
-extern GLogModule NFC_CORE_LOG_MODULE;
+#define NFC_LLC_LOG_MODULE nfc_llc_log
+#define NFC_PEER_LOG_MODULE nfc_peer_log
+#define NFC_SNEP_LOG_MODULE nfc_snep_log
+extern GLogModule NFC_CORE_LOG_MODULE NFCD_EXPORT;
+extern GLogModule NFC_LLC_LOG_MODULE NFCD_EXPORT; /* Since 1.1.0 */
+extern GLogModule NFC_PEER_LOG_MODULE NFCD_EXPORT; /* Since 1.1.0 */
+extern GLogModule NFC_SNEP_LOG_MODULE NFCD_EXPORT; /* Since 1.1.0 */
G_END_DECLS
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/include/nfc_version.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -34,8 +34,8 @@
#define NFC_VERSION_H
#define NFC_VERSION_MAJOR 1
-#define NFC_VERSION_MINOR 0
-#define NFC_VERSION_NANO 35
+#define NFC_VERSION_MINOR 1
+#define NFC_VERSION_NANO 2
#define NFC_VERSION_WORD(v1,v2,v3) \
((((v1) & 0x7f) << 24) | \
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/nfcd-plugin.pc.in
^
|
@@ -4,5 +4,5 @@
Name: ${name}
Description: Header files for building ${name} plugins
Version: @version@
-Requires: glib-2.0
+Requires.private: glib-2.0
Cflags: -I${includedir} -I${includedir}/${name}
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_adapter.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -32,10 +32,12 @@
#define GLIB_DISABLE_DEPRECATION_WARNINGS
-#include "nfc_adapter_impl.h"
#include "nfc_adapter_p.h"
+#include "nfc_adapter_impl.h"
+#include "nfc_peer_services.h"
#include "nfc_tag_p.h"
#include "nfc_tag_t4_p.h"
+#include "nfc_peer_p.h"
#include "nfc_log.h"
#include <gutil_misc.h>
@@ -43,22 +45,31 @@
#include <stdlib.h>
#define NFC_TAG_NAME_FORMAT "tag%u"
+#define NFC_PEER_NAME_FORMAT "peer%u"
typedef struct nfc_adapter_tag_entry {
NfcTag* tag;
gulong gone_id;
} NfcAdapterTagEntry;
+typedef struct nfc_adapter_peer_entry {
+ NfcPeer* peer;
+ gulong gone_id;
+} NfcAdapterPeerEntry;
+
struct nfc_adapter_priv {
char* name;
- GHashTable* tags;
+ NfcPeerServices* services;
+ GHashTable* tag_table;
+ GHashTable* peer_table;
+ NfcPeer** peers;
guint next_tag_index;
+ guint next_peer_index;
guint32 pending_signals;
NFC_MODE mode_submitted;
gboolean mode_pending;
gboolean power_submitted;
gboolean power_pending;
- gboolean target_presence_notified;
};
G_DEFINE_ABSTRACT_TYPE(NfcAdapter, nfc_adapter, G_TYPE_OBJECT)
@@ -74,6 +85,8 @@
SIGNAL_MODE,
SIGNAL_MODE_REQUESTED,
SIGNAL_TARGET_PRESENCE,
+ SIGNAL_PEER_ADDED,
+ SIGNAL_PEER_REMOVED,
SIGNAL_COUNT
};
@@ -87,12 +100,14 @@
#define SIGNAL_MODE_NAME "nfc-adapter-mode"
#define SIGNAL_MODE_REQUESTED_NAME "nfc-adapter-mode-requested"
#define SIGNAL_TARGET_PRESENCE_NAME "nfc-adapter-target-presence"
+#define SIGNAL_PEER_ADDED_NAME "nfc-adapter-peer-added"
+#define SIGNAL_PEER_REMOVED_NAME "nfc-adapter-peer-removed"
static guint nfc_adapter_signals[SIGNAL_COUNT] = { 0 };
-#define NEW_SIGNAL(name) nfc_adapter_signals[SIGNAL_##name] = \
- g_signal_new(SIGNAL_##name##_NAME, G_OBJECT_CLASS_TYPE(klass), \
- G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0)
+#define NEW_SIGNAL(name,type) nfc_adapter_signals[SIGNAL_##name] = \
+ g_signal_new(SIGNAL_##name##_NAME, type, G_SIGNAL_RUN_FIRST, \
+ 0, NULL, NULL, NULL, G_TYPE_NONE, 0)
static
void
@@ -142,17 +157,19 @@
}
static
-NfcTag**
-nfc_adapter_tags(
- NfcAdapterPriv* priv)
+void
+nfc_adapter_update_tags(
+ NfcAdapter* self)
{
- const guint count = g_hash_table_size(priv->tags);
- NfcTag** out = g_new(NfcTag*, count + 1);
- NfcTag** ptr = out;
+ NfcAdapterPriv* priv = self->priv;
+ const guint count = g_hash_table_size(priv->tag_table);
+ NfcTag** ptr;
GHashTableIter iter;
gpointer value;
- g_hash_table_iter_init(&iter, priv->tags);
+ g_free(self->tags);
+ ptr = self->tags = g_new(NfcTag*, count + 1);
+ g_hash_table_iter_init(&iter, priv->tag_table);
while (g_hash_table_iter_next(&iter, NULL, &value)) {
NfcAdapterTagEntry* entry = value;
*ptr++ = entry->tag;
@@ -160,26 +177,80 @@
*ptr = NULL;
/* Sort tags by name */
- qsort(out, count, sizeof(NfcTag*), nfc_adapter_compare_tags);
- return out;
+ qsort(self->tags, count, sizeof(NfcTag*), nfc_adapter_compare_tags);
+}
+
+static
+int
+nfc_adapter_compare_peers(
+ const void* p1,
+ const void* p2)
+{
+ NfcPeer* a1 = *(NfcPeer* const*)p1;
+ NfcPeer* a2 = *(NfcPeer* const*)p2;
+
+ return strcmp(a1->name, a2->name);
}
static
void
-nfc_adapter_update_target_presence(
+nfc_adapter_update_peers(
+ NfcAdapterPriv* priv)
+{
+ const guint count = g_hash_table_size(priv->peer_table);
+ NfcPeer** ptr;
+ GHashTableIter iter;
+ gpointer value;
+
+ g_free(priv->peers);
+ ptr = priv->peers = g_new(NfcPeer*, count + 1);
+ g_hash_table_iter_init(&iter, priv->peer_table);
+ while (g_hash_table_iter_next(&iter, NULL, &value)) {
+ NfcAdapterPeerEntry* entry = value;
+ *ptr++ = entry->peer;
+ }
+ *ptr = NULL;
+
+ /* Sort peers by name */
+ qsort(priv->peers, count, sizeof(NfcPeer*), nfc_adapter_compare_peers);
+}
+
+static
+void
+nfc_adapter_set_presence(
+ NfcAdapter* self,
+ gboolean present)
+{
+ if (self->target_present != present) {
+ self->target_present = present;
+ GDEBUG("Target %s", present ? "detected" : "disappeared");
+ nfc_adapter_queue_signal(self, SIGNAL_TARGET_PRESENCE);
+ }
+}
+
+static
+void
+nfc_adapter_update_presence(
NfcAdapter* self)
{
- /* Target detection flag should still work even if implementation
- * never calls nfc_adapter_target_notify */
NfcAdapterPriv* priv = self->priv;
- const gboolean detected = priv->target_presence_notified ||
- g_hash_table_size(priv->tags);
+ gboolean present = FALSE;
+ GHashTableIter it;
+ gpointer value;
- if (self->target_present != detected) {
- self->target_present = detected;
- GDEBUG("Target %s", detected ? "detected" : "disappeared");
- nfc_adapter_queue_signal(self, SIGNAL_TARGET_PRESENCE);
+ g_hash_table_iter_init(&it, priv->tag_table);
+ while (g_hash_table_iter_next(&it, NULL, &value) && !present) {
+ present = ((NfcAdapterTagEntry*)value)->tag->present;
+ }
+
+ if (!present) {
+ g_hash_table_iter_init(&it, priv->peer_table);
+ while (g_hash_table_iter_next(&it, NULL, &value) && !present) {
+ present = ((NfcAdapterPeerEntry*)value)->peer->present;
+ }
}
+
+ nfc_adapter_set_presence(self, present);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_adapter_p.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -38,11 +38,22 @@
#include <nfc_adapter.h>
void
+nfc_adapter_set_enabled(
+ NfcAdapter* adapter,
+ gboolean enabled); /* It used to be public and stays exported */
+
+void
nfc_adapter_set_name(
NfcAdapter* adapter,
const char* name)
NFCD_INTERNAL;
+void
+nfc_adapter_set_services(
+ NfcAdapter* adapter,
+ NfcPeerServices* services)
+ NFCD_INTERNAL;
+
#endif /* NFC_ADAPTER_PRIVATE_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_core.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,6 +30,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "nfc_types_p.h"
#include "nfc_core.h"
#include "nfc_version.h"
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_crc.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018 Jolla Ltd.
- * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -14,8 +14,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -30,6 +30,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "nfc_types_p.h"
#include "nfc_crc.h"
/*
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_initiator.c
^
|
@@ -0,0 +1,482 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
+#include "nfc_initiator_p.h"
+#include "nfc_initiator_impl.h"
+#include "nfc_log.h"
+
+#include <gutil_misc.h>
+
+struct nfc_initiator_priv {
+ NfcTransmission* current; /* Pointer */
+ NfcTransmission* next; /* Reference */
+ GBytes* next_data;
+ gboolean deactivated;
+};
+
+#define THIS(obj) NFC_INITIATOR(obj)
+#define THIS_TYPE NFC_TYPE_INITIATOR
+#define PARENT_CLASS (nfc_initiator_parent_class)
+G_DEFINE_ABSTRACT_TYPE(NfcInitiator, nfc_initiator, G_TYPE_OBJECT)
+#define NFC_INITIATOR_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), \
+ THIS_TYPE, NfcInitiatorClass)
+
+enum nfc_initiator_signal {
+ SIGNAL_TRANSMISSION,
+ SIGNAL_GONE,
+ SIGNAL_COUNT
+};
+
+#define SIGNAL_TRANSMISSION_NAME "nfc-initiator-transmission"
+#define SIGNAL_GONE_NAME "nfc-initiator-gone"
+
+static guint nfc_initiator_signals[SIGNAL_COUNT] = { 0 };
+
+struct nfc_transmission {
+ NfcInitiator* owner;
+ NfcTransmissionDoneFunc done;
+ void* user_data;
+ gboolean responded;
+ gint ref_count;
+};
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+inline
+gboolean
+nfc_initiator_can_deactivate(
+ NfcInitiator* self)
+{
+ return self->present && !self->priv->deactivated;
+}
+
+static
+void
+nfc_initiator_do_deactivate(
+ NfcInitiator* self)
+{
+ /* Caller has checked nfc_initiator_can_deactivate() */
+ self->priv->deactivated = TRUE;
+ NFC_INITIATOR_GET_CLASS(self)->deactivate(self);
+}
+
+/*==========================================================================*
+ * Transmission API
+ *==========================================================================*/
+
+static
+NfcTransmission*
+nfc_transmission_new(
+ NfcInitiator* initiator)
+{
+ NfcTransmission* self = g_slice_new0(NfcTransmission);
+
+ self->owner = initiator;
+ g_atomic_int_set(&self->ref_count, 1);
+ return self;
+}
+
+static
+void
+nfc_transmission_free(
+ NfcTransmission* self)
+{
+ NfcInitiator* owner = self->owner;
+
+ if (owner) {
+ NfcInitiatorPriv* priv = owner->priv;
+
+ /*
+ * Clear the pointer. Note that priv->next is an internal reference
+ * meaning that NfcTransmission pointed to by priv->next can't get
+ * here before pointer is cleared and reference is released.
+ * Therefore, there's no need to check priv->next.
+ */
+ if (priv->current == self) {
+ priv->current = NULL;
+ if (!self->responded && nfc_initiator_can_deactivate(owner)) {
+ /* Transmission was dropped without responding */
+ GDEBUG("Transmission dropped, deactivating");
+ nfc_initiator_do_deactivate(owner);
+ }
+ }
+ }
+ g_slice_free1(sizeof(*self), self);
+}
+
+NfcTransmission*
+nfc_transmission_ref(
+ NfcTransmission* self)
+{
+ if (G_LIKELY(self)) {
+ g_atomic_int_inc(&self->ref_count);
+ }
+ return self;
+}
+
+void
+nfc_transmission_unref(
+ NfcTransmission* self)
+{
+ if (G_LIKELY(self)) {
+ if (g_atomic_int_dec_and_test(&self->ref_count)) {
+ nfc_transmission_free(self);
+ }
+ }
+}
+
+gboolean
+nfc_transmission_respond(
+ NfcTransmission* self,
+ const void* data,
+ guint len,
+ NfcTransmissionDoneFunc done,
+ void* user_data)
+{
+ if (G_LIKELY(self && !self->responded)) {
+ NfcInitiator* owner = self->owner;
+
+ self->responded = TRUE;
+ if (owner) {
+ self->done = done;
+ self->user_data = user_data;
+ nfc_transmission_ref(self);
+ if (NFC_INITIATOR_GET_CLASS(owner)->respond(owner, data, len)) {
+ nfc_transmission_unref(self);
+ return TRUE;
+ }
+ self->done = NULL;
+ nfc_transmission_unref(self);
+ }
+ }
+ return FALSE;
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NfcInitiator*
+nfc_initiator_ref(
+ NfcInitiator* self)
+{
+ if (G_LIKELY(self)) {
+ g_object_ref(THIS(self));
+ }
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_initiator_p.h
^
|
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_INITIATOR_PRIVATE_H
+#define NFC_INITIATOR_PRIVATE_H
+
+#include "nfc_types_p.h"
+
+#include <nfc_initiator.h>
+
+typedef struct nfc_transmission NfcTransmission;
+
+typedef
+void
+(*NfcInitiatorFunc)(
+ NfcInitiator* initiator,
+ void* user_data);
+
+typedef
+gboolean
+(*NfcTransmissionHandlerFunc)(
+ NfcInitiator* initiator,
+ NfcTransmission* transmission,
+ const GUtilData* data,
+ void* user_data);
+
+typedef
+void
+(*NfcTransmissionDoneFunc)(
+ NfcTransmission* transmission,
+ gboolean ok,
+ void* user_data);
+
+void
+nfc_initiator_deactivate(
+ NfcInitiator* initiator)
+ NFCD_INTERNAL;
+
+gulong
+nfc_initiator_add_transmission_handler(
+ NfcInitiator* initiator,
+ NfcTransmissionHandlerFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+gulong
+nfc_initiator_add_gone_handler(
+ NfcInitiator* initiator,
+ NfcInitiatorFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+void
+nfc_initiator_remove_handler(
+ NfcInitiator* initiator,
+ gulong id)
+ NFCD_INTERNAL;
+
+void
+nfc_initiator_remove_handlers(
+ NfcInitiator* initiator,
+ gulong* ids,
+ guint count)
+ NFCD_INTERNAL;
+
+#define nfc_initiator_remove_all_handlers(initiator,ids) \
+ nfc_initiator_remove_handlers(initiator, ids, G_N_ELEMENTS(ids))
+
+/*
+ * Incoming transmission API
+ */
+
+NfcTransmission*
+nfc_transmission_ref(
+ NfcTransmission* transmission)
+ NFCD_INTERNAL;
+
+void
+nfc_transmission_unref(
+ NfcTransmission* transmission)
+ NFCD_INTERNAL;
+
+gboolean
+nfc_transmission_respond(
+ NfcTransmission* transmission,
+ const void* data,
+ guint len,
+ NfcTransmissionDoneFunc done,
+ void* user_data)
+ NFCD_INTERNAL;
+
+#endif /* NFC_INITIATOR_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_llc.c
^
|
@@ -0,0 +1,1854 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_llc.h"
+#include "nfc_llc_io.h"
+#include "nfc_llc_param.h"
+#include "nfc_peer_connection_p.h"
+#include "nfc_peer_service_p.h"
+#include "nfc_peer_services.h"
+
+#define GLOG_MODULE_NAME NFC_LLC_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_idlepool.h>
+#include <gutil_misc.h>
+#include <gutil_macros.h>
+
+#include <glib-object.h>
+#include <stdlib.h>
+
+GLOG_MODULE_DEFINE2("llc", NFC_CORE_LOG_MODULE);
+
+typedef enum llcp_ptype {
+ LLCP_PTYPE_SYMM = 0x00,
+ LLCP_PTYPE_PAX = 0x01,
+ LLCP_PTYPE_AGF = 0x02,
+ LLCP_PTYPE_UI = 0x03,
+ LLCP_PTYPE_CONNECT = 0x04,
+ LLCP_PTYPE_DISC = 0x05,
+ LLCP_PTYPE_CC = 0x06,
+ LLCP_PTYPE_DM = 0x07,
+ LLCP_PTYPE_FRMR = 0x08,
+ LLCP_PTYPE_SNL = 0x09, /* LLCP 1.1 */
+ /* Reserved 0x0a*/
+ /* Reserved 0x0b*/
+ LLCP_PTYPE_I = 0x0c,
+ LLCP_PTYPE_RR = 0x0d,
+ LLCP_PTYPE_RNR = 0x0e
+} LLCP_PTYPE;
+
+typedef enum llc_frmr_flags {
+ NFC_LLC_FRMR_S = 0x01,
+ NFC_LLC_FRMR_R = 0x02,
+ NFC_LLC_FRMR_I = 0x04,
+ NFC_LLC_FRMR_W = 0x08
+} NFC_LLC_FRMR_FLAGS;
+
+#define LLCP_MAKE_HDR(dsap,ptype,ssap) \
+ (((((guint16)(dsap)) & 0x3f) << 10) | \
+ (((guint16)(ptype)) << 6) /* Assuming PTYPE is within range */| \
+ (((guint16)(ssap)) & 0x3f))
+#define LLCP_GET_DSAP(hdr) ((guint8)((hdr) >> 10))
+#define LLCP_GET_PTYPE(hrd) ((LLCP_PTYPE)(((hdr) >> 6) & 0x0f))
+#define LLCP_GET_SSAP(hdr) ((guint8)((hdr) & 0x3f))
+
+enum nfc_llc_io_events {
+ LLC_IO_EVENT_CAN_SEND,
+ LLC_IO_EVENT_RECEIVE,
+ LLC_IO_EVENT_ERROR,
+ LLC_IO_EVENT_COUNT
+};
+
+typedef struct nfc_llc_connect_req {
+ NfcPeerConnection* connection;
+ NfcLlcConnectFunc complete;
+ GDestroyNotify destroy;
+ void* user_data;
+} NfcLlcConnectReq;
+
+typedef struct nfc_llc_object {
+ GObject object;
+ NfcLlc pub;
+ NfcLlcIo* io;
+ gulong io_event[LLC_IO_EVENT_COUNT];
+ GUtilIdlePool* pool;
+ NfcPeerServices* services;
+ guint8 version;
+ guint miu;
+ guint lto;
+ guint packets_handled;
+ GList* pdu_queue;
+ GSList* connect_queue;
+ GHashTable* conn_table;
+} NfcLlcObject;
+
+typedef GObjectClass NfcLlcObjectClass;
+G_DEFINE_TYPE(NfcLlcObject, nfc_llc_object, G_TYPE_OBJECT)
+#define NFC_TYPE_LLC (nfc_llc_object_get_type())
+#define NFC_LLC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ NFC_TYPE_LLC, NfcLlcObject))
+
+typedef enum nfc_llc_signal {
+ SIGNAL_STATE_CHANGED,
+ SIGNAL_IDLE_CHANGED,
+ SIGNAL_WKS_CHANGED,
+ SIGNAL_COUNT
+} NFC_LLC_SIGNAL;
+
+typedef struct nfc_llc_closure {
+ GCClosure cclosure;
+ NfcLlcFunc func;
+ void* user_data;
+} NfcLlcClosure;
+
+#define nfc_llc_closure_new() ((NfcLlcClosure*) \
+ g_closure_new_simple(sizeof(NfcLlcClosure), NULL))
+
+#define SIGNAL_STATE_CHANGED_NAME "nfc-llc-state-changed"
+#define SIGNAL_IDLE_CHANGED_NAME "nfc-llc-idle-changed"
+#define SIGNAL_WKS_CHANGED_NAME "nfc-llc-wks-changed"
+
+static guint nfc_llc_signals[SIGNAL_COUNT] = { 0 };
+
+static
+void
+nfc_llc_send_next_pdu(
+ NfcLlcObject* self);
+
+static
+gboolean
+nfc_llc_handle_pdu(
+ NfcLlcObject* self,
+ const void* data,
+ gsize len);
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+inline
+NfcLlcObject*
+nfc_llc_object_cast(
+ NfcLlc* llc)
+{
+ return llc ? NFC_LLC(G_CAST(llc,NfcLlcObject,pub)) : NULL;
+}
+
+static
+void
+nfc_llc_closure_callback(
+ NfcLlcObject* self,
+ NfcLlcClosure* closure)
+{
+ closure->func(&self->pub, closure->user_data);
+}
+
+static
+gulong
+nfc_llc_add_handler(
+ NfcLlc* llc,
+ NFC_LLC_SIGNAL signal,
+ NfcLlcFunc func,
+ void* user_data)
+{
+ NfcLlcObject* self = nfc_llc_object_cast(llc);
+
+ if (G_LIKELY(self) && G_LIKELY(func)) {
+ NfcLlcClosure* closure = nfc_llc_closure_new();
+ GCClosure* cc = &closure->cclosure;
+
+ cc->closure.data = closure;
+ cc->callback = G_CALLBACK(nfc_llc_closure_callback);
+ closure->func = func;
+ closure->user_data = user_data;
+ return g_signal_connect_closure_by_id(self, nfc_llc_signals
+ [signal], 0, &cc->closure, FALSE);
+ }
+ return 0;
+}
+
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_llc.h
^
|
@@ -0,0 +1,239 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_LLC_H
+#define NFC_LLC_H
+
+#include "nfc_types_p.h"
+
+typedef enum nfc_llc_flags {
+ NFC_LLC_FLAGS_NONE = 0x00,
+ NFC_LLC_FLAG_INITIATOR = 0x01 /* Otherwise Target */
+} NFC_LLC_FLAGS;
+
+/*
+ * NFCForum-TS-LLCP_1.1
+ * 4.3.8 Disconnected Mode (DM)
+ * Table 4: Disconnected Mode Reasons
+ */
+typedef enum nfc_llc_dm_reason {
+ /* The LLC has received a DISC PDU and is now logically disconnected
+ * from the data link connection. */
+ NFC_LLC_DM_DISC_RECEIVED = 0x00,
+ /* The LLC has received a connection-oriented PDU but the target
+ * service access point has no active connection. */
+ NFC_LLC_DM_NOT_CONNECTED = 0x01,
+ /* The remote LLC has received a CONNECT PDU and there is no service
+ * bound to the specified target service access point. */
+ NFC_LLC_DM_NO_SERVICE = 0x02,
+ /* The remote LLC has processed a CONNECT PDU and the request to
+ * connect was rejected by the service layer. */
+ NFC_LLC_DM_REJECT = 0x03
+} NFC_LLC_DM_REASON;
+
+/*
+ * LLC Link Management state machine:
+ *
+ * +=======+
+ * +---> | ERROR | <---+
+ * | +=======+ |
+ * protocol protocol
+ * error error
+ * | |
+ * +-------+ +--------+
+ * | START | -- ok --> | ACTIVE |
+ * +-------+ +--------+
+ * | |
+ * transmit transmit
+ * error error
+ * | +===========+ |
+ * +-> | PEER_LOST | <-+
+ * +===========+
+ */
+typedef enum nfc_llc_state {
+ NFC_LLC_STATE_START, /* Initial state */
+ NFC_LLC_STATE_ACTIVE, /* Functional state */
+ NFC_LLC_STATE_ERROR, /* Terminal state */
+ NFC_LLC_STATE_PEER_LOST /* Terminal state */
+} NFC_LLC_STATE;
+
+struct nfc_llc {
+ NFC_LLC_STATE state;
+ gboolean idle;
+ guint wks; /* Remote well-known services (mask) */
+};
+
+typedef
+void
+(*NfcLlcFunc)(
+ NfcLlc* llc,
+ void* user_data);
+
+typedef
+void
+(*NfcLlcConnectFunc)(
+ NfcPeerConnection* conn,
+ NFC_PEER_CONNECT_RESULT result,
+ void* user_data);
+
+NfcLlc*
+nfc_llc_new(
+ NfcLlcIo* io,
+ NfcPeerServices* services,
+ const NfcLlcParam* const* params)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_free(
+ NfcLlc* llc)
+ NFCD_INTERNAL;
+
+NfcPeerConnection*
+nfc_llc_connect(
+ NfcLlc* llc,
+ NfcPeerService* service,
+ guint rsap,
+ NfcLlcConnectFunc complete,
+ GDestroyNotify destroy,
+ void* user_data)
+ NFCD_INTERNAL;
+
+NfcPeerConnection*
+nfc_llc_connect_sn(
+ NfcLlc* llc,
+ NfcPeerService* service,
+ const char* sn,
+ NfcLlcConnectFunc complete,
+ GDestroyNotify destroy,
+ void* user_data)
+ NFCD_INTERNAL;
+
+gulong
+nfc_llc_add_state_changed_handler(
+ NfcLlc* llc,
+ NfcLlcFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+gulong
+nfc_llc_add_idle_changed_handler(
+ NfcLlc* llc,
+ NfcLlcFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+gulong
+nfc_llc_add_wks_changed_handler(
+ NfcLlc* llc,
+ NfcLlcFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_remove_handler(
+ NfcLlc* llc,
+ gulong id)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_remove_handlers(
+ NfcLlc* llc,
+ gulong* ids,
+ guint count)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_ack(
+ NfcLlc* llc,
+ NfcPeerConnection* conn,
+ gboolean last)
+ NFCD_INTERNAL;
+
+gboolean
+nfc_llc_i_pdu_queued(
+ NfcLlc* llc,
+ NfcPeerConnection* conn)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_submit_dm_pdu(
+ NfcLlc* llc,
+ guint8 dsap,
+ guint8 ssap,
+ NFC_LLC_DM_REASON reason)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_submit_disc_pdu(
+ NfcLlc* llc,
+ guint8 dsap,
+ guint8 ssap)
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_llc_io.c
^
|
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_llc_io_impl.h"
+
+#define GLOG_MODULE_NAME NFC_LLC_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_misc.h>
+
+#define THIS(obj) NFC_LLC_IO(obj)
+G_DEFINE_ABSTRACT_TYPE(NfcLlcIo, nfc_llc_io, G_TYPE_OBJECT)
+#define NFC_LLC_IO_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), \
+ NFC_TYPE_LLC_IO, NfcLlcIoClass)
+
+enum nfc_llc_io_signal {
+ SIGNAL_CAN_SEND,
+ SIGNAL_RECEIVE,
+ SIGNAL_ERROR,
+ SIGNAL_COUNT
+};
+
+#define SIGNAL_ERROR_NAME "nfc-llc-io-error"
+#define SIGNAL_CAN_SEND_NAME "nfc-llc-io-can-send"
+#define SIGNAL_RECEIVE_NAME "nfc-llc-io-receive"
+
+static guint nfc_llc_io_signals[SIGNAL_COUNT] = { 0 };
+
+/*==========================================================================*
+ * Internal interface
+ *==========================================================================*/
+
+void
+nfc_llc_io_error(
+ NfcLlcIo* self)
+{
+ if (!self->error) {
+ self->error = TRUE;
+ self->can_send = FALSE;
+ g_signal_emit(self, nfc_llc_io_signals[SIGNAL_ERROR], 0);
+ }
+}
+
+void
+nfc_llc_io_can_send(
+ NfcLlcIo* self)
+{
+ if (!self->can_send && !self->error) {
+ self->can_send = TRUE;
+ g_signal_emit(self, nfc_llc_io_signals[SIGNAL_CAN_SEND], 0);
+ }
+}
+
+gboolean
+nfc_llc_io_receive(
+ NfcLlcIo* self,
+ const GUtilData* data)
+{
+ gboolean ret = FALSE;
+
+ g_signal_emit(self, nfc_llc_io_signals[SIGNAL_RECEIVE], 0, data, &ret);
+ return ret;
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NfcLlcIo*
+nfc_llc_io_ref(
+ NfcLlcIo* self)
+{
+ if (G_LIKELY(self)) {
+ g_object_ref(THIS(self));
+ }
+ return self;
+}
+
+void
+nfc_llc_io_unref(
+ NfcLlcIo* self)
+{
+ if (G_LIKELY(self)) {
+ g_object_unref(THIS(self));
+ }
+}
+
+gboolean
+nfc_llc_io_start(
+ NfcLlcIo* self)
+{
+ return G_LIKELY(self) && NFC_LLC_IO_GET_CLASS(self)->start(self);
+}
+
+gboolean
+nfc_llc_io_send(
+ NfcLlcIo* self,
+ GBytes* data)
+{
+ if (G_LIKELY(self)) {
+ GASSERT(self->can_send);
+ if (self->can_send) {
+ return NFC_LLC_IO_GET_CLASS(self)->send(self, data);
+ }
+ }
+ return FALSE;
+}
+
+gulong
+nfc_llc_io_add_can_send_handler(
+ NfcLlcIo* self,
+ NfcLlcIoFunc func,
+ void* user_data)
+{
+ return (G_LIKELY(self) && G_LIKELY(func)) ? g_signal_connect(self,
+ SIGNAL_CAN_SEND_NAME, G_CALLBACK(func), user_data) : 0;
+}
+
+gulong
+nfc_llc_io_add_receive_handler(
+ NfcLlcIo* self,
+ NfcLlcIoReceiveFunc func,
+ void* user_data)
+{
+ return (G_LIKELY(self) && G_LIKELY(func)) ? g_signal_connect(self,
+ SIGNAL_RECEIVE_NAME, G_CALLBACK(func), user_data) : 0;
+}
+
+gulong
+nfc_llc_io_add_error_handler(
+ NfcLlcIo* self,
+ NfcLlcIoFunc func,
+ void* user_data)
+{
+ return (G_LIKELY(self) && G_LIKELY(func)) ? g_signal_connect(self,
+ SIGNAL_ERROR_NAME, G_CALLBACK(func), user_data) : 0;
+}
+
+void
+nfc_llc_io_remove_handlers(
+ NfcLlcIo* self,
+ gulong* ids,
+ guint count)
+{
+ gutil_disconnect_handlers(self, ids, count);
+}
+
+/*==========================================================================*
+ * Internals
+ *==========================================================================*/
+
+static
+void
+nfc_llc_io_init(
+ NfcLlcIo* self)
+{
+}
+
+static
+void
+nfc_llc_io_class_init(
+ NfcLlcIoClass* klass)
+{
+ GType type = G_OBJECT_CLASS_TYPE(klass);
+
+ nfc_llc_io_signals[SIGNAL_CAN_SEND] =
+ g_signal_new(SIGNAL_CAN_SEND_NAME, type, G_SIGNAL_RUN_FIRST, 0,
+ NULL, NULL, NULL, G_TYPE_NONE, 0);
+ nfc_llc_io_signals[SIGNAL_RECEIVE] =
+ g_signal_new(SIGNAL_RECEIVE_NAME, type, G_SIGNAL_RUN_LAST, 0,
+ g_signal_accumulator_true_handled, NULL, NULL,
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_llc_io.h
^
|
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_LLC_IO_H
+#define NFC_LLC_IO_H
+
+#include "nfc_types_p.h"
+
+#include <glib-object.h>
+
+/*
+ * LLC I/O API
+ *
+ * I/O modules reponsible for the symmetry procedure, i.e. sending
+ * SYMM packets in the Initiator mode to request data from the peer.
+ * It also does the polling when necessary.
+ *
+ * Basically, it hides the difference between Target and Initiator roles.
+ *
+ * If can_transmit is FALSE, the client needs to ways
+ * to be invoked. can_transmit field is updated before invoking the callback.
+ */
+
+struct nfc_llc_io {
+ GObject object;
+ gboolean error;
+ gboolean can_send;
+};
+
+GType nfc_llc_io_get_type(void) NFCD_INTERNAL;
+#define NFC_TYPE_LLC_IO (nfc_llc_io_get_type())
+#define NFC_LLC_IO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ NFC_TYPE_LLC_IO, NfcLlcIo))
+
+#define LLC_IO_EXPECT_MORE (TRUE)
+#define LLC_IO_IGNORE (FALSE)
+
+typedef
+gboolean
+(*NfcLlcIoReceiveFunc)(
+ NfcLlcIo* io,
+ const GUtilData* data,
+ gpointer user_data);
+
+typedef
+void
+(*NfcLlcIoFunc)(
+ NfcLlcIo* io,
+ gpointer user_data);
+
+NfcLlcIo*
+nfc_llc_io_ref(
+ NfcLlcIo* io)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_io_unref(
+ NfcLlcIo* io)
+ NFCD_INTERNAL;
+
+gboolean
+nfc_llc_io_start(
+ NfcLlcIo* io)
+ NFCD_INTERNAL;
+
+gboolean
+nfc_llc_io_send(
+ NfcLlcIo* io,
+ GBytes* data)
+ NFCD_INTERNAL;
+
+gulong
+nfc_llc_io_add_can_send_handler(
+ NfcLlcIo* io,
+ NfcLlcIoFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+gulong
+nfc_llc_io_add_receive_handler(
+ NfcLlcIo* io,
+ NfcLlcIoReceiveFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+gulong
+nfc_llc_io_add_error_handler(
+ NfcLlcIo* io,
+ NfcLlcIoFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_io_remove_handlers(
+ NfcLlcIo* io,
+ gulong* ids,
+ guint count)
+ NFCD_INTERNAL;
+
+#define nfc_llc_io_remove_all_handlers(io,ids) \
+ nfc_llc_io_remove_handlers(io, ids, G_N_ELEMENTS(ids))
+
+/* Initiator-side I/O */
+
+NfcLlcIo*
+nfc_llc_io_initiator_new(
+ NfcTarget* target)
+ NFCD_INTERNAL;
+
+/* Target-side I/O */
+
+NfcLlcIo*
+nfc_llc_io_target_new(
+ NfcInitiator* initiator)
+ NFCD_INTERNAL;
+
+#endif /* NFC_LLC_IO_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_llc_io_impl.h
^
|
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_LLC_IO_IMPL_H
+#define NFC_LLC_IO_IMPL_H
+
+#include "nfc_types_p.h"
+#include "nfc_llc_io.h"
+
+/* Internal API for use by NfcLlcIo implemenations */
+
+typedef struct nfc_llc_io_class {
+ GObjectClass parent;
+ gboolean (*start)(NfcLlcIo* io);
+ gboolean (*send)(NfcLlcIo* io, GBytes* data);
+} NfcLlcIoClass;
+
+#define NFC_LLC_IO_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
+ NFC_TYPE_LLC_IO, NfcLlcIoClass)
+
+void
+nfc_llc_io_error(
+ NfcLlcIo* io)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_io_can_send(
+ NfcLlcIo* io)
+ NFCD_INTERNAL;
+
+gboolean
+nfc_llc_io_receive(
+ NfcLlcIo* io,
+ const GUtilData* data)
+ NFCD_INTERNAL;
+
+#endif /* NFC_LLC_IO_IMPL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_llc_io_initiator.c
^
|
@@ -0,0 +1,278 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_llc_io_impl.h"
+#include "nfc_target_p.h"
+
+#define GLOG_MODULE_NAME NFC_LLC_LOG_MODULE
+#include <gutil_log.h>
+
+#define DEFAULT_POLL_PERIOD (100) /* ms */
+
+typedef struct nfc_llc_io_initiator {
+ NfcLlcIo io;
+ NfcTarget* target;
+ guint poll_period;
+ guint poll_id;
+ guint tx_id;
+} NfcLlcIoInitiator;
+
+#define THIS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ THIS_TYPE, NfcLlcIoInitiator))
+#define THIS_TYPE (nfc_llc_io_initiator_get_type())
+#define PARENT_TYPE NFC_TYPE_LLC_IO
+#define PARENT_CLASS (nfc_llc_io_initiator_parent_class)
+
+GType nfc_llc_io_initiator_get_type(void) NFCD_INTERNAL;
+typedef NfcLlcIoClass NfcLlcIoInitiatorClass;
+G_DEFINE_TYPE(NfcLlcIoInitiator, nfc_llc_io_initiator, PARENT_TYPE)
+
+static
+gboolean
+nfc_llc_io_initiator_send_symm(
+ NfcLlcIoInitiator* self);
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+gboolean
+nfc_llc_io_initiator_poll(
+ gpointer user_data)
+{
+ NfcLlcIoInitiator* self = THIS(user_data);
+
+ /* Polling is happening with can_send being TRUE */
+ GASSERT(self->io.can_send);
+ GASSERT(self->poll_id);
+ self->poll_id = 0;
+ GDEBUG("< SYMM (poll)");
+ nfc_llc_io_initiator_send_symm(self);
+ return G_SOURCE_REMOVE;
+}
+
+static
+void
+nfc_llc_io_initiator_symm_transmit_done(
+ NfcTarget* target,
+ NFC_TRANSMIT_STATUS status,
+ const void* data,
+ guint len,
+ void* user_data)
+{
+ NfcLlcIoInitiator* self = THIS(user_data);
+ NfcLlcIo* io = &self->io;
+
+ GASSERT(!io->can_send);
+ GASSERT(self->tx_id);
+ self->tx_id = 0;
+ io->can_send = TRUE; /* Don't issue a signal just yet */
+ nfc_llc_io_ref(io);
+ if (status == NFC_TRANSMIT_STATUS_OK) {
+ GUtilData received;
+
+ received.bytes = data;
+ received.size = len;
+ if (nfc_llc_io_receive(io, &received)) {
+ if (!self->tx_id) {
+ /* Something else might be coming, don't wait */
+ GDEBUG("< SYMM");
+ nfc_llc_io_initiator_send_symm(self);
+ }
+ } else if (!self->tx_id) {
+ /* Nothing is expected to arrive urgently, start polling. */
+ self->poll_id = g_timeout_add(self->poll_period,
+ nfc_llc_io_initiator_poll, self);
+ nfc_llc_io_can_send(io);
+ }
+ } else {
+ nfc_llc_io_error(io);
+ }
+ nfc_llc_io_unref(io);
+}
+
+static
+void
+nfc_llc_io_initiator_pdu_transmit_done(
+ NfcTarget* target,
+ NFC_TRANSMIT_STATUS status,
+ const void* data,
+ guint len,
+ void* user_data)
+{
+ NfcLlcIoInitiator* self = THIS(user_data);
+ NfcLlcIo* io = &self->io;
+
+ GASSERT(!io->can_send);
+ GASSERT(self->tx_id);
+ self->tx_id = 0;
+ io->can_send = TRUE; /* Don't issue a signal just yet */
+ nfc_llc_io_ref(io);
+ if (status == NFC_TRANSMIT_STATUS_OK) {
+ GUtilData received;
+
+ received.bytes = data;
+ received.size = len;
+ nfc_llc_io_receive(io, &received);
+ if (!self->tx_id) {
+ GDEBUG("< SYMM");
+ nfc_llc_io_initiator_send_symm(self);
+ }
+ } else {
+ nfc_llc_io_error(io);
+ }
+ nfc_llc_io_unref(io);
+}
+
+static
+gboolean
+nfc_llc_io_initiator_send_symm(
+ NfcLlcIoInitiator* self)
+{
+ static const guint8 SYMM[] = { 0x00, 0x00 };
+ NfcLlcIo* io = &self->io;
+
+ GASSERT(!self->tx_id);
+ io->can_send = FALSE;
+ self->tx_id = nfc_target_transmit(self->target, SYMM, sizeof(SYMM), NULL,
+ nfc_llc_io_initiator_symm_transmit_done, NULL, self);
+ if (self->tx_id) {
+ return TRUE;
+ } else {
+ nfc_llc_io_error(io);
+ return FALSE;
+ }
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NfcLlcIo*
+nfc_llc_io_initiator_new(
+ NfcTarget* target)
+{
+ if (G_LIKELY(target)) {
+ NfcLlcIoInitiator* self = g_object_new(THIS_TYPE, NULL);
+
+ self->target = nfc_target_ref(target);
+ self->poll_period = DEFAULT_POLL_PERIOD;
+ return &self->io;
+ }
+ return NULL;
+}
+
+/*==========================================================================*
+ * Methods
+ *==========================================================================*/
+
+static
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_llc_io_target.c
^
|
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_llc_io_impl.h"
+#include "nfc_initiator_p.h"
+
+#define GLOG_MODULE_NAME NFC_LLC_LOG_MODULE
+#include <gutil_log.h>
+
+typedef struct nfc_llc_io_target {
+ NfcLlcIo io;
+ NfcInitiator* initiator;
+ NfcTransmission* transmission;
+ gulong tx_handler_id;
+} NfcLlcIoTarget;
+
+#define THIS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ THIS_TYPE, NfcLlcIoTarget))
+#define THIS_TYPE (nfc_llc_io_target_get_type())
+#define PARENT_TYPE NFC_TYPE_LLC_IO
+#define PARENT_CLASS (nfc_llc_io_target_parent_class)
+
+GType nfc_llc_io_target_get_type(void) NFCD_INTERNAL;
+typedef NfcLlcIoClass NfcLlcIoTargetClass;
+G_DEFINE_TYPE(NfcLlcIoTarget, nfc_llc_io_target, PARENT_TYPE)
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+nfc_llc_io_target_response_sent(
+ NfcTransmission* transmission,
+ gboolean ok,
+ void* user_data)
+{
+ NfcLlcIoTarget* self = THIS(user_data);
+ NfcLlcIo* io = &self->io;
+
+ GASSERT(transmission == self->transmission);
+ nfc_transmission_unref(self->transmission);
+ self->transmission = NULL;
+ if (!ok) {
+ nfc_llc_io_error(io);
+ }
+}
+
+static
+gboolean
+nfc_llc_io_target_transmission_handler(
+ NfcInitiator* initiator,
+ NfcTransmission* transmission,
+ const GUtilData* data,
+ void* user_data)
+{
+ NfcLlcIoTarget* self = THIS(user_data);
+
+ GASSERT(!self->transmission);
+ if (!self->transmission) {
+ NfcLlcIo* io = &self->io;
+
+ self->transmission = nfc_transmission_ref(transmission);
+ if (data) {
+ io->can_send = TRUE;
+ nfc_llc_io_receive(io, data);
+ } else {
+ nfc_llc_io_can_send(io);
+ }
+ /* nfc_llc_io_target_send() sets can_send to FALSE */
+ if (self->transmission && io->can_send) {
+ static const guint8 SYMM[] = { 0x00, 0x00 };
+
+ /* LLC isn't sending anything, respond with a SYMM */
+ GDEBUG("< SYMM");
+ io->can_send = FALSE;
+ if (nfc_transmission_respond(transmission, SYMM, sizeof(SYMM),
+ nfc_llc_io_target_response_sent, self)) {
+ } else {
+ nfc_llc_io_error(io);
+ }
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NfcLlcIo*
+nfc_llc_io_target_new(
+ NfcInitiator* initiator)
+{
+ if (G_LIKELY(initiator)) {
+ NfcLlcIoTarget* self = g_object_new(THIS_TYPE, NULL);
+
+ self->initiator = nfc_initiator_ref(initiator);
+ self->tx_handler_id = nfc_initiator_add_transmission_handler(initiator,
+ nfc_llc_io_target_transmission_handler, self);
+ return &self->io;
+ }
+ return NULL;
+}
+
+/*==========================================================================*
+ * Methods
+ *==========================================================================*/
+
+static
+gboolean
+nfc_llc_io_target_start(
+ NfcLlcIo* io)
+{
+ return TRUE;
+}
+
+static
+gboolean
+nfc_llc_io_target_send(
+ NfcLlcIo* io,
+ GBytes* send)
+{
+ NfcLlcIoTarget* self = THIS(io);
+ gsize size;
+ gconstpointer data = g_bytes_get_data(send, &size);
+
+ io->can_send = FALSE;
+ if (nfc_transmission_respond(self->transmission, data, (guint)size,
+ nfc_llc_io_target_response_sent, self)) {
+ return TRUE;
+ } else {
+ nfc_llc_io_error(io);
+ return FALSE;
+ }
+}
+
+/*==========================================================================*
+ * Internals
+ *==========================================================================*/
+
+static
+void
+nfc_llc_io_target_init(
+ NfcLlcIoTarget* self)
+{
+}
+
+static
+void
+nfc_llc_io_target_finalize(
+ GObject* object)
+{
+ NfcLlcIoTarget* self = THIS(object);
+
+ nfc_transmission_unref(self->transmission);
+ nfc_initiator_remove_handler(self->initiator, self->tx_handler_id);
+ nfc_initiator_unref(self->initiator);
+ G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
+}
+
+static
+void
+nfc_llc_io_target_class_init(
+ NfcLlcIoTargetClass* klass)
+{
+ klass->start = nfc_llc_io_target_start;
+ klass->send = nfc_llc_io_target_send;
+ G_OBJECT_CLASS(klass)->finalize = nfc_llc_io_target_finalize;
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_llc_param.c
^
|
@@ -0,0 +1,338 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_llc_param.h"
+
+#include <gutil_macros.h>
+
+/*
+ * NFCForum-TS-LLCP_1.1
+ * Section 4.4 LLC Parameter Format
+ */
+
+GByteArray*
+nfc_llc_param_encode(
+ const NfcLlcParam* const* params,
+ GByteArray* dest,
+ guint maxlen)
+{
+ if (params) {
+ const NfcLlcParam* const* ptr = params;
+
+ if (!dest) dest = g_byte_array_new();
+ while (*ptr) {
+ const NfcLlcParam* param = *ptr++;
+ const NfcLlcParamValue* value = ¶m->value;
+ const guint len = dest->len;
+ guint8* tlv;
+ guint l, v;
+
+ switch (param->type) {
+ /* 4.5.1 Version Number, VERSION */
+ case NFC_LLC_PARAM_VERSION:
+ g_byte_array_set_size(dest, len + 3);
+ tlv = dest->data + len;
+ tlv[0] = (guint8)param->type;
+ tlv[1] = 0x01;
+ tlv[2] = value->version;
+ break;
+ /* 4.5.2 Maximum Information Unit Extension, MIUX */
+ case NFC_LLC_PARAM_MIUX:
+ g_byte_array_set_size(dest, len + 4);
+ tlv = dest->data + len;
+ v = MAX(value->miu, NFC_LLC_MIU_MIN) - NFC_LLC_MIU_MIN;
+ tlv[0] = (guint8)param->type;
+ tlv[1] = 0x02;
+ tlv[2] = (v >> 8) & 0x07;
+ tlv[3] = (guint8)v;
+ break;
+ /* 4.5.3 Well-Known Service List, WKS */
+ case NFC_LLC_PARAM_WKS:
+ g_byte_array_set_size(dest, len + 4);
+ tlv = dest->data + len;
+ tlv[0] = (guint8)param->type;
+ tlv[1] = 0x02;
+ tlv[2] = (value->wks >> 8) & 0x07;
+ tlv[3] = (guint8)value->wks;
+ break;
+ /* 4.5.4 Link Timeout, LTO */
+ case NFC_LLC_PARAM_LTO:
+ g_byte_array_set_size(dest, len + 3);
+ tlv = dest->data + len;
+ v = value->lto / 10;
+ tlv[0] = (guint8)param->type;
+ tlv[1] = 0x01;
+ tlv[2] = (guint8)MIN(v, 0xff);
+ break;
+ /* 4.5.5 Receive Window Size, RW */
+ case NFC_LLC_PARAM_RW:
+ g_byte_array_set_size(dest, len + 3);
+ tlv = dest->data + len;
+ tlv[0] = (guint8)param->type;
+ tlv[1] = 0x01;
+ tlv[2] = (guint8)MIN(value->rw, 0x0f);
+ break;
+ /* 4.5.6 Service Name, SN */
+ case NFC_LLC_PARAM_SN:
+ l = (guint)(value->sn ? strlen(value->sn) : 0);
+ l = MIN(l, 0xff);
+ g_byte_array_set_size(dest, len + 2 + l);
+ tlv = dest->data + len;
+ tlv[0] = (guint8)param->type;
+ tlv[1] = (guint8)l;
+ if (l) memcpy(tlv + 2, value->sn, l);
+ break;
+ /* 4.5.7 Option, OPT */
+ case NFC_LLC_PARAM_OPT:
+ g_byte_array_set_size(dest, len + 3);
+ tlv = dest->data + len;
+ tlv[0] = (guint8)param->type;
+ tlv[1] = 0x01;
+ tlv[2] = (guint8)value->opt;
+ break;
+ /* 4.5.8 Service Discovery Request, SDREQ */
+ case NFC_LLC_PARAM_SDREQ:
+ l = (guint)(value->sdreq.uri ? strlen(value->sdreq.uri) : 0);
+ l = MIN(l, 0xfe);
+ g_byte_array_set_size(dest, len + 3 + l);
+ tlv = dest->data + len;
+ tlv[0] = (guint8)param->type;
+ tlv[1] = (guint8)(l + 1);
+ tlv[2] = value->sdreq.tid;
+ if (l) memcpy(tlv + 3, value->sdreq.uri, l);
+ break;
+ /* 4.5.9 Service Discovery Response, SDRES */
+ case NFC_LLC_PARAM_SDRES:
+ g_byte_array_set_size(dest, len + 4);
+ tlv = dest->data + len;
+ tlv[0] = (guint8)param->type;
+ tlv[1] = 0x02;
+ tlv[2] = value->sdres.tid;
+ tlv[3] = value->sdres.sap;
+ break;
+ }
+ if (maxlen && dest->len >= maxlen) {
+ if (dest->len > maxlen) {
+ g_byte_array_set_size(dest, len);
+ }
+ break;
+ }
+ }
+ }
+ return dest;
+}
+
+NfcLlcParam**
+nfc_llc_param_decode(
+ const GUtilData* tlvs)
+{
+ NfcLlcParam** params = NULL;
+
+ if (tlvs) {
+ const guint8* ptr = tlvs->bytes;
+ const guint8* end = ptr + tlvs->size;
+ GPtrArray* list = g_ptr_array_new();
+
+ while (ptr + 1 < end && ptr + (ptr[1] + 1) < end) {
+ const guint t = ptr[0];
+ const guint l = ptr[1];
+ const guint8* v = ptr + 2;
+ NfcLlcParam* param = NULL;
+ char* buf;
+
+ switch (t) {
+ /* 4.5.1 Version Number, VERSION */
+ case NFC_LLC_PARAM_VERSION:
+ if (l == 1) {
+ param = g_new0(NfcLlcParam, 1);
+ param->value.version = v[0];
+ }
+ break;
+ /* 4.5.2 Maximum Information Unit Extension, MIUX */
+ case NFC_LLC_PARAM_MIUX:
+ if (l == 2) {
+ const guint miux = (((((guint)v[0]) << 8) | v[1]) & 0x7ff);
+
+ param = g_new0(NfcLlcParam, 1);
+ param->value.miu = miux + NFC_LLC_MIU_MIN;
+ }
+ break;
+ /* 4.5.3 Well-Known Service List, WKS */
+ case NFC_LLC_PARAM_WKS:
+ if (l == 2) {
+ param = g_new0(NfcLlcParam, 1);
+ param->value.wks = ((((guint)v[0]) << 8) | v[1]);
+ }
+ break;
+ /* 4.5.4 Link Timeout, LTO */
+ case NFC_LLC_PARAM_LTO:
+ /*
+ * The LTO parameter value SHALL be an 8-bit unsigned
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_llc_param.h
^
|
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_LLC_PARAM_H
+#define NFC_LLC_PARAM_H
+
+#include "nfc_types_p.h"
+
+#define NFC_LLC_MIU_MIN (128)
+#define NFC_LLC_MIU_MAX (0x7ff + NFC_LLC_MIU_MIN)
+#define NFC_LLC_MIU_DEFAULT NFC_LLC_MIU_MIN
+#define NFC_LLC_LTO_DEFAULT (100) /* milliseconds */
+#define NFC_LLC_RW_DEFAULT (1)
+#define NFC_LLC_RW_MAX (0xf)
+
+typedef enum nfc_llc_param_type {
+ NFC_LLC_PARAM_VERSION = 1,
+ NFC_LLC_PARAM_MIUX = 2,
+ NFC_LLC_PARAM_WKS = 3,
+ NFC_LLC_PARAM_LTO = 4,
+ NFC_LLC_PARAM_RW = 5,
+ NFC_LLC_PARAM_SN = 6,
+ NFC_LLC_PARAM_OPT = 7,
+ NFC_LLC_PARAM_SDREQ = 8, /* LLCP 1.1 */
+ NFC_LLC_PARAM_SDRES = 9 /* LLCP 1.1 */
+} NFC_LLC_PARAM_TYPE;
+
+typedef enum nfc_llc_opt {
+ NFC_LLC_OPT_NONE = 0x00,
+ NFC_LLC_OPT_CL = 0x01, /* Connectionless link service */
+ NFC_LLC_OPT_CO = 0x02 /* Connection-oriented link service */
+} NFC_LLC_OPT;
+
+typedef struct nfc_llc_param_sdreq {
+ guint8 tid;
+ const char* uri;
+} NfcLlcParamSdReq;
+
+typedef struct nfc_llc_param_sdres {
+ guint8 tid;
+ guint8 sap;
+} NfcLlcParamSdRes;
+
+typedef union nfc_llc_param_value {
+ guint8 version;
+ guint miu; /* MIUX + NFC_LLC_MIU_MIN */
+ guint wks;
+ guint lto; /* milliseconds */
+ guint8 rw;
+ NFC_LLC_OPT opt;
+ const char* sn;
+ NfcLlcParamSdReq sdreq;
+ NfcLlcParamSdRes sdres;
+} NfcLlcParamValue;
+
+struct nfc_llc_param {
+ NFC_LLC_PARAM_TYPE type;
+ NfcLlcParamValue value;
+};
+
+GByteArray*
+nfc_llc_param_encode(
+ const NfcLlcParam* const* params,
+ GByteArray* dest,
+ guint maxlen)
+ NFCD_INTERNAL;
+
+NfcLlcParam**
+nfc_llc_param_decode(
+ const GUtilData* tlvs)
+ NFCD_INTERNAL;
+
+NfcLlcParam**
+nfc_llc_param_decode_bytes(
+ const void* data,
+ guint size)
+ NFCD_INTERNAL;
+
+guint
+nfc_llc_param_count(
+ const NfcLlcParam* const* params)
+ NFCD_INTERNAL;
+
+const NfcLlcParam*
+nfc_llc_param_find(
+ const NfcLlcParam* const* params,
+ NFC_LLC_PARAM_TYPE type)
+ NFCD_INTERNAL;
+
+void
+nfc_llc_param_free(
+ NfcLlcParam** list)
+ NFCD_INTERNAL;
+
+static inline const NfcLlcParam** nfc_llc_param_constify(NfcLlcParam** params)
+ { return (const NfcLlcParam**)params; }
+
+#endif /* NFC_LLC_PARAM_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_manager.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -32,12 +32,16 @@
#define GLIB_DISABLE_DEPRECATION_WARNINGS
+#include "nfc_manager_p.h"
#include "internal/nfc_manager_i.h"
#include "nfc_adapter_p.h"
+#include "nfc_peer_service.h"
+#include "nfc_peer_services.h"
#include "nfc_plugins.h"
#include "nfc_log.h"
#include <gutil_misc.h>
+#include <gutil_macros.h>
#include <stdlib.h>
@@ -45,10 +49,22 @@
#define NFC_ADAPTER_NAME_FORMAT "nfc%u"
+struct nfc_mode_request {
+ NfcModeRequest* next;
+ NfcManager* manager;
+ NFC_MODE enable;
+ NFC_MODE disable;
+};
+
struct nfc_manager_priv {
NfcPlugins* plugins;
+ NfcPeerServices* services;
+ NfcModeRequest* p2p_request;
GHashTable* adapters;
guint next_adapter_index;
+ gboolean requested_power;
+ NFC_MODE default_mode;
+ NfcModeRequest* mode_requests;
};
typedef GObjectClass NfcManagerClass;
@@ -57,15 +73,21 @@
enum nfc_manager_signal {
SIGNAL_ADAPTER_ADDED,
SIGNAL_ADAPTER_REMOVED,
+ SIGNAL_SERVICE_REGISTERED,
+ SIGNAL_SERVICE_UNREGISTERED,
SIGNAL_ENABLED_CHANGED,
+ SIGNAL_MODE_CHANGED,
SIGNAL_STOPPED,
SIGNAL_COUNT
};
-#define SIGNAL_ADAPTER_ADDED_NAME "nfc-manager-adapter-added"
-#define SIGNAL_ADAPTER_REMOVED_NAME "nfc-manager-adapter-removed"
-#define SIGNAL_ENABLED_CHANGED_NAME "nfc-manager-enabled-changed"
-#define SIGNAL_STOPPED_NAME "nfc-manager-stopped"
+#define SIGNAL_ADAPTER_ADDED_NAME "nfc-manager-adapter-added"
+#define SIGNAL_ADAPTER_REMOVED_NAME "nfc-manager-adapter-removed"
+#define SIGNAL_SERVICE_REGISTERED_NAME "nfc-manager-service-registered"
+#define SIGNAL_SERVICE_UNREGISTERED_NAME "nfc-manager-service-unregistered"
+#define SIGNAL_ENABLED_CHANGED_NAME "nfc-manager-enabled-changed"
+#define SIGNAL_MODE_CHANGED_NAME "nfc-manager-mode-changed"
+#define SIGNAL_STOPPED_NAME "nfc-manager-stopped"
static guint nfc_manager_signals[SIGNAL_COUNT] = { 0 };
@@ -140,6 +162,121 @@
g_free(adapters);
}
+static
+void
+nfc_manager_update_adapter_modes(
+ NfcManager* self)
+{
+ NfcAdapter** adapters = nfc_manager_ref_adapters(self->priv);
+
+ if (adapters) {
+ const NFC_MODE mode = self->mode;
+ NfcAdapter** ptr = adapters;
+
+ while (*ptr) {
+ nfc_adapter_request_mode(*ptr++, mode);
+ }
+ nfc_manager_unref_adapters(adapters);
+ }
+}
+
+static
+gboolean
+nfc_manager_update_mode(
+ NfcManager* self)
+{
+ NfcManagerPriv* priv = self->priv;
+ const NFC_MODE prev_mode = self->mode;
+ const NfcModeRequest* req = priv->mode_requests;
+
+ self->mode = priv->default_mode;
+ for (req = priv->mode_requests; req; req = req->next) {
+ self->mode = (self->mode & ~req->disable) | req->enable;
+ }
+ if (self->mode != prev_mode) {
+ GDEBUG("NFC mode 0x%02x", self->mode);
+ g_signal_emit(self, nfc_manager_signals[SIGNAL_MODE_CHANGED], 0);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+static
+NfcModeRequest*
+nfc_manager_mode_request_new_internal(
+ NfcManager* self,
+ gboolean internal,
+ NFC_MODE enable,
+ NFC_MODE disable)
+{
+ NfcManagerPriv* priv = self->priv;
+ NfcModeRequest* req = g_slice_new0(NfcModeRequest);
+
+ if (!internal) {
+ req->manager = nfc_manager_ref(self);
+ }
+ req->enable = enable;
+ req->disable = disable;
+ req->next = priv->mode_requests;
+ priv->mode_requests = req;
+ if (nfc_manager_update_mode(self)) {
+ nfc_manager_update_adapter_modes(self);
+ }
+ return req;
+}
+
+static
+void
+nfc_manager_mode_request_free_internal(
+ NfcManager* self,
+ NfcModeRequest* req)
+{
+ NfcManagerPriv* priv = self->priv;
+
+ /* Remove it from the list */
+ if (priv->mode_requests == req) {
+ priv->mode_requests = req->next;
+ } else {
+ NfcModeRequest* prev = priv->mode_requests;
+
+ while (prev) {
+ if (prev->next == req) {
+ prev->next = req->next;
+ break;
+ }
+ prev = prev->next;
+ }
+ }
+
+ /* Update the effective mode */
+ if (nfc_manager_update_mode(self)) {
+ nfc_manager_update_adapter_modes(self);
+ }
+
+ nfc_manager_unref(req->manager); /* Can be NULL */
+ req->next = NULL;
+ gutil_slice_free(req);
+}
+
+static
+void
+nfc_manager_release_p2p_mode_request(
+ NfcManager* self)
+{
+ NfcManagerPriv* priv = self->priv;
+ NfcModeRequest* req = priv->p2p_request;
+
+ if (req) {
+ /*
+ * Since nfc_manager_mode_request_free_internal() may emit signals,
+ * we need to NULLify the pointer beforehand.
+ */
+ priv->p2p_request = NULL;
+ nfc_manager_mode_request_free_internal(self, req);
+ }
+}
+
/*==========================================================================*
* Interface
*==========================================================================*/
@@ -210,7 +347,10 @@
}
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_manager_p.h
^
|
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_MANAGER_PRIVATE_H
+#define NFC_MANAGER_PRIVATE_H
+
+#include "nfc_types_p.h"
+
+#include <nfc_manager.h>
+
+void
+nfc_manager_request_mode(
+ NfcManager* manager,
+ NFC_MODE mode); /* It used to be public and stays exported */
+
+#endif /* NFC_MANAGER_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_ndef_rec.c
^
|
@@ -45,13 +45,6 @@
G_DEFINE_TYPE(NfcNdefRec, nfc_ndef_rec, G_TYPE_OBJECT)
-static const GUtilData nfc_ndef_rec_type_hs = { (const guint8*) "Hs", 2 };
-static const GUtilData nfc_ndef_rec_type_hr = { (const guint8*) "Hr", 2 };
-static const GUtilData nfc_ndef_rec_type_hc = { (const guint8*) "Hc", 2 };
-static const GUtilData nfc_ndef_rec_type_ac = { (const guint8*) "ac", 2 };
-static const GUtilData nfc_ndef_rec_type_cr = { (const guint8*) "cr", 2 };
-static const GUtilData nfc_ndef_rec_type_err = { (const guint8*) "err", 3 };
-
static
NfcNdefRec*
nfc_ndef_rec_alloc(
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer.c
^
|
@@ -0,0 +1,632 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
+#include "nfc_peer_p.h"
+#include "nfc_llc.h"
+#include "nfc_llc_param.h"
+#include "nfc_peer_services.h"
+#include "nfc_snep_server.h"
+#include "nfc_ndef.h"
+
+#define GLOG_MODULE_NAME NFC_PEER_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_misc.h>
+
+GLOG_MODULE_DEFINE2("nfc-peer", NFC_CORE_LOG_MODULE);
+
+enum {
+ LLC_EVENT_STATE,
+ LLC_EVENT_IDLE,
+ LLC_EVENT_WKS,
+ LLC_EVENT_COUNT
+};
+
+enum {
+ SNEP_EVENT_NDEF,
+ SNEP_EVENT_STATE,
+ SNEP_EVENT_COUNT
+};
+
+typedef struct nfc_peer_connect {
+ NfcPeer* peer;
+ NfcPeerConnectFunc complete;
+ void* user_data;
+ GDestroyNotify destroy;
+} NfcPeerConnect;
+
+struct nfc_peer_priv {
+ NfcLlc* llc;
+ NfcPeerServices* services;
+ NfcSnepServer* snep;
+ char* name;
+ gulong llc_event_id[LLC_EVENT_COUNT];
+ gulong snep_event_id[SNEP_EVENT_COUNT];
+ gboolean ndef_reception_started;
+};
+
+#define THIS(obj) NFC_PEER(obj)
+#define THIS_TYPE NFC_TYPE_PEER
+#define PARENT_TYPE G_TYPE_OBJECT
+#define PARENT_CLASS (nfc_peer_parent_class)
+G_DEFINE_ABSTRACT_TYPE(NfcPeer, nfc_peer, PARENT_TYPE)
+
+#define NFC_PEER_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), \
+ NFC_TYPE_PEER, NfcPeerClass)
+
+enum nfc_peer_signal {
+ SIGNAL_WKS_CHANGED,
+ SIGNAL_NDEF_CHANGED,
+ SIGNAL_INITIALIZED,
+ SIGNAL_GONE,
+ SIGNAL_COUNT
+};
+
+#define SIGNAL_WKS_CHANGED_NAME "nfc-peer-wks-changed"
+#define SIGNAL_NDEF_CHANGED_NAME "nfc-peer-ndef-changed"
+#define SIGNAL_INITIALIZED_NAME "nfc-peer-initialized"
+#define SIGNAL_GONE_NAME "nfc-peer-gone"
+
+static guint nfc_peer_signals[SIGNAL_COUNT] = { 0 };
+static const guint8 LLCP_MAGIC[] = { 0x46, 0x66, 0x6d };
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+NfcPeerConnect*
+nfc_peer_connect_new(
+ NfcPeer* peer,
+ NfcPeerConnectFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ NfcPeerConnect* connect = g_slice_new(NfcPeerConnect);
+
+ g_object_ref(connect->peer = peer);
+ connect->complete = complete;
+ connect->user_data = user_data;
+ connect->destroy = destroy;
+ return connect;
+}
+
+static
+void
+nfc_peer_connect_free(
+ NfcPeerConnect* connect)
+{
+ if (connect->destroy) {
+ connect->destroy(connect->user_data);
+ }
+ g_object_unref(connect->peer);
+ g_slice_free1(sizeof(*connect), connect);
+}
+
+static
+void
+nfc_peer_connect_complete(
+ NfcPeerConnection* pc,
+ NFC_PEER_CONNECT_RESULT result,
+ void* user_data)
+{
+ NfcPeerConnect* connect = user_data;
+
+ if (connect->complete) {
+ connect->complete(connect->peer, pc, result, connect->user_data);
+ }
+}
+
+static
+void
+nfc_peer_disconnect_handlers(
+ NfcPeer* self)
+{
+ NfcPeerPriv* priv = self->priv;
+
+ nfc_snep_server_remove_all_handlers(priv->snep, priv->snep_event_id);
+ nfc_llc_remove_all_handlers(priv->llc, priv->llc_event_id);
+}
+
+static
+void
+nfc_peer_initialized(
+ NfcPeer* self)
+{
+ NfcPeerPriv* priv = self->priv;
+
+ /*
+ * Once we are initialized, we are no longer interested in LLC_EVENT_IDLE
+ * but we need to keep the the remaining ones (WKS and STATE) registered.
+ */
+ if (priv->llc_event_id[LLC_EVENT_IDLE]) {
+ nfc_llc_remove_handler(priv->llc, priv->llc_event_id[LLC_EVENT_IDLE]);
+ priv->llc_event_id[LLC_EVENT_IDLE] = 0;
+ }
+ nfc_snep_server_remove_all_handlers(priv->snep, priv->snep_event_id);
+ if (!(self->flags & NFC_PEER_FLAG_INITIALIZED)) {
+ GDEBUG("Peer initialized");
+ self->flags |= NFC_PEER_FLAG_INITIALIZED;
+ g_signal_emit(self, nfc_peer_signals[SIGNAL_INITIALIZED], 0);
+
+ /* Notify the services */
+ nfc_peer_services_peer_arrived(priv->services, self);
+ }
+}
+
+static
+void
+nfc_peer_check_ndef_reception_state(
+ NfcPeer* self)
+{
+ NfcPeerPriv* priv = self->priv;
+ NfcSnepServer* snep = priv->snep;
+ NfcLlc* llc = priv->llc;
+
+ if (snep->ndef || llc->idle) {
+ /* Either NDEF has been received or nothing seems to be coming */
+ nfc_ndef_rec_unref(self->ndef);
+ self->ndef = nfc_ndef_rec_ref(snep->ndef);
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_connection.c
^
|
@@ -0,0 +1,698 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
+#include "nfc_llc.h"
+#include "nfc_llc_param.h"
+#include "nfc_peer_connection_impl.h"
+#include "nfc_peer_connection_p.h"
+#include "nfc_peer_service_p.h"
+
+#define GLOG_MODULE_NAME NFC_PEER_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_idlepool.h>
+#include <gutil_macros.h>
+
+#define NFC_LLC_LOCAL_RW NFC_LLC_RW_MAX
+#define NFC_LLC_LOCAL_MIU NFC_LLC_MIU_MAX
+
+struct nfc_peer_connection_priv {
+ char* name;
+ NfcLlc* llc;
+ GUtilIdlePool* pool;
+ NfcPeerConnectionLlcpState ps;
+ NfcLlcParam miu_param;
+ NfcLlcParam rw_param;
+ const NfcLlcParam* lp[3];
+ guint send_off;
+ GList* send_queue;
+ GByteArray* send_buf;
+ gboolean disc_sent;
+};
+
+#define THIS(obj) NFC_PEER_CONNECTION(obj)
+#define THIS_TYPE NFC_TYPE_PEER_CONNECTION
+#define PARENT_CLASS (nfc_peer_connection_parent_class)
+
+G_DEFINE_ABSTRACT_TYPE(NfcPeerConnection, nfc_peer_connection, G_TYPE_OBJECT)
+#define NFC_PEER_CONNECTION_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), \
+ THIS_TYPE, NfcPeerConnectionClass)
+
+enum nfc_peer_connection_signal {
+ SIGNAL_STATE_CHANGED,
+ SIGNAL_COUNT
+};
+
+#define SIGNAL_STATE_CHANGED_NAME "nfc-llc-connection-state-changed"
+
+static guint nfc_peer_connection_signals[SIGNAL_COUNT] = { 0 };
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+#if GUTIL_LOG_DEBUG
+static
+const char*
+nfc_peer_connection_state_name(
+ NfcPeerConnectionPriv* priv,
+ NFC_LLC_CO_STATE state)
+{
+ char* tmp;
+
+ switch (state) {
+ case NFC_LLC_CO_CONNECTING: return "CONNECTING";
+ case NFC_LLC_CO_ACCEPTING: return "ACCEPTING";
+ case NFC_LLC_CO_ABANDONED: return "ABANDONED";
+ case NFC_LLC_CO_ACTIVE: return "ACTIVE";
+ case NFC_LLC_CO_DISCONNECTING: return "DISCONNECTING";
+ case NFC_LLC_CO_DEAD: return "DEAD";
+ }
+ tmp = g_strdup_printf("%d (?)", state);
+ gutil_idle_pool_add(priv->pool, tmp, g_free);
+ return tmp;
+}
+#endif /* GUTIL_LOG_DEBUG */
+
+static
+gboolean
+nfc_peer_connection_can_send(
+ NfcPeerConnection* self)
+{
+ NfcPeerConnectionPriv* priv = self->priv;
+ const NfcPeerConnectionLlcpState* ps = &priv->ps;
+
+ /*
+ * NFCForum-TS-LLCP_1.1
+ * 5.6 Connection-oriented Transport Mode Procedures
+ * 5.6.4.1 Sending I PDUs
+ *
+ * While the send state variable V(S) is equal to the send
+ * acknowledge state variable V(SA) plus the remote receive
+ * window size RW(R), the LLC SHALL NOT send an I PDU on that
+ * data link connection.
+ */
+ return ps->vs != ((ps->vsa + ps->rwr) & 0x0f);
+}
+
+static
+void
+nfc_peer_connection_submit_i_pdu(
+ NfcPeerConnection* self,
+ const void* data,
+ guint len)
+{
+ NfcPeerConnectionPriv* priv = self->priv;
+
+ nfc_llc_submit_i_pdu(priv->llc, self, data, len);
+ GASSERT(self->bytes_queued >= len);
+ self->bytes_queued -= len;
+ self->bytes_sent += len;
+}
+
+static
+gboolean
+nfc_peer_connection_drop_queued_data(
+ NfcPeerConnection* self)
+{
+ NfcPeerConnectionPriv* priv = self->priv;
+
+ if (priv->send_queue) {
+ GASSERT(self->bytes_queued);
+ self->bytes_queued = 0;
+ g_list_free_full(priv->send_queue, (GDestroyNotify) g_bytes_unref);
+ priv->send_queue = NULL;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static
+inline
+void
+nfc_peer_connection_data_dequeued(
+ NfcPeerConnection* self)
+{
+ NFC_PEER_CONNECTION_GET_CLASS(self)->data_dequeued(self);
+}
+
+static
+void
+nfc_peer_connection_disconnect_internal(
+ NfcPeerConnection* self,
+ gboolean flush)
+{
+ NfcPeerConnectionPriv* priv = self->priv;
+ NfcPeerService* service = self->service;
+ gboolean data_dropped = FALSE;
+
+ switch (self->state) {
+ case NFC_LLC_CO_CONNECTING:
+ GDEBUG("Abandoning %u:%u", service->sap, self->rsap);
+ data_dropped = nfc_peer_connection_drop_queued_data(self);
+ nfc_peer_connection_set_state(self, NFC_LLC_CO_ABANDONED);
+ break;
+ case NFC_LLC_CO_ACCEPTING:
+ GDEBUG("Connection %u:%u cancelled", service->sap, self->rsap);
+ data_dropped = nfc_peer_connection_drop_queued_data(self);
+ NFC_PEER_CONNECTION_GET_CLASS(self)->accept_cancelled(self);
+ nfc_peer_connection_set_state(self, NFC_LLC_CO_DEAD);
+ break;
+ case NFC_LLC_CO_ACTIVE:
+ nfc_llc_ack(priv->llc, self, TRUE);
+ GDEBUG("Disconnecting %u:%u", service->sap, self->rsap);
+ if (!flush) {
+ data_dropped = nfc_peer_connection_drop_queued_data(self);
+ }
+ if (!priv->send_queue) {
+ nfc_llc_submit_disc_pdu(priv->llc, self->rsap, service->sap);
+ priv->disc_sent = TRUE;
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_connection_p.h
^
|
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_CONNECTION_PRIVATE_H
+#define NFC_PEER_CONNECTION_PRIVATE_H
+
+#include "nfc_types_p.h"
+
+#include <nfc_peer_connection.h>
+
+typedef struct nfc_peer_connection_llcp_state {
+ /*
+ * NFCForum-TS-LLCP_1.1
+ * 5.6 Connection-oriented Transport Mode Procedures
+ * 5.6.1 Data Link Connection State Variables
+ */
+ guint8 vs; /* Send State Variable V(S) */
+ guint8 vsa; /* Send Acknowledgement State Variable V(SA) */
+ guint8 vr; /* Receive State Variable V(R) */
+ guint8 vra; /* Receive Acknowledgement State Variable V(RA) */
+
+ /*
+ * 5.6.2 Data Link Connection Parameters
+ */
+ guint8 rwr; /* Remote Receive Window Size, RW(R) */
+ guint16 rmiu; /* Remote Maximum Information Unit size for I PDUs */
+} NfcPeerConnectionLlcpState;
+
+#define LLCP_CONN_KEY(lsap,rsap) GINT_TO_POINTER(\
+ ((((guint16)(lsap)) & 0x3f) << 10) | \
+ (((guint16)(rsap)) & 0x3f))
+
+gpointer
+nfc_peer_connection_key(
+ NfcPeerConnection* pc)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_connection_set_llc(
+ NfcPeerConnection* pc,
+ NfcLlc* llc)
+ NFCD_INTERNAL;
+
+const NfcLlcParam* const*
+nfc_peer_connection_lp(
+ NfcPeerConnection* pc)
+ NFCD_INTERNAL;
+
+NfcPeerConnectionLlcpState*
+nfc_peer_connection_ps(
+ NfcPeerConnection* pc)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_connection_apply_remote_params(
+ NfcPeerConnection* pc,
+ const NfcLlcParam* const* params)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_connection_set_state(
+ NfcPeerConnection* pc,
+ NFC_LLC_CO_STATE state)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_connection_accept(
+ NfcPeerConnection* pc)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_connection_data_received(
+ NfcPeerConnection* pc,
+ const void* data,
+ guint len)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_connection_flush(
+ NfcPeerConnection* pc)
+ NFCD_INTERNAL;
+
+#endif /* NFC_PEER_CONNECTION_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_initiator.c
^
|
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_peer_p.h"
+#include "nfc_target_p.h"
+#include "nfc_llc.h"
+#include "nfc_llc_io.h"
+
+#define GLOG_MODULE_NAME NFC_PEER_LOG_MODULE
+#include <gutil_log.h>
+
+#define DEFAULT_POLL_PERIOD (100) /* ms */
+
+typedef struct nfc_peer_initiator {
+ NfcPeer peer;
+ NfcLlcIo* llc_io;
+ NfcTarget* target;
+ gulong gone_id;
+} NfcPeerInitiator;
+
+#define THIS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ THIS_TYPE, NfcPeerInitiator))
+#define THIS_TYPE (nfc_peer_initiator_get_type())
+#define PARENT_TYPE NFC_TYPE_PEER
+#define PARENT_CLASS (nfc_peer_initiator_parent_class)
+
+typedef NfcPeerClass NfcPeerInitiatorClass;
+G_DEFINE_TYPE(NfcPeerInitiator, nfc_peer_initiator, PARENT_TYPE)
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+nfc_peer_initiator_gone(
+ NfcTarget* target,
+ void* user_data)
+{
+ /* NfcTarget makes sure that this signal is only issued once */
+ nfc_peer_gone(NFC_PEER(user_data));
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NfcPeer*
+nfc_peer_new_initiator(
+ NfcTarget* target,
+ NFC_TECHNOLOGY technology,
+ const NfcParamNfcDepInitiator* nfc_dep,
+ NfcPeerServices* services)
+{
+ if (G_LIKELY(target) && G_LIKELY(nfc_dep)) {
+ NfcPeerInitiator* self = g_object_new(THIS_TYPE, NULL);
+ NfcPeer* peer = &self->peer;
+
+ self->target = nfc_target_ref(target);
+ self->llc_io = nfc_llc_io_initiator_new(target);
+ if (nfc_peer_init_base(peer, self->llc_io, &nfc_dep->atr_res_g,
+ services, technology, NFC_PEER_FLAG_INITIATOR)) {
+ peer->present = target->present;
+ self->gone_id = nfc_target_add_gone_handler(target,
+ nfc_peer_initiator_gone, self);
+ return peer;
+ }
+ g_object_unref(self);
+ }
+ return NULL;
+}
+
+/*==========================================================================*
+ * Methods
+ *==========================================================================*/
+
+static
+void
+nfc_peer_initiator_deactivate(
+ NfcPeer* peer)
+{
+ NfcPeerInitiator* self = THIS(peer);
+
+ nfc_target_deactivate(self->target);
+ NFC_PEER_CLASS(PARENT_CLASS)->deactivate(peer);
+}
+
+/*==========================================================================*
+ * Internals
+ *==========================================================================*/
+
+static
+void
+nfc_peer_initiator_init(
+ NfcPeerInitiator* self)
+{
+}
+
+static
+void
+nfc_peer_initiator_finalize(
+ GObject* object)
+{
+ NfcPeerInitiator* self = THIS(object);
+
+ nfc_llc_io_unref(self->llc_io);
+ nfc_target_remove_handler(self->target, self->gone_id);
+ nfc_target_unref(self->target);
+ G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
+}
+
+static
+void
+nfc_peer_initiator_class_init(
+ NfcPeerInitiatorClass* klass)
+{
+ klass->deactivate = nfc_peer_initiator_deactivate;
+ G_OBJECT_CLASS(klass)->finalize = nfc_peer_initiator_finalize;
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_p.h
^
|
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_PRIVATE_H
+#define NFC_PEER_PRIVATE_H
+
+#include "nfc_types_p.h"
+#include "nfc_peer.h"
+
+typedef struct nfc_peer_class {
+ GObjectClass object;
+ void (*deactivate)(NfcPeer* peer);
+ void (*gone)(NfcPeer* peer);
+} NfcPeerClass;
+
+#define NFC_PEER_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
+ NFC_TYPE_PEER, NfcPeerClass)
+
+NfcPeer*
+nfc_peer_new_initiator(
+ NfcTarget* target,
+ NFC_TECHNOLOGY technology,
+ const NfcParamNfcDepInitiator* nfc_dep,
+ NfcPeerServices* services)
+ NFCD_INTERNAL;
+
+NfcPeer*
+nfc_peer_new_target(
+ NfcInitiator* initiator,
+ NFC_TECHNOLOGY technology,
+ const NfcParamNfcDepTarget* nfc_dep,
+ NfcPeerServices* services)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_set_name(
+ NfcPeer* peer,
+ const char* name)
+ NFCD_INTERNAL;
+
+/* For use by derived classes */
+
+gboolean
+nfc_peer_init_base(
+ NfcPeer* peer,
+ NfcLlcIo* llc_io,
+ const GUtilData* gb, /* ATR_RES/ATR_REQ General Bytes */
+ NfcPeerServices* services,
+ NFC_TECHNOLOGY technology,
+ NFC_PEER_FLAGS flags)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_gone(
+ NfcPeer* peer)
+ NFCD_INTERNAL;
+
+#endif /* NFC_PEER_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_service.c
^
|
@@ -0,0 +1,321 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
+#include "nfc_peer_connection_p.h"
+#include "nfc_peer_service_impl.h"
+#include "nfc_peer_service_p.h"
+#include "nfc_llc.h"
+
+#define GLOG_MODULE_NAME NFC_PEER_LOG_MODULE
+#include <gutil_log.h>
+
+struct nfc_peer_service_priv {
+ char* name;
+ NfcPeerConnection** conns;
+};
+
+#define THIS(obj) NFC_PEER_SERVICE(obj)
+#define THIS_TYPE NFC_TYPE_PEER_SERVICE
+#define PARENT_CLASS (nfc_peer_service_parent_class)
+
+G_DEFINE_ABSTRACT_TYPE(NfcPeerService, nfc_peer_service, G_TYPE_OBJECT)
+#define NFC_PEER_SERVICE_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), \
+ THIS_TYPE, NfcPeerServiceClass)
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NfcPeerService*
+nfc_peer_service_ref(
+ NfcPeerService* self)
+{
+ if (G_LIKELY(self)) {
+ g_object_ref(THIS(self));
+ }
+ return self;
+}
+
+void
+nfc_peer_service_unref(
+ NfcPeerService* self)
+{
+ if (G_LIKELY(self)) {
+ g_object_unref(THIS(self));
+ }
+}
+
+void
+nfc_peer_service_disconnect_all(
+ NfcPeerService* self)
+{
+ if (G_LIKELY(self)) {
+ NfcPeerServicePriv* priv = self->priv;
+
+ if (priv->conns) {
+ NfcPeerConnection** ptr = priv->conns;
+ NfcPeerConnection** tmp;
+ guint n = 0;
+
+ /* Temporarily bump references */
+ for (ptr = priv->conns; *ptr++; n++);
+ tmp = g_new(NfcPeerConnection*, n + 1);
+ for (n = 0, ptr = priv->conns; *ptr; n++, ptr++) {
+ tmp[n] = nfc_peer_connection_ref(*ptr);
+ }
+ tmp[n] = NULL;
+
+ /* Disconnect all connections and release temporary refs */
+ for (ptr = tmp; *ptr; ptr++) {
+ nfc_peer_connection_disconnect(*ptr);
+ nfc_peer_connection_unref(*ptr);
+ }
+
+ g_free(tmp);
+ }
+ }
+}
+
+/*==========================================================================*
+ * Internal interface
+ *==========================================================================*/
+
+void
+nfc_peer_service_init_base(
+ NfcPeerService* self,
+ const char* name)
+{
+ NfcPeerServicePriv* priv = self->priv;
+
+ GASSERT(!self->name);
+ if (name) {
+ if (!strcmp(name, NFC_LLC_NAME_SNEP)) {
+ self->name = NFC_LLC_NAME_SNEP;
+ self->sap = NFC_LLC_SAP_SNEP;
+ } else {
+ self->name = priv->name = g_strdup(name);
+ }
+ }
+}
+
+NfcPeerConnection*
+nfc_peer_service_new_connect(
+ NfcPeerService* self,
+ guint8 rsap,
+ const char* name)
+{
+ NfcPeerConnection* pc = NFC_PEER_SERVICE_GET_CLASS(self)->
+ new_connect(self, rsap, name);
+
+ /* Make sure the state is right */
+ nfc_peer_connection_set_state(pc, NFC_LLC_CO_CONNECTING);
+ return pc;
+}
+
+NfcPeerConnection*
+nfc_peer_service_new_accept(
+ NfcPeerService* self,
+ guint8 rsap)
+{
+ NfcPeerConnection* pc = NFC_PEER_SERVICE_GET_CLASS(self)->
+ new_accept(self, rsap);
+
+ /* Make sure the state is right */
+ nfc_peer_connection_set_state(pc, NFC_LLC_CO_ACCEPTING);
+ return pc;
+}
+
+void
+nfc_peer_service_connection_created(
+ NfcPeerService* self,
+ NfcPeerConnection* connection)
+{
+ NfcPeerServicePriv* priv = self->priv;
+ guint n = 0;
+
+ if (priv->conns) {
+ NfcPeerConnection** ptr = priv->conns;
+
+ while (*ptr++) n++;
+ }
+ priv->conns = g_renew(NfcPeerConnection*, priv->conns, n + 2);
+ priv->conns[n] = connection;
+ priv->conns[n + 1] = NULL;
+}
+
+void
+nfc_peer_service_connection_dead(
+ NfcPeerService* self,
+ NfcPeerConnection* pc)
+{
+ NfcPeerServicePriv* priv = self->priv;
+ int pos = -1;
+ guint n = 0;
+
+ if (priv->conns) {
+ NfcPeerConnection** ptr = priv->conns;
+
+ while (*ptr) {
+ if (*ptr++ == pc) {
+ pos = n;
+ }
+ n++;
+ }
+ }
+ if (pos == 0 && n == 1) {
+ g_free(priv->conns);
+ priv->conns = NULL;
+ } else if (pos >= 0) {
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_service_p.h
^
|
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_SERVICE_PRIVATE_H
+#define NFC_PEER_SERVICE_PRIVATE_H
+
+#include "nfc_types_p.h"
+
+#include <nfc_peer_service.h>
+
+NfcPeerConnection*
+nfc_peer_service_new_connect(
+ NfcPeerService* service,
+ guint8 rsap,
+ const char* rname)
+ NFCD_INTERNAL;
+
+NfcPeerConnection*
+nfc_peer_service_new_accept(
+ NfcPeerService* service,
+ guint8 rsap)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_service_connection_created(
+ NfcPeerService* service,
+ NfcPeerConnection* connection)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_service_connection_dead(
+ NfcPeerService* service,
+ NfcPeerConnection* connection)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_service_peer_arrived(
+ NfcPeerService* service,
+ NfcPeer* peer)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_service_peer_left(
+ NfcPeerService* service,
+ NfcPeer* peer)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_service_datagram_received(
+ NfcPeerService* service,
+ guint8 ssap,
+ const void* data,
+ guint len)
+ NFCD_INTERNAL;
+
+#endif /* NFC_PEER_SERVICE_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_services.c
^
|
@@ -0,0 +1,386 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_peer_services.h"
+#include "nfc_peer_service_p.h"
+
+#define GLOG_MODULE_NAME NFC_PEER_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_macros.h>
+
+#include <stdlib.h>
+
+#define SAP_BIT(sap) (((guint64)1) << (sap))
+
+typedef struct nfc_peer_services_object {
+ NfcPeerServices pub;
+ NfcPeerService** list;
+ gint64 sap_mask;
+ gint refcount;
+} NfcPeerServicesObject;
+
+static NfcPeerService* const nfc_peer_services_empty_list[] = { NULL };
+
+static inline
+NfcPeerServicesObject* nfc_peer_services_cast(NfcPeerServices* pub)
+ { return G_LIKELY(pub) ? G_CAST(pub,NfcPeerServicesObject,pub) : NULL; }
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+nfc_peer_services_free(
+ NfcPeerServicesObject* self)
+{
+ NfcPeerService* const* ptr = self->pub.list;
+
+ while (*ptr) nfc_peer_service_unref(*ptr++);
+ g_free(self->list);
+ g_slice_free1(sizeof(*self), self);
+}
+
+static
+gboolean
+nfc_peer_services_contains(
+ NfcPeerServices* services,
+ NfcPeerService* service)
+{
+ NfcPeerService* const* ptr;
+
+ for (ptr = services->list; *ptr; ptr++) {
+ if (*ptr == service) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+static
+int
+nfc_peer_services_compare(
+ const void* p1,
+ const void* p2)
+{
+ NfcPeerService* ps1 = *(NfcPeerService**)p1;
+ NfcPeerService* ps2 = *(NfcPeerService**)p2;
+
+ return (int)ps1->sap - (int)ps2->sap;
+}
+
+static
+void
+nfc_peer_services_peer_notify(
+ NfcPeerServices* services,
+ NfcPeer* peer,
+ void (*notify)(NfcPeerService* ps, NfcPeer* peer))
+{
+ if (G_LIKELY(services)) {
+ NfcPeerService* const* ptr;
+ guint n = 0;
+
+ /* Count the services and bump references at the same time */
+ for (ptr = services->list; *ptr; ptr++) {
+ nfc_peer_service_ref(*ptr);
+ n++;
+ }
+
+ if (n) {
+ NfcPeerService** tmp = g_new(NfcPeerService*, n + 1);
+
+ /* In case if callbacks modify the list, make a copy */
+ memcpy(tmp, services->list, sizeof(NfcPeerService*) * (n + 1));
+ for (ptr = tmp; *ptr; ptr++) {
+ NfcPeerService* ps = *ptr;
+
+ /* Paranoid check if the service is still there */
+ if (nfc_peer_services_contains(services, ps)) {
+ notify(ps, peer);
+ }
+ }
+
+ /* Release temporary references */
+ for (ptr = tmp; *ptr; ptr++) {
+ nfc_peer_service_unref(*ptr);
+ }
+ g_free(tmp);
+ }
+ }
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NfcPeerServices*
+nfc_peer_services_new(
+ void)
+{
+ NfcPeerServicesObject* self = g_slice_new0(NfcPeerServicesObject);
+ NfcPeerServices* services = &self->pub;
+
+ services->list = nfc_peer_services_empty_list;
+ self->sap_mask = 1; /* Reserved for LLC Link Management Service */
+ g_atomic_int_set(&self->refcount, 1);
+ return services;
+}
+
+NfcPeerServices*
+nfc_peer_services_ref(
+ NfcPeerServices* services)
+{
+ NfcPeerServicesObject* self = nfc_peer_services_cast(services);
+
+ if (G_LIKELY(self)) {
+ GASSERT(self->refcount > 0);
+ g_atomic_int_inc(&self->refcount);
+ }
+ return services;
+}
+
+void
+nfc_peer_services_unref(
+ NfcPeerServices* services)
+{
+ NfcPeerServicesObject* self = nfc_peer_services_cast(services);
+
+ if (G_LIKELY(self)) {
+ GASSERT(self->refcount > 0);
+ if (g_atomic_int_dec_and_test(&self->refcount)) {
+ nfc_peer_services_free(self);
+ }
+ }
+}
+
+NfcPeerServices*
+nfc_peer_services_copy(
+ NfcPeerServices* services)
+{
+ NfcPeerServicesObject* self = nfc_peer_services_cast(services);
+
+ if (G_LIKELY(self)) {
+ NfcPeerServices* copy = nfc_peer_services_new();
+
+ if (self->list) {
+ NfcPeerServicesObject* priv = nfc_peer_services_cast(copy);
+ NfcPeerService* const* ptr;
+ guint n = 0;
+
+ /* Count the services and bump references at the same time */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_services.h
^
|
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_PEER_SERVICES_H
+#define NFC_PEER_SERVICES_H
+
+#include "nfc_types_p.h"
+
+struct nfc_peer_services {
+ NfcPeerService* const* list; /* NULL-terminated */
+};
+
+NfcPeerServices*
+nfc_peer_services_new(
+ void)
+ NFCD_INTERNAL;
+
+NfcPeerServices*
+nfc_peer_services_ref(
+ NfcPeerServices* services)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_services_unref(
+ NfcPeerServices* services)
+ NFCD_INTERNAL;
+
+NfcPeerServices*
+nfc_peer_services_copy(
+ NfcPeerServices* services)
+ NFCD_INTERNAL;
+
+NfcPeerService*
+nfc_peer_services_find_sn(
+ NfcPeerServices* services,
+ const char* name)
+ NFCD_INTERNAL;
+
+NfcPeerService*
+nfc_peer_services_find_sap(
+ NfcPeerServices* services,
+ guint8 sap)
+ NFCD_INTERNAL;
+
+gboolean
+nfc_peer_services_add(
+ NfcPeerServices* services,
+ NfcPeerService* service)
+ NFCD_INTERNAL;
+
+gboolean
+nfc_peer_services_remove(
+ NfcPeerServices* services,
+ NfcPeerService* service)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_services_peer_arrived(
+ NfcPeerServices* services,
+ NfcPeer* peer)
+ NFCD_INTERNAL;
+
+void
+nfc_peer_services_peer_left(
+ NfcPeerServices* services,
+ NfcPeer* peer)
+ NFCD_INTERNAL;
+
+#endif /* NFC_PEER_SERVICES_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_socket.c
^
|
@@ -0,0 +1,520 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
+#include "nfc_llc.h"
+#include "nfc_peer_service.h"
+#include "nfc_peer_socket.h"
+#include "nfc_peer_socket_impl.h"
+
+#define GLOG_MODULE_NAME NFC_PEER_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_macros.h>
+
+#include <gio/gunixfdlist.h>
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+struct nfc_peer_socket_priv {
+ GIOChannel* io_channel;
+ GList* write_queue;
+ guint read_watch_id;
+ guint write_watch_id;
+ guint write_pos;
+ int fd;
+};
+
+/* NOTE: we can exceed this limit, but by no more than MIU. There's no
+ * need to be overly strict about it. */
+#define DEFAULT_MAX_SEND_QUEUE (128*1024)
+
+#define THIS(obj) NFC_PEER_SOCKET(obj)
+#define THIS_TYPE NFC_TYPE_PEER_SOCKET
+#define PARENT_TYPE NFC_TYPE_PEER_CONNECTION
+#define PARENT_CLASS (nfc_peer_socket_parent_class)
+
+G_DEFINE_TYPE(NfcPeerSocket, nfc_peer_socket, PARENT_TYPE)
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+nfc_peer_socket_shutdown(
+ NfcPeerSocket* self)
+{
+ NfcPeerSocketPriv* priv = self->priv;
+
+ if (priv->read_watch_id) {
+ g_source_remove(priv->read_watch_id);
+ priv->read_watch_id = 0;
+ }
+ if (priv->write_watch_id) {
+ g_source_remove(priv->write_watch_id);
+ priv->write_watch_id = 0;
+ }
+ if (priv->io_channel) {
+ shutdown(priv->fd, SHUT_RDWR);
+ g_io_channel_shutdown(priv->io_channel, FALSE, NULL);
+ g_io_channel_unref(priv->io_channel);
+ priv->io_channel = NULL;
+ priv->fd = -1;
+ }
+}
+
+static
+gboolean
+nfc_peer_socket_read_bytes(
+ NfcPeerSocket* self,
+ gchar* buf,
+ gsize count,
+ gsize* bytes_read)
+{
+ GError* error = NULL;
+ NfcPeerSocketPriv* priv = self->priv;
+ NfcPeerConnection* conn = &self->connection;
+ GIOStatus status = g_io_channel_read_chars(priv->io_channel, buf,
+ count, bytes_read, &error);
+
+ if (error) {
+ GDEBUG("Connection %u:%u read failed: %s", conn->service->sap,
+ conn->rsap, GERRMSG(error));
+ priv->read_watch_id = 0;
+ nfc_peer_socket_shutdown(self);
+ nfc_peer_connection_disconnect(conn);
+ g_error_free(error);
+ return FALSE;
+ } else if (status == G_IO_STATUS_EOF) {
+ GDEBUG("Connection %u:%u hung up", conn->service->sap, conn->rsap);
+ priv->read_watch_id = 0;
+ nfc_peer_socket_shutdown(self);
+ nfc_peer_connection_disconnect(conn);
+ return FALSE;
+ } else {
+ GVERBOSE("Connection %u:%u read %u bytes", conn->service->sap,
+ conn->rsap, (guint)(*bytes_read));
+ return TRUE;
+ }
+}
+
+static
+gboolean
+nfc_peer_socket_read(
+ NfcPeerSocket* self)
+{
+ NfcPeerConnection* conn = &self->connection;
+ const guint rmiu = nfc_peer_connection_rmiu(conn);
+ void* buf = g_malloc(rmiu);
+ gsize bytes_read;
+
+ if (nfc_peer_socket_read_bytes(self, buf, rmiu, &bytes_read)) {
+ GBytes* bytes = g_bytes_new_take(buf, bytes_read);
+ const gboolean sent = nfc_peer_connection_send(conn, bytes);
+
+ g_bytes_unref(bytes);
+ /* Stop reading when we hit the queue size limit */
+ return sent && (self->connection.bytes_queued <= self->max_send_queue);
+ } else {
+ g_free(buf);
+ }
+ return FALSE;
+}
+
+static
+gboolean
+nfc_peer_socket_read_callback(
+ GIOChannel* source,
+ GIOCondition condition,
+ gpointer user_data)
+{
+ NfcPeerSocket* self = THIS(user_data);
+ gboolean result;
+
+ g_object_ref(self);
+ if ((condition & G_IO_IN) && nfc_peer_socket_read(self)) {
+ result = G_SOURCE_CONTINUE;
+ } else {
+ NfcPeerSocketPriv* priv = self->priv;
+
+ priv->read_watch_id = 0;
+ result = G_SOURCE_REMOVE;
+ }
+ g_object_unref(self);
+ return result;
+}
+
+static
+void
+nfc_peer_socket_read_check(
+ NfcPeerSocket* self)
+{
+ NfcPeerConnection* conn = &self->connection;
+ NfcPeerSocketPriv* priv = self->priv;
+
+ if (priv->io_channel && !priv->read_watch_id &&
+ conn->bytes_queued <= self->max_send_queue &&
+ conn->state <= NFC_LLC_CO_ACTIVE) {
+ priv->read_watch_id = g_io_add_watch(priv->io_channel,
+ G_IO_IN | G_IO_ERR | G_IO_HUP, nfc_peer_socket_read_callback,
+ self);
+ }
+}
+
+static
+gboolean
+nfc_peer_socket_write_bytes(
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_peer_target.c
^
|
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_peer_p.h"
+#include "nfc_initiator_p.h"
+#include "nfc_llc.h"
+#include "nfc_llc_io.h"
+
+#define GLOG_MODULE_NAME NFC_PEER_LOG_MODULE
+#include <gutil_log.h>
+
+typedef struct nfc_peer_target {
+ NfcPeer peer;
+ NfcLlcIo* llc_io;
+ NfcInitiator* initiator;
+ gulong gone_id;
+} NfcPeerTarget;
+
+#define THIS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), THIS_TYPE, NfcPeerTarget))
+#define THIS_TYPE (nfc_peer_target_get_type())
+#define PARENT_TYPE NFC_TYPE_PEER
+#define PARENT_CLASS (nfc_peer_target_parent_class)
+
+typedef NfcPeerClass NfcPeerTargetClass;
+G_DEFINE_TYPE(NfcPeerTarget, nfc_peer_target, PARENT_TYPE)
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+nfc_peer_target_gone(
+ NfcInitiator* initiator,
+ void* user_data)
+{
+ /* NfcInitiator makes sure that this signal is only issued once */
+ nfc_peer_gone(NFC_PEER(user_data));
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NfcPeer*
+nfc_peer_new_target(
+ NfcInitiator* initiator,
+ NFC_TECHNOLOGY technology,
+ const NfcParamNfcDepTarget* nfc_dep,
+ NfcPeerServices* services)
+{
+ if (G_LIKELY(initiator) && G_LIKELY(nfc_dep)) {
+ NfcPeerTarget* self = g_object_new(THIS_TYPE, NULL);
+ NfcPeer* peer = &self->peer;
+
+ self->initiator = nfc_initiator_ref(initiator);
+ self->llc_io = nfc_llc_io_target_new(initiator);
+ if (nfc_peer_init_base(peer, self->llc_io, &nfc_dep->atr_req_g,
+ services, technology, NFC_PEER_FLAGS_NONE)) {
+ peer->present = initiator->present;
+ self->gone_id = nfc_initiator_add_gone_handler(initiator,
+ nfc_peer_target_gone, self);
+ return peer;
+ }
+ g_object_unref(self);
+ }
+ return NULL;
+}
+
+/*==========================================================================*
+ * Methods
+ *==========================================================================*/
+
+static
+void
+nfc_peer_target_deactivate(
+ NfcPeer* peer)
+{
+ NfcPeerTarget* self = THIS(peer);
+
+ nfc_initiator_deactivate(self->initiator);
+ NFC_PEER_CLASS(PARENT_CLASS)->deactivate(peer);
+}
+
+/*==========================================================================*
+ * Internals
+ *==========================================================================*/
+
+static
+void
+nfc_peer_target_init(
+ NfcPeerTarget* self)
+{
+}
+
+static
+void
+nfc_peer_target_finalize(
+ GObject* object)
+{
+ NfcPeerTarget* self = THIS(object);
+
+ nfc_llc_io_unref(self->llc_io);
+ nfc_initiator_remove_handler(self->initiator, self->gone_id);
+ nfc_initiator_unref(self->initiator);
+ G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
+}
+
+static
+void
+nfc_peer_target_class_init(
+ NfcPeerTargetClass* klass)
+{
+ klass->deactivate = nfc_peer_target_deactivate;
+ G_OBJECT_CLASS(klass)->finalize = nfc_peer_target_finalize;
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_plugin.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -32,8 +32,8 @@
#define GLIB_DISABLE_DEPRECATION_WARNINGS
-#include "nfc_plugin_impl.h"
#include "nfc_plugin_p.h"
+#include "nfc_plugin_impl.h"
struct nfc_plugin_priv {
gboolean started;
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_snep_server.c
^
|
@@ -0,0 +1,461 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
+#include "nfc_snep_server.h"
+#include "nfc_peer_connection_impl.h"
+#include "nfc_peer_connection_p.h"
+#include "nfc_peer_service_impl.h"
+#include "nfc_peer_service_p.h"
+#include "nfc_ndef.h"
+#include "nfc_llc.h"
+
+#define GLOG_MODULE_NAME NFC_SNEP_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_misc.h>
+
+GLOG_MODULE_DEFINE2("snep", NFC_CORE_LOG_MODULE);
+
+/*
+ * NFCForum-TS-SNEP_1.0
+ *
+ * Table 2: Request Field Values
+ */
+typedef enum snep_request_code {
+ SNEP_REQUEST_CONTINUE = 0x00,
+ SNEP_REQUEST_GET = 0x01,
+ SNEP_REQUEST_PUT = 0x02,
+ SNEP_REQUEST_REJECT = 0x7f
+} SNEP_REQUEST_CODE;
+
+/*
+ * Table 3: Response Field Values
+ */
+typedef enum snep_response_code {
+ SNEP_RESPONSE_CONTINUE = 0x80,
+ SNEP_RESPONSE_SUCCESS = 0x81,
+ SNEP_RESPONSE_NOT_FOUND = 0xc0,
+ SNEP_RESPONSE_EXCESS_DATA = 0xc1,
+ SNEP_RESPONSE_BAD_REQUEST = 0xc2,
+ SNEP_RESPONSE_NOT_IMPLEMENTED = 0xe0,
+ SNEP_RESPONSE_UNSUPPORTED_VERSION = 0xe1,
+ SNEP_RESPONSE_REJECT = 0xff
+} SNEP_RESPONSE_CODE;
+
+#define SNEP_MAJOR_VERSION (1)
+#define SNEP_VERSION (0x10) /* (MAJOR << 4) | MINOR */
+
+typedef struct nfc_snep_server_connection {
+ NfcPeerConnection connection;
+ GByteArray* buf;
+ guint ndef_length;
+} NfcSnepServerConnection;
+
+typedef NfcPeerConnectionClass NfcSnepServerConnectionClass;
+GType nfc_snep_server_connection_get_type(void) NFCD_INTERNAL;
+G_DEFINE_TYPE(NfcSnepServerConnection, nfc_snep_server_connection, \
+ NFC_TYPE_PEER_CONNECTION)
+#define NFC_TYPE_SNEP_SERVER_CONNECTION (nfc_snep_server_connection_get_type())
+#define NFC_SNEP_SERVER_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ NFC_TYPE_SNEP_SERVER_CONNECTION, NfcSnepServerConnection))
+
+struct nfc_snep_server_priv {
+ int connection_count;
+};
+
+typedef NfcPeerServiceClass NfcSnepServerClass;
+GType nfc_snep_server_get_type(void) NFCD_INTERNAL;
+G_DEFINE_TYPE(NfcSnepServer, nfc_snep_server, NFC_TYPE_PEER_SERVICE)
+#define NFC_TYPE_SNEP_SERVER (nfc_snep_server_get_type())
+#define NFC_SNEP_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ NFC_TYPE_SNEP_SERVER, NfcSnepServer))
+
+enum nfc_snep_server_signal {
+ SIGNAL_STATE_CHANGED,
+ SIGNAL_NDEF_CHANGED,
+ SIGNAL_COUNT
+};
+
+#define SIGNAL_STATE_CHANGED_NAME "nfc-snep-server-state-changed"
+#define SIGNAL_NDEF_CHANGED_NAME "nfc-snep-server-ndef-changed"
+
+static guint nfc_snep_server_signals[SIGNAL_COUNT] = { 0 };
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+nfc_snep_server_response(
+ NfcPeerConnection* conn,
+ SNEP_RESPONSE_CODE code)
+{
+ const guint size = 6;
+ guint8* data = g_malloc(size);
+ GBytes* pkt = g_bytes_new_take(data, size);
+
+ memset(data, 0, size);
+ data[0] = SNEP_VERSION; /* Version */
+ data[1] = code; /* Response */
+ nfc_peer_connection_send(conn, pkt);
+ g_bytes_unref(pkt);
+}
+
+static
+void
+nfc_snep_server_set_state(
+ NfcSnepServer* self,
+ NFC_SNEP_SERVER_STATE state)
+{
+ if (self->state != state) {
+ self->state = state;
+ g_signal_emit(self, nfc_snep_server_signals[SIGNAL_STATE_CHANGED], 0);
+ }
+}
+
+static
+void
+nfc_snep_server_update_connection_count(
+ NfcSnepServer* self,
+ int change)
+{
+ NfcSnepServerPriv* priv = self->priv;
+ const int prev_count = priv->connection_count;
+
+ priv->connection_count += change;
+ if (change > 0) {
+ if (!prev_count) {
+ nfc_snep_server_set_state(self, NFC_SNEP_SERVER_RECEIVING);
+ }
+ } else {
+ if (!priv->connection_count) {
+ nfc_snep_server_set_state(self, NFC_SNEP_SERVER_LISTENING);
+ }
+ }
+}
+
+/*==========================================================================*
+ * Connection
+ *==========================================================================*/
+
+static
+void
+nfc_snep_server_connection_receive_ndef(
+ NfcSnepServerConnection* self,
+ const void* data,
+ guint len)
+{
+ NfcPeerConnection* conn = &self->connection;
+ NfcSnepServer* snep = NFC_SNEP_SERVER(conn->service);
+ GByteArray* buf = self->buf;
+
+ if ((buf->len + len) > self->ndef_length) {
+ GWARN("Broken SNEP Response (%u > %u)", buf->len + len,
+ self->ndef_length);
+ nfc_peer_connection_disconnect(conn);
+ } else {
+ g_byte_array_append(buf, data, len);
+ GDEBUG("Received %u bytes", buf->len);
+ if (buf->len == self->ndef_length) {
+ GUtilData ndef_data;
+ NfcNdefRec* prev_ndef;
+
+ /* Done with receiving NDEF. Parse it. */
+ ndef_data.bytes = buf->data;
+ ndef_data.size = buf->len;
+ prev_ndef = snep->ndef;
+ snep->ndef = nfc_ndef_rec_new(&ndef_data);
+
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_snep_server.h
^
|
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NFC_SNEP_SERVER_H
+#define NFC_SNEP_SERVER_H
+
+#include "nfc_types_p.h"
+#include "nfc_peer_service.h"
+
+/*
+ * SNEP server accespts NDEF message from SNEP client.
+ */
+typedef enum nfc_snep_server_state {
+ NFC_SNEP_SERVER_LISTENING,
+ NFC_SNEP_SERVER_RECEIVING
+} NFC_SNEP_SERVER_STATE;
+
+typedef struct nfc_snep_server_priv NfcSnepServerPriv;
+typedef struct nfc_snep_server {
+ NfcPeerService service;
+ NfcSnepServerPriv* priv;
+ NFC_SNEP_SERVER_STATE state;
+ NfcNdefRec* ndef;
+} NfcSnepServer;
+
+typedef
+void
+(*NfcSnepServerFunc)(
+ NfcSnepServer* snep,
+ void* user_data);
+
+NfcSnepServer*
+nfc_snep_server_new(
+ void)
+ NFCD_INTERNAL;
+
+gulong
+nfc_snep_server_add_state_changed_handler(
+ NfcSnepServer* snep,
+ NfcSnepServerFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+gulong
+nfc_snep_server_add_ndef_changed_handler(
+ NfcSnepServer* snep,
+ NfcSnepServerFunc func,
+ void* user_data)
+ NFCD_INTERNAL;
+
+void
+nfc_snep_server_remove_handler(
+ NfcSnepServer* snep,
+ gulong id)
+ NFCD_INTERNAL;
+
+void
+nfc_snep_server_remove_handlers(
+ NfcSnepServer* snep,
+ gulong* ids,
+ guint count)
+ NFCD_INTERNAL;
+
+#define nfc_snep_server_remove_all_handlers(snep,ids) \
+ nfc_snep_server_remove_handlers(snep, ids, G_N_ELEMENTS(ids))
+
+#endif /* NFC_SNEP_SERVER_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_tag.c
^
|
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2018-2020 Jolla Ltd.
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -47,6 +48,8 @@
};
G_DEFINE_TYPE(NfcTag, nfc_tag, G_TYPE_OBJECT)
+#define NFC_TAG_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), \
+ NFC_TYPE_TAG, NfcTagClass)
enum nfc_tag_signal {
SIGNAL_INITIALIZED,
@@ -68,9 +71,7 @@
NfcTag* self = NFC_TAG(user_data);
/* NfcTarget makes sure that this signal is only issued once */
- GASSERT(self->present);
- self->present = FALSE;
- g_signal_emit(self, nfc_tag_signals[SIGNAL_GONE], 0);
+ NFC_TAG_GET_CLASS(self)->gone(self);
}
/*==========================================================================*
@@ -186,6 +187,8 @@
if (poll) {
const gsize aligned_size = G_ALIGN8(sizeof(*poll));
const GUtilData* src;
+ const NfcParamPollB* poll_b;
+ guint8* dest;
gsize size;
/*
@@ -198,21 +201,32 @@
size = src->size ? (aligned_size + src->size) : sizeof(*poll);
*(priv->param = g_malloc0(size)) = *poll;
if (src->bytes) {
- guint8* dest = (guint8*)priv->param + aligned_size;
+ dest = (guint8*)priv->param + aligned_size;
memcpy(dest, src->bytes, src->size);
priv->param->a.nfcid1.bytes = dest;
}
break;
case NFC_TECHNOLOGY_B:
- src = &poll->b.nfcid0;
- size = src->size ? (aligned_size + src->size) : sizeof(*poll);
+ poll_b = &poll->b;
+ if (poll_b->nfcid0.size || poll_b->prot_info.size) {
+ size = aligned_size + G_ALIGN8(poll_b->nfcid0.size) +
+ poll_b->prot_info.size;
+ } else {
+ size = sizeof(*poll);
+ }
*(priv->param = g_malloc0(size)) = *poll;
+ dest = (guint8*)priv->param + aligned_size;
+ src = &poll_b->nfcid0;
if (src->bytes) {
- guint8* dest = (guint8*)priv->param + aligned_size;
-
memcpy(dest, src->bytes, src->size);
priv->param->b.nfcid0.bytes = dest;
+ dest += G_ALIGN8(src->size);
+ }
+ src = &poll_b->prot_info;
+ if (src->bytes) {
+ memcpy(dest, src->bytes, src->size);
+ priv->param->b.prot_info.bytes = dest;
}
break;
case NFC_TECHNOLOGY_F:
@@ -244,6 +258,21 @@
}
/*==========================================================================*
+ * Methods
+ *==========================================================================*/
+
+static
+void
+nfc_tag_default_gone(
+ NfcTag* self)
+{
+ /* Must only be invoked once per lifetime */
+ GASSERT(self->present);
+ self->present = FALSE;
+ g_signal_emit(self, nfc_tag_signals[SIGNAL_GONE], 0);
+}
+
+/*==========================================================================*
* Internals
*==========================================================================*/
@@ -277,6 +306,7 @@
NfcTagClass* klass)
{
g_type_class_add_private(klass, sizeof(NfcTagPriv));
+ klass->gone = nfc_tag_default_gone;
G_OBJECT_CLASS(klass)->finalize = nfc_tag_finalize;
nfc_tag_signals[SIGNAL_INITIALIZED] =
g_signal_new(SIGNAL_INITIALIZED_NAME, G_OBJECT_CLASS_TYPE(klass),
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_tag_p.h
^
|
@@ -39,8 +39,12 @@
typedef struct nfc_tag_class {
GObjectClass parent;
+ void (*gone)(NfcTag* tag);
} NfcTagClass;
+#define NFC_TAG_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
+ NFC_TYPE_TAG, NfcTagClass)
+
NfcTag*
nfc_tag_new(
NfcTarget* target,
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_tag_t2.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -32,8 +33,8 @@
#define GLIB_DISABLE_DEPRECATION_WARNINGS
-#include "nfc_tag_t2.h"
#include "nfc_tag_p.h"
+#include "nfc_tag_t2.h"
#include "nfc_target_p.h"
#include "nfc_ndef.h"
#include "nfc_util.h"
@@ -114,7 +115,6 @@
GHashTable* reads;
GHashTable* writes;
GByteArray* cached_blocks;
- guint8 serial[4];
guint sector_count;
NfcTagType2Sector* sectors;
guint init_id;
@@ -902,22 +902,17 @@
priv->init_id = 0;
if (status == NFC_TRANSMIT_STATUS_OK && len == 16) {
const guint8* bytes = data;
- const guint8* serial = bytes + 4;
const guint8* cc = bytes + 12;
/*
* Layout of the first 4 blocks accorting to NFCForum-TS-Type-2-Tag:
*
- * Bytes 0..3 - UID / Internal
- * Bytes 4..7 - Serial Number
- * Bytes 8..11 - Internal / Lock
+ * Bytes 0..9 - UID / Internal
+ * Bytes 10..11 - Lock
* Bytes 12..15 - Capability Container (CC)
*/
- memcpy(priv->serial, serial, 4);
- self->serial.bytes = priv->serial;
- self->serial.size = 4;
- GDEBUG("Serial: %02x %02x %02x %02x", priv->serial[0],
- priv->serial[1], priv->serial[2], priv->serial[3]);
+ GDEBUG("Internal data:");
+ nfc_hexdump(bytes, 10);
if (cc[0] == NFC_TAG_T2_CC_NFC_FORUM_MAGIC &&
cc[1] >= NFC_TAG_T2_CC_MIN_VERSION) {
@@ -970,6 +965,8 @@
nfc_tag_init_base(tag, target, &poll);
/* nfc_tag_init_base has copied nfcid1 to the internal storage */
self->nfcid1 = nfc_tag_param(tag)->a.nfcid1;
+ /* serial is same as nfcid1 */
+ self->serial = nfc_tag_param(tag)->a.nfcid1;
self->sel_res = poll_a->sel_res;
} else {
nfc_tag_init_base(tag, target, NULL);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_tag_t4.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -32,13 +33,15 @@
#define GLIB_DISABLE_DEPRECATION_WARNINGS
-#include "nfc_tag_t4_p.h"
#include "nfc_tag_p.h"
+#include "nfc_tag_t4_p.h"
#include "nfc_target_p.h"
#include "nfc_ndef.h"
#include "nfc_util.h"
#include "nfc_log.h"
+#include <gutil_macros.h>
+
typedef struct nfc_isodep_tx {
NfcTagType4* t4;
NfcTagType4ResponseFunc resp;
@@ -60,8 +63,16 @@
NfcTargetSequence* init_seq;
NfcIsoDepNdefRead* init_read;
guint init_id;
+ NfcParamIsoDep* iso_dep; /* Since 1.0.39 */
};
+typedef struct nfc_isodep_reset_data {
+ NfcTagType4* t4;
+ NfcTagType4ResetRespFunc resp;
+ GDestroyNotify destroy;
+ void* user_data;
+} NfcIsoDepResetData;
+
G_DEFINE_ABSTRACT_TYPE(NfcTagType4, nfc_tag_t4, NFC_TYPE_TAG)
/*
@@ -116,7 +127,6 @@
* Implementation
*==========================================================================*/
-static
gboolean
nfc_tag_t4_build_apdu(
GByteArray* buf,
@@ -131,13 +141,13 @@
/*
* Command APDU encoding options (ISO/IEC 7816-4):
*
- * Case 1: |CLA|INS|P1|P2| n = 4
- * Case 2s: |CLA|INS|P1|P2|LE | n = 5
- * Case 3s: |CLA|INS|P1|P2|LC |...BODY...| n = 6..260
- * Case 4s: |CLA|INS|P1|P2|LC |...BODY...|LE | n = 7..261
- * Case 2e: |CLA|INS|P1|P2|00 |LE1|LE2| n = 7
- * Case 3e: |CLA|INS|P1|P2|00 |LC1|LC2|...BODY...| n = 8..65542
- * Case 4e: |CLA|INS|P1|P2|00 |LC1|LC2|...BODY...|LE1|LE2| n = 10..65544
+ * Case 1: |CLA|INS|P1|P2| n = 4
+ * Case 2s: |CLA|INS|P1|P2|LE| n = 5
+ * Case 3s: |CLA|INS|P1|P2|LC|...BODY...| n = 6..260
+ * Case 4s: |CLA|INS|P1|P2|LC|...BODY...|LE | n = 7..261
+ * Case 2e: |CLA|INS|P1|P2|00|LE1|LE2| n = 7
+ * Case 3e: |CLA|INS|P1|P2|00|LC1|LC2|...BODY...| n = 8..65542
+ * Case 4e: |CLA|INS|P1|P2|00|LC1|LC2|...BODY...|LE1|LE2| n = 10..65544
*
* LE, LE1, LE2 may be 0x00, 0x00|0x00 (means the maximum, 256 or 65536)
* LC must not be 0x00 and LC1|LC2 must not be 0x00|0x00
@@ -149,13 +159,13 @@
buf->data[2] = p1;
buf->data[3] = p2;
if (len > 0) {
- if (len < 0x100) {
- /* Short Lc field */
+ if (len <= 0xff) {
+ /* Cases 3s and 4s */
guint8 lc = (guint8)len;
g_byte_array_append(buf, &lc, 1);
} else {
- /* Extended Lc field */
+ /* Cases 3e and 4e */
guint8 lc[3];
lc[0] = 0;
@@ -166,13 +176,13 @@
g_byte_array_append(buf, data, len);
}
if (exp > 0) {
- if (exp <= 0x100) {
- /* Short Le field */
+ if (exp <= 0x100 && len <= 0xff) {
+ /* Cases 2s and 4s */
guint8 le = (exp == 0x100) ? 0 : ((guint8)exp);
g_byte_array_append(buf, &le, 1);
} else {
- /* Extended Le field */
+ /* Cases 4e and 2e */
guint8 le[2];
if (exp == 0x10000) {
@@ -181,6 +191,11 @@
le[0] = (guint8)(exp >> 8);
le[1] = (guint8)exp;
}
+ if (!len) {
+ /* Case 2e */
+ g_byte_array_set_size(buf, 5);
+ buf->data[4] = 0;
+ }
g_byte_array_append(buf, le, sizeof(le));
}
}
@@ -371,20 +386,33 @@
NfcTag* tag = &self->tag;
GASSERT(!priv->init_id);
+ g_object_ref(self);
nfc_target_sequence_unref(priv->init_seq);
nfc_iso_dep_ndef_read_free(priv->init_read);
priv->init_seq = NULL;
priv->init_read = NULL;
nfc_tag_set_initialized(tag);
+ g_object_unref(self);
}
static
void
nfc_tag_t4_init_done(
NfcTarget* target,
- void* user_data)
+ NFC_REACTIVATE_STATUS status,
+ void* tag)
{
- nfc_tag_t4_initialized(NFC_TAG_T4(user_data));
+ NfcTagType4* self = NFC_TAG_T4(tag);
+
+ /*
+ * It doesn't make sense to mark tag as initialized in case of
+ * reactivation timeout, because the tag going to get deactivated
+ * and dropped right after this function returns.
+ */
+ if (status != NFC_REACTIVATE_STATUS_TIMEOUT) {
+ nfc_tag_t4_initialized(self);
+ }
+ nfc_tag_unref(&self->tag);
}
static
@@ -399,12 +427,13 @@
* done now, to avoid blocking presence checks in case if reactivation
* times out.
*/
- nfc_target_sequence_unref(priv->init_seq);
- priv->init_seq = NULL;
GDEBUG("Reactivating Type 4 tag");
- if (!nfc_target_reactivate(self->tag.target, nfc_tag_t4_init_done, self)) {
+ nfc_tag_ref(&self->tag);
+ if (!nfc_target_reactivate(self->tag.target, priv->init_seq,
+ nfc_tag_t4_init_done, NULL, self)) {
GDEBUG("Oops. Failed to reactivate, leaving the tag as is");
nfc_tag_t4_initialized(self);
+ nfc_tag_unref(&self->tag);
}
}
@@ -663,6 +692,44 @@
nfc_tag_t4_initialized(self);
}
+static
+void
+nfc_tag_t4_reset_data_free(
+ NfcIsoDepResetData* rst)
+{
+ GDestroyNotify destroy = rst->destroy;
+
+ if (destroy) {
+ rst->destroy = NULL;
+ destroy(rst->user_data);
+ }
+ g_slice_free1(sizeof(*rst), rst);
+}
+
+static
+void
+nfc_tag_t4_reset_data_free1(
+ void* data)
+{
+ nfc_tag_t4_reset_data_free((NfcIsoDepResetData*)data);
+}
+
+static
+void
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_tag_t4_p.h
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -33,8 +34,8 @@
#ifndef NFC_TAG_T4_PRIVATE_H
#define NFC_TAG_T4_PRIVATE_H
-#include "nfc_tag_t4.h"
#include "nfc_tag_p.h"
+#include "nfc_tag_t4.h"
typedef struct nfc_tag_t4_class {
NfcTagClass parent;
@@ -59,7 +60,21 @@
NfcTagType4* tag,
NfcTarget* target,
guint mtu,
- const NfcParamPoll* poll)
+ const NfcParamPoll* poll,
+ const NfcParamIsoDep* iso_dep)
+ NFCD_INTERNAL;
+
+/* For unit tests */
+gboolean
+nfc_tag_t4_build_apdu(
+ GByteArray* buf,
+ guint8 cla, /* Class byte */
+ guint8 ins, /* Instruction byte */
+ guint8 p1, /* Parameter byte 1 */
+ guint8 p2, /* Parameter byte 2 */
+ guint len, /* Command data length */
+ const void* data, /* Command data */
+ guint exp) /* Expected length */
NFCD_INTERNAL;
#endif /* NFC_TAG_T4_PRIVATE_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_tag_t4a.c
^
|
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2019-2020 Jolla Ltd.
* Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -52,27 +53,32 @@
nfc_tag_t4a_new(
NfcTarget* target,
const NfcParamPollA* poll_a,
- const NfcParamIsoDepPollA* iso_dep_param)
+ const NfcParamIsoDepPollA* iso_dep_a)
{
- if (G_LIKELY(iso_dep_param)) {
+ if (G_LIKELY(iso_dep_a)) {
NfcTagType4a* self = g_object_new(NFC_TYPE_TAG_T4A, NULL);
+ NfcTagType4* t4 = &self->t4;
+ NfcParamIsoDep iso_dep;
GDEBUG("Type 4A tag");
+ GASSERT(target->technology == NFC_TECHNOLOGY_A);
+ memset(&iso_dep, 0, sizeof(iso_dep));
+ iso_dep.a = *iso_dep_a;
if (poll_a) {
NfcParamPoll poll;
- GASSERT(target->technology == NFC_TECHNOLOGY_A);
memset(&poll, 0, sizeof(poll));
poll.a = *poll_a;
- nfc_tag_t4_init_base(&self->t4, target, iso_dep_param->fsc, &poll);
+ nfc_tag_t4_init_base(t4, target, iso_dep_a->fsc, &poll, &iso_dep);
} else {
- nfc_tag_t4_init_base(&self->t4, target, iso_dep_param->fsc, NULL);
+ nfc_tag_t4_init_base(t4, target, iso_dep_a->fsc, NULL, &iso_dep);
}
return self;
}
return NULL;
}
+
/*==========================================================================*
* Internals
*==========================================================================*/
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_tag_t4b.c
^
|
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2019-2020 Jolla Ltd.
* Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -52,17 +53,26 @@
nfc_tag_t4b_new(
NfcTarget* target,
const NfcParamPollB* poll_b,
- const NfcParamIsoDepPollB* iso_dep_param)
+ const NfcParamIsoDepPollB* iso_dep_b)
{
if (G_LIKELY(poll_b)) {
NfcTagType4b* self = g_object_new(NFC_TYPE_TAG_T4B, NULL);
+ NfcTagType4* t4 = &self->t4;
NfcParamPoll poll;
GDEBUG("Type 4B tag");
GASSERT(target->technology == NFC_TECHNOLOGY_B);
memset(&poll, 0, sizeof(poll));
poll.b = *poll_b;
- nfc_tag_t4_init_base(&self->t4, target, poll_b->fsc, &poll);
+ if (iso_dep_b) {
+ NfcParamIsoDep iso_dep;
+
+ memset(&iso_dep, 0, sizeof(iso_dep));
+ iso_dep.b = *iso_dep_b;
+ nfc_tag_t4_init_base(t4, target, poll_b->fsc, &poll, &iso_dep);
+ } else {
+ nfc_tag_t4_init_base(t4, target, poll_b->fsc, &poll, NULL);
+ }
return self;
}
return NULL;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_target.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -32,29 +33,55 @@
#define GLIB_DISABLE_DEPRECATION_WARNINGS
-#include "nfc_target_impl.h"
#include "nfc_target_p.h"
+#include "nfc_target_impl.h"
#include "nfc_log.h"
+#include <gutil_macros.h>
#include <gutil_misc.h>
-#define TRANSMIT_TIMEOUT_MS (500)
-#define DEFAULT_REACTIVATION_TIMEOUT_MS (1000)
+#define DEFAULT_TRANSMIT_TIMEOUT_MS (500)
+#define DEFAULT_REACTIVATION_TIMEOUT_MS (1500)
typedef struct nfc_target_request NfcTargetRequest;
+typedef struct nfc_target_request_type {
+ const char* name;
+ gboolean (*submit)(NfcTargetRequest* req);
+ void (*cancel)(NfcTargetRequest* req);
+ void (*abandon)(NfcTargetRequest* req);
+ guint (*timeout_ms)(NfcTargetRequest* req);
+ void (*transmit_done)(NfcTargetRequest* req, NFC_TRANSMIT_STATUS status,
+ const void* data, guint len);
+ void (*reactivated)(NfcTargetRequest* req);
+ void (*timed_out)(NfcTargetRequest* req);
+ void (*failed)(NfcTargetRequest* req);
+ void (*free)(NfcTargetRequest* req);
+} NfcTargetRequestType;
+
struct nfc_target_request {
NfcTargetRequest* next;
NfcTargetSequence* seq;
+ const NfcTargetRequestType* type;
NfcTarget* target;
guint id;
- void* data;
- guint len;
guint timeout;
- NfcTargetTransmitFunc complete;
GDestroyNotify destroy;
void* user_data;
};
+typedef struct nfc_target_transmit_request {
+ NfcTargetRequest request;
+ const void* data;
+ void* copied_data;
+ guint len;
+ NfcTargetTransmitFunc complete;
+} NfcTargetTransmitRequest;
+
+typedef struct nfc_target_reactivate_request {
+ NfcTargetRequest request;
+ NfcTargetReactivateFunc callback;
+} NfcTargetReactivateRequest;
+
typedef struct nfc_target_request_queue {
NfcTargetRequest* first;
NfcTargetRequest* last;
@@ -77,11 +104,9 @@
NfcTargetRequest* req_active;
NfcTargetSequenceQueue seq_queue;
NfcTargetRequestQueue req_queue;
- /* Reactivation */
- NfcTargetFunc ra_func;
- void* ra_data;
+ guint tx_timeout_ms;
guint ra_timeout_ms;
- guint ra_timeout;
+ gboolean reactivating;
};
G_DEFINE_ABSTRACT_TYPE(NfcTarget, nfc_target, G_TYPE_OBJECT)
@@ -101,7 +126,7 @@
static
void
-nfc_target_schedule_next_transmit(
+nfc_target_schedule_next_request(
NfcTarget* self);
static
@@ -111,6 +136,301 @@
NfcTargetSequence* seq);
/*==========================================================================*
+ * Transmit request
+ *==========================================================================*/
+
+static inline
+NfcTargetTransmitRequest*
+nfc_target_transmit_request_cast(
+ NfcTargetRequest* req)
+{
+ return G_CAST(req, NfcTargetTransmitRequest, request);
+}
+
+static
+gboolean
+nfc_target_transmit_request_submit(
+ NfcTargetRequest* req)
+{
+ NfcTarget* target = req->target;
+ NfcTargetTransmitRequest* tx = nfc_target_transmit_request_cast(req);
+
+ return NFC_TARGET_GET_CLASS(target)->transmit(target, tx->data, tx->len);
+}
+
+static
+void
+nfc_target_transmit_request_cancel(
+ NfcTargetRequest* req)
+{
+ NFC_TARGET_GET_CLASS(req->target)->cancel_transmit(req->target);
+}
+
+static
+void
+nfc_target_transmit_request_abandon(
+ NfcTargetRequest* req)
+{
+ nfc_target_transmit_request_cast(req)->complete = NULL;
+}
+
+static
+guint
+nfc_target_transmit_request_timeout_ms(
+ NfcTargetRequest* req)
+{
+ return req->target->priv->tx_timeout_ms;
+}
+
+static
+void
+nfc_target_transmit_request_done(
+ NfcTargetRequest* req,
+ NFC_TRANSMIT_STATUS status,
+ const void* data,
+ guint len)
+{
+ NfcTargetTransmitRequest* tx = nfc_target_transmit_request_cast(req);
+ NfcTargetTransmitFunc complete = tx->complete;
+
+ if (complete) {
+ tx->complete = NULL;
+ complete(req->target, status, data, len, req->user_data);
+ }
+}
+
+static
+void
+nfc_target_transmit_request_failed(
+ NfcTargetRequest* req)
+{
+ nfc_target_transmit_request_done(req, NFC_TRANSMIT_STATUS_ERROR, NULL, 0);
+}
+
+static
+void
+nfc_target_transmit_request_timed_out(
+ NfcTargetRequest* req)
+{
+ nfc_target_transmit_request_done(req, NFC_TRANSMIT_STATUS_TIMEOUT, NULL, 0);
+}
+
+static
+void
+nfc_target_transmit_request_free(
+ NfcTargetRequest* req)
+{
+ NfcTargetTransmitRequest* tx = nfc_target_transmit_request_cast(req);
+
+ g_free(tx->copied_data);
+ g_slice_free1(sizeof(*tx), tx);
+}
+
+static
+NfcTargetTransmitRequest*
+nfc_target_transmit_request_new(
+ NfcTarget* target,
+ const void* data,
+ guint len,
+ NfcTargetSequence* seq,
+ NfcTargetTransmitFunc complete,
+ GDestroyNotify destroy,
+ void* user_data)
+{
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_target_p.h
^
|
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2018-2020 Jolla Ltd.
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -37,6 +38,19 @@
#include <nfc_target.h>
+typedef enum nfc_reactivate_status {
+ NFC_REACTIVATE_STATUS_SUCCESS, /* Reactivation successful */
+ NFC_REACTIVATE_STATUS_GONE, /* Target is done */
+ NFC_REACTIVATE_STATUS_TIMEOUT /* Reactivation timed out */
+} NFC_REACTIVATE_STATUS;
+
+typedef
+void
+(*NfcTargetReactivateFunc)(
+ NfcTarget* target,
+ NFC_REACTIVATE_STATUS status,
+ void* user_data);
+
void
nfc_target_deactivate(
NfcTarget* target)
@@ -50,7 +64,9 @@
gboolean
nfc_target_reactivate(
NfcTarget* target,
- NfcTargetFunc func,
+ NfcTargetSequence* seq,
+ NfcTargetReactivateFunc func,
+ GDestroyNotify destroy,
void* user_data)
NFCD_INTERNAL;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/core/src/nfc_types_p.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -33,8 +33,33 @@
#ifndef NFC_TYPES_PRIVATE_H
#define NFC_TYPES_PRIVATE_H
+/* Need to define NFCD_EXPORT before including <nfc_types.h> */
+#define NFCD_EXPORT __attribute__((visibility ("default")))
+
+/* Now pull in the public types */
#include <nfc_types.h>
+/* Types */
+typedef struct nfc_llc NfcLlc;
+typedef struct nfc_llc_io NfcLlcIo;
+typedef struct nfc_llc_param NfcLlcParam;
+typedef struct nfc_peer_services NfcPeerServices;
+
+/*
+ * SAP:
+ *
+ * 00h..0Fh Well-Known Service access points
+ * 10h..1Fh Named services advertised by SDP
+ * 20h..3Fh Unnamed services that are NOT advertised by SDP
+ */
+
+#define NFC_LLC_SAP_MASK (0x3f) /* 6 bit */
+#define NFC_LLC_SAP_COUNT (NFC_LLC_SAP_MASK + 1)
+#define NFC_LLC_SAP_WKS_MASK (0x0f) /* Well-Known Services */
+#define NFC_LLC_SAP_NAMED (0x10) /* First named service */
+#define NFC_LLC_SAP_UNNAMED (0x20) /* First unnamed service */
+#define NFC_LLC_SAP_MAX NFC_LLC_SAP_MASK /* Maximum SAP value */
+
/* Macros */
#define NFCD_INTERNAL G_GNUC_INTERNAL
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/Makefile
^
|
@@ -41,9 +41,12 @@
dbus_service_adapter.c \
dbus_service_error.c \
dbus_service_isodep.c \
+ dbus_service_local.c \
dbus_service_name.c \
dbus_service_ndef.c \
+ dbus_service_peer.c \
dbus_service_plugin.c \
+ dbus_service_util.c \
dbus_service_tag.c \
dbus_service_tag_t2.c
@@ -51,7 +54,9 @@
org.sailfishos.nfc.Adapter.c \
org.sailfishos.nfc.Daemon.c \
org.sailfishos.nfc.IsoDep.c \
+ org.sailfishos.nfc.LocalService.c \
org.sailfishos.nfc.NDEF.c \
+ org.sailfishos.nfc.Peer.c \
org.sailfishos.nfc.Tag.c \
org.sailfishos.nfc.TagType2.c
@@ -146,8 +151,6 @@
# Setting plugin
#
-PKGS += libmce-glib
-
SETTINGS_DIR = settings
SETTINGS_PLUGIN_SRC = \
settings_plugin.c
@@ -233,40 +236,6 @@
mkdir -p $@
#
-# D-Bus log plugin
-#
-
-PKGS += libdbuslogserver-gio
-
-DBUS_LOG_DIR = dbus_log
-DBUS_LOG_SRC = dbus_log_plugin.c
-
-DEBUG_DBUS_LOG_BUILD_DIR = $(DEBUG_BUILD_DIR)/$(DBUS_LOG_DIR)
-RELEASE_DBUS_LOG_BUILD_DIR = $(RELEASE_BUILD_DIR)/$(DBUS_LOG_DIR)
-COVERAGE_DBUS_LOG_BUILD_DIR = $(COVERAGE_BUILD_DIR)/$(DBUS_LOG_DIR)
-
-DEBUG_DBUS_LOG_OBJS = $(DBUS_LOG_SRC:%.c=$(DEBUG_DBUS_LOG_BUILD_DIR)/%.o)
-RELEASE_DBUS_LOG_OBJS = $(DBUS_LOG_SRC:%.c=$(RELEASE_DBUS_LOG_BUILD_DIR)/%.o)
-COVERAGE_DBUS_LOG_OBJS = $(DBUS_LOG_SRC:%.c=$(COVERAGE_DBUS_LOG_BUILD_DIR)/%.o)
-
-DEBUG_OBJS += $(DEBUG_DBUS_LOG_OBJS)
-RELEASE_OBJS += $(RELEASE_DBUS_LOG_OBJS)
-COVERAGE_OBJS += $(COVERAGE_DBUS_LOG_OBJS)
-
-$(DEBUG_DBUS_LOG_OBJS): | $(DEBUG_DBUS_LOG_BUILD_DIR)
-$(RELEASE_DBUS_LOG_OBJS): | $(RELEASE_DBUS_LOG_BUILD_DIR)
-$(COVERAGE_DBUS_LOG_OBJS): | $(COVERAGE_DBUS_LOG_BUILD_DIR)
-
-$(DEBUG_DBUS_LOG_BUILD_DIR):
- mkdir -p $@
-
-$(RELEASE_DBUS_LOG_BUILD_DIR):
- mkdir -p $@
-
-$(COVERAGE_DBUS_LOG_BUILD_DIR):
- mkdir -p $@
-
-#
# Tools and flags
#
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -38,7 +38,7 @@
#define GLOG_MODULE_NAME dbus_service_log
#include <gutil_log.h>
-#include <nfc_types.h>
+#include <nfc_peer_service.h>
#include <gio/gio.h>
@@ -48,6 +48,7 @@
typedef struct dbus_service_tag DBusServiceTag;
typedef struct dbus_service_tag_t2 DBusServiceTagType2;
typedef struct dbus_service_isodep DBusServiceIsoDep;
+typedef struct dbus_service_peer DBusServicePeer;
#define DBUS_SERVICE_ERROR (dbus_service_error_quark())
GQuark dbus_service_error_quark(void);
@@ -60,6 +61,10 @@
DBUS_SERVICE_ERROR_NOT_SUPPORTED, /* NotSupported */
DBUS_SERVICE_ERROR_ABORTED, /* Aborted */
DBUS_SERVICE_ERROR_NACK, /* NACK */
+ DBUS_SERVICE_ERROR_CANCELLED, /* Cancelled */
+ DBUS_SERVICE_ERROR_NO_SERVICE, /* NoService */
+ DBUS_SERVICE_ERROR_REJECTED, /* Rejected */
+ DBUS_SERVICE_ERROR_ALREADY_EXISTS, /* AlreadyExists */
DBUS_SERVICE_NUM_ERRORS
} DBusServiceError;
@@ -78,6 +83,27 @@
dbus_service_name_unown(
guint id);
+DBusServicePeer*
+dbus_service_plugin_find_peer(
+ DBusServicePlugin* plugin,
+ NfcPeer* peer);
+
+/* org.sailfishos.nfc.LocalService */
+
+typedef struct dbus_service_local {
+ NfcPeerService service;
+ DBusServicePlugin* plugin;
+ const char* dbus_name;
+ const char* obj_path;
+} DBusServiceLocal;
+
+DBusServiceLocal*
+dbus_service_local_new(
+ GDBusConnection* connection,
+ const char* obj_path,
+ const char* llc_name,
+ const char* dbus_name);
+
/* org.sailfishos.nfc.Adapter */
DBusServiceAdapter*
@@ -89,30 +115,33 @@
dbus_service_adapter_path(
DBusServiceAdapter* adapter);
+DBusServicePeer*
+dbus_service_adapter_find_peer(
+ DBusServiceAdapter* self,
+ NfcPeer* peer);
+
void
dbus_service_adapter_free(
DBusServiceAdapter* adapter);
/* org.sailfishos.nfc.Tag */
+struct dbus_service_tag {
+ GDBusConnection* connection;
+ const char* path;
+ NfcTag* tag;
+};
+
DBusServiceTag*
dbus_service_tag_new(
NfcTag* tag,
const char* parent_path,
GDBusConnection* connection);
-GDBusConnection*
-dbus_service_tag_connection(
- DBusServiceTag* tag);
-
-const char*
-dbus_service_tag_path(
- DBusServiceTag* tag);
-
NfcTargetSequence*
dbus_service_tag_sequence(
DBusServiceTag* tag,
- const char* sender);
+ GDBusMethodInvocation* call);
void
dbus_service_tag_free(
@@ -154,7 +183,25 @@
void
dbus_service_isodep_free(
- DBusServiceIsoDep* t2);
+ DBusServiceIsoDep* isodep);
+
+/* org.sailfishos.nfc.Peer */
+
+struct dbus_service_peer {
+ GDBusConnection* connection;
+ const char* path;
+ NfcPeer* peer;
+};
+
+DBusServicePeer*
+dbus_service_peer_new(
+ NfcPeer* peer,
+ const char* parent_path,
+ GDBusConnection* connection);
+
+void
+dbus_service_peer_free(
+ DBusServicePeer* peer);
#endif /* DBUS_SERVICE_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_adapter.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2020 Jolla Ltd.
+ * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -34,6 +34,7 @@
#include "dbus_service/org.sailfishos.nfc.Adapter.h"
#include <nfc_adapter.h>
+#include <nfc_peer.h>
#include <nfc_tag.h>
#include <gutil_idlepool.h>
@@ -48,11 +49,14 @@
EVENT_TARGET_PRESENCE,
EVENT_TAG_ADDED,
EVENT_TAG_REMOVED,
+ EVENT_PEER_ADDED,
+ EVENT_PEER_REMOVED,
EVENT_COUNT
};
enum {
CALL_GET_ALL,
+ CALL_GET_ALL2,
CALL_GET_INTERFACE_VERSION,
CALL_GET_ENABLED,
CALL_GET_POWERED,
@@ -60,6 +64,7 @@
CALL_GET_MODE,
CALL_GET_TARGET_PRESENT,
CALL_GET_TAGS,
+ CALL_GET_PEERS,
CALL_COUNT
};
@@ -69,12 +74,22 @@
OrgSailfishosNfcAdapter* iface;
GUtilIdlePool* pool;
GHashTable* tags;
+ GHashTable* peers;
NfcAdapter* adapter;
gulong event_id[EVENT_COUNT];
gulong call_id[CALL_COUNT];
};
-#define NFC_DBUS_ADAPTER_INTERFACE_VERSION (1)
+#define NFC_DBUS_ADAPTER_INTERFACE_VERSION (2)
+
+static
+int
+dbus_service_adapter_compare_strings(
+ const void* p1,
+ const void* p2)
+{
+ return strcmp(*(char* const*)p1, *(char* const*)p2);
+}
static
gboolean
@@ -94,6 +109,23 @@
}
static
+gboolean
+dbus_service_adapter_create_peer(
+ DBusServiceAdapter* self,
+ NfcPeer* peer)
+{
+ DBusServicePeer* dbus =
+ dbus_service_peer_new(peer, self->path, self->connection);
+
+ if (dbus) {
+ g_hash_table_replace(self->peers, g_strdup(peer->name), dbus);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+static
void
dbus_service_adapter_free_tag(
void* tag)
@@ -102,12 +134,11 @@
}
static
-int
-dbus_service_adapter_compare_strings(
- const void* p1,
- const void* p2)
+void
+dbus_service_adapter_free_peer(
+ void* peer)
{
- return strcmp(*(char* const*)p1, *(char* const*)p2);
+ dbus_service_peer_free((DBusServicePeer*)peer);
}
static
@@ -122,7 +153,7 @@
g_hash_table_iter_init(&it, self->tags);
while (g_hash_table_iter_next(&it, NULL, &value)) {
- out[n++] = dbus_service_tag_path((DBusServiceTag*)value);
+ out[n++] = ((DBusServiceTag*)value)->path;
}
out[n] = NULL;
qsort(out, n, sizeof(char*), dbus_service_adapter_compare_strings);
@@ -133,6 +164,28 @@
}
static
+const char* const*
+dbus_service_adapter_get_peer_paths(
+ DBusServiceAdapter* self)
+{
+ const char** out = g_new(const char*, g_hash_table_size(self->peers) + 1);
+ GHashTableIter it;
+ gpointer value;
+ int n = 0;
+
+ g_hash_table_iter_init(&it, self->peers);
+ while (g_hash_table_iter_next(&it, NULL, &value)) {
+ out[n++] = ((DBusServicePeer*)value)->path;
+ }
+ out[n] = NULL;
+ qsort(out, n, sizeof(char*), dbus_service_adapter_compare_strings);
+
+ /* Deallocated by the idle pool (actual strings are owned by peers) */
+ gutil_idle_pool_add(self->pool, out, g_free);
+ return out;
+}
+
+static
void
dbus_service_adapter_tags_changed(
DBusServiceAdapter* self)
@@ -141,6 +194,15 @@
dbus_service_adapter_get_tag_paths(self));
}
+static
+void
+dbus_service_adapter_peers_changed(
+ DBusServiceAdapter* self)
+{
+ org_sailfishos_nfc_adapter_emit_peers_changed(self->iface,
+ dbus_service_adapter_get_peer_paths(self));
+}
+
/*==========================================================================*
* NfcAdapter events
*==========================================================================*/
@@ -221,10 +283,61 @@
}
}
+static
+void
+dbus_service_adapter_peer_added(
+ NfcAdapter* adapter,
+ NfcPeer* peer,
+ void* user_data)
+{
+ DBusServiceAdapter* self = user_data;
+
+ if (dbus_service_adapter_create_peer(self, peer)) {
+ dbus_service_adapter_peers_changed(self);
+ }
+}
+
+static
+void
+dbus_service_adapter_peer_removed(
+ NfcAdapter* adapter,
+ NfcPeer* peer,
+ void* user_data)
+{
+ DBusServiceAdapter* self = user_data;
+
+ if (g_hash_table_remove(self->peers, (void*)peer->name)) {
+ dbus_service_adapter_peers_changed(self);
+ }
+}
+
+DBusServicePeer*
+dbus_service_adapter_find_peer(
+ DBusServiceAdapter* self,
+ NfcPeer* peer)
+{
+ if (G_LIKELY(self)) {
+ GHashTableIter it;
+ gpointer value;
+
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_error.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2020 Jolla Ltd.
+ * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -35,13 +35,17 @@
#define DBUS_SERVICE_ERROR_(error) "org.sailfishos.nfc.Error." error
static const GDBusErrorEntry dbus_service_errors[] = {
- { DBUS_SERVICE_ERROR_FAILED, DBUS_SERVICE_ERROR_("Failed") },
- { DBUS_SERVICE_ERROR_ACCESS_DENIED, DBUS_SERVICE_ERROR_("AccessDenied") },
- { DBUS_SERVICE_ERROR_INVALID_ARGS, DBUS_SERVICE_ERROR_("InvalidArgs") },
- { DBUS_SERVICE_ERROR_NOT_FOUND, DBUS_SERVICE_ERROR_("NotFound") },
- { DBUS_SERVICE_ERROR_NOT_SUPPORTED, DBUS_SERVICE_ERROR_("NotSupported") },
- { DBUS_SERVICE_ERROR_ABORTED, DBUS_SERVICE_ERROR_("Aborted") },
- { DBUS_SERVICE_ERROR_NACK, DBUS_SERVICE_ERROR_("NACK") }
+ { DBUS_SERVICE_ERROR_FAILED, DBUS_SERVICE_ERROR_("Failed") },
+ { DBUS_SERVICE_ERROR_ACCESS_DENIED, DBUS_SERVICE_ERROR_("AccessDenied") },
+ { DBUS_SERVICE_ERROR_INVALID_ARGS, DBUS_SERVICE_ERROR_("InvalidArgs") },
+ { DBUS_SERVICE_ERROR_NOT_FOUND, DBUS_SERVICE_ERROR_("NotFound") },
+ { DBUS_SERVICE_ERROR_NOT_SUPPORTED, DBUS_SERVICE_ERROR_("NotSupported") },
+ { DBUS_SERVICE_ERROR_ABORTED, DBUS_SERVICE_ERROR_("Aborted") },
+ { DBUS_SERVICE_ERROR_NACK, DBUS_SERVICE_ERROR_("NACK") },
+ { DBUS_SERVICE_ERROR_CANCELLED, DBUS_SERVICE_ERROR_("Cancelled") },
+ { DBUS_SERVICE_ERROR_NO_SERVICE, DBUS_SERVICE_ERROR_("NoService") },
+ { DBUS_SERVICE_ERROR_REJECTED, DBUS_SERVICE_ERROR_("Rejected") },
+ { DBUS_SERVICE_ERROR_ALREADY_EXISTS, DBUS_SERVICE_ERROR_("AlreadyExists") }
};
G_STATIC_ASSERT(G_N_ELEMENTS(dbus_service_errors) == DBUS_SERVICE_NUM_ERRORS);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_isodep.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -31,9 +32,11 @@
*/
#include "dbus_service.h"
+#include "dbus_service_util.h"
#include "dbus_service/org.sailfishos.nfc.IsoDep.h"
#include <nfc_tag_t4.h>
+#include <nfc_target.h>
#include <gutil_misc.h>
@@ -41,6 +44,9 @@
CALL_GET_ALL,
CALL_GET_INTERFACE_VERSION,
CALL_TRANSMIT,
+ CALL_GET_ALL2,
+ CALL_GET_ACTIVATION_PARAMETERS,
+ CALL_RESET,
CALL_COUNT
};
@@ -51,7 +57,7 @@
gulong call_id[CALL_COUNT];
};
-#define NFC_DBUS_ISODEP_INTERFACE_VERSION (1)
+#define NFC_DBUS_ISODEP_INTERFACE_VERSION (3)
typedef struct dbus_service_isodep_async_call {
OrgSailfishosNfcIsoDep* iface;
@@ -59,25 +65,12 @@
} DBusServiceIsoDepAsyncCall;
static
-GVariant*
-dbus_service_isodep_dup_data_as_variant(
- const void* data,
- guint size)
-{
- return size ?
- g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, data, size, 1) :
- g_variant_new_from_data(G_VARIANT_TYPE("ay"), NULL, 0, TRUE,
- NULL, NULL);
-}
-
-static
NfcTargetSequence*
dbus_service_isodep_sequence(
DBusServiceIsoDep* self,
GDBusMethodInvocation* call)
{
- return dbus_service_tag_sequence(self->owner,
- g_dbus_method_invocation_get_sender(call));
+ return dbus_service_tag_sequence(self->owner, call);
}
/*==========================================================================*
@@ -163,7 +156,7 @@
if (sw) {
GDEBUG("%04X", sw);
org_sailfishos_nfc_iso_dep_complete_transmit(async->iface, async->call,
- dbus_service_isodep_dup_data_as_variant(data, len),
+ dbus_service_dup_byte_array_as_variant(data, len),
sw >> 8, sw & 0xff);
} else {
GDEBUG("oops");
@@ -206,6 +199,127 @@
return TRUE;
}
+/* Interface version 2 */
+
+static
+GVariant*
+dbus_service_isodep_get_act_parameters(
+ NfcTagType4* t4,
+ const NfcParamIsoDep* act)
+{
+ GVariantBuilder builder;
+
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
+ if (G_LIKELY(act)) {
+ switch(t4->tag.target->technology) {
+ case NFC_TECHNOLOGY_A:
+ dbus_service_dict_add_byte(&builder, "T0", act->a.t0);
+ if (act->a.t0 & NFC_PARAM_ISODEP_T0_A) {
+ dbus_service_dict_add_byte(&builder, "TA", act->a.ta);
+ }
+ if (act->a.t0 & NFC_PARAM_ISODEP_T0_B) {
+ dbus_service_dict_add_byte(&builder, "TB", act->a.tb);
+ }
+ if (act->a.t0 & NFC_PARAM_ISODEP_T0_C) {
+ dbus_service_dict_add_byte(&builder, "TC", act->a.tc);
+ }
+ dbus_service_dict_add_byte_array_data(&builder, "HB", &act->a.t1);
+ break;
+ case NFC_TECHNOLOGY_B:
+ dbus_service_dict_add_byte(&builder, "MBLI", act->b.mbli);
+ dbus_service_dict_add_byte(&builder, "DID", act->b.did);
+ if (act->b.hlr.bytes) {
+ dbus_service_dict_add_byte_array_data(&builder, "HLR",
+ &act->b.hlr);
+ }
+ break;
+ case NFC_TECHNOLOGY_F:
+ case NFC_TECHNOLOGY_UNKNOWN:
+ break;
+ }
+ }
+ return g_variant_builder_end(&builder);
+}
+
+/* GetAll2 */
+
+static
+gboolean
+dbus_service_isodep_handle_get_all2(
+ OrgSailfishosNfcIsoDep* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceIsoDep* self)
+{
+ NfcTagType4* t4 = self->t4;
+
+ org_sailfishos_nfc_iso_dep_complete_get_all2(iface, call,
+ NFC_DBUS_ISODEP_INTERFACE_VERSION,
+ dbus_service_isodep_get_act_parameters(t4, t4->iso_dep));
+ return TRUE;
+}
+
+/* GetActivationParameters */
+
+static
+gboolean
+dbus_service_isodep_handle_get_act_parameters(
+ OrgSailfishosNfcIsoDep* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceIsoDep* self)
+{
+ NfcTagType4* t4 = self->t4;
+
+ org_sailfishos_nfc_iso_dep_complete_get_activation_parameters(iface,
+ call, dbus_service_isodep_get_act_parameters(t4, t4->iso_dep));
+ return TRUE;
+}
+
+/* Interface version 3 */
+
+/* Reset*/
+
+static
+void
+dbus_service_isodep_handle_reset_done(
+ NfcTagType4* tag,
+ gboolean ok,
+ void* user_data)
+{
+ DBusServiceIsoDepAsyncCall* async = user_data;
+
+ GDEBUG("ISO-DEP reset %s", ok ? "succeeded" : "failed");
+
+ if (ok) {
+ org_sailfishos_nfc_iso_dep_complete_reset(async->iface, async->call);
+ } else {
+ GDEBUG("oops");
+ g_dbus_method_invocation_return_error_literal(async->call,
+ DBUS_SERVICE_ERROR, DBUS_SERVICE_ERROR_FAILED,
+ "ISO-DEP reset failed");
+ }
+}
+
+static
+gboolean
+dbus_service_isodep_handle_reset(
+ OrgSailfishosNfcIsoDep* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceIsoDep* self)
+{
+ DBusServiceIsoDepAsyncCall* async =
+ dbus_service_isodep_async_call_new(iface, call);
+
+ if (!nfc_isodep_reset(self->t4, dbus_service_isodep_sequence(self, call),
+ dbus_service_isodep_handle_reset_done,
+ dbus_service_isodep_async_call_free1, async)) {
+ dbus_service_isodep_async_call_free(async);
+ g_dbus_method_invocation_return_error_literal(call,
+ DBUS_SERVICE_ERROR, DBUS_SERVICE_ERROR_FAILED,
+ "Failed to submit Reset");
+ }
+ return TRUE;
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_local.c
^
|
@@ -0,0 +1,394 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "dbus_service.h"
+#include "dbus_service_util.h"
+#include "dbus_service/org.sailfishos.nfc.LocalService.h"
+
+#include <nfc_peer_connection_impl.h>
+#include <nfc_peer_service_impl.h>
+#include <nfc_peer_socket_impl.h>
+#include <nfc_tag.h>
+
+typedef NfcPeerServiceClass DBusServiceLocalObjectClass;
+typedef struct dbus_service_local_object {
+ DBusServiceLocal pub;
+ OrgSailfishosNfcLocalService* proxy;
+ char* peer_path;
+ char* dbus_name;
+ char* obj_path;
+ guint watch_id;
+} DBusServiceLocalObject;
+
+#define DBUS_SERVICE_TYPE_LOCAL_OBJECT (dbus_service_local_object_get_type())
+G_DEFINE_TYPE(DBusServiceLocalObject, dbus_service_local_object, \
+ NFC_TYPE_PEER_SERVICE)
+#define DBUS_SERVICE_LOCAL_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj,\
+ DBUS_SERVICE_TYPE_LOCAL_OBJECT, DBusServiceLocalObject))
+
+typedef NfcPeerSocketClass DBusServiceConnectionClass;
+typedef struct dbus_service_connection {
+ NfcPeerSocket socket;
+ GCancellable* cancel_accept;
+ OrgSailfishosNfcLocalService* proxy;
+} DBusServiceConnection;
+
+#define DBUS_SERVICE_TYPE_CONNECTION (dbus_service_connection_get_type())
+G_DEFINE_TYPE(DBusServiceConnection, dbus_service_connection, \
+ NFC_TYPE_PEER_SOCKET)
+#define DBUS_SERVICE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj,\
+ DBUS_SERVICE_TYPE_CONNECTION, DBusServiceConnection))
+
+#define LOCAL_SERVICE_INTERFACE "org.sailfishos.nfc.LocalService"
+#define PEER_ARRIVED "PeerArrived"
+#define PEER_LEFT "PeerLeft"
+#define DATAGRAM_RECEIVED "DatagramReceived"
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+GDBusConnection*
+dbus_service_local_connection(
+ DBusServiceLocalObject* self)
+{
+ return g_dbus_proxy_get_connection(G_DBUS_PROXY(self->proxy));
+}
+
+static
+void
+dbus_service_local_peer_notify(
+ DBusServiceLocalObject* self,
+ const char* method,
+ const char* peer_path)
+{
+ GDBusConnection* connection = dbus_service_local_connection(self);
+ GDBusMessage* message = g_dbus_message_new_method_call(self->dbus_name,
+ self->obj_path, LOCAL_SERVICE_INTERFACE, method);
+
+ /*
+ * Generated stub doesn't allow setting "no-reply-expected" flag,
+ * we have to build and send D-Bus message manually.
+ */
+ g_dbus_message_set_flags(message, g_dbus_message_get_flags(message) |
+ G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED);
+ g_dbus_message_set_body(message, g_variant_new("(o)", peer_path));
+ g_dbus_connection_send_message(connection, message,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
+ g_object_unref(message);
+}
+
+static
+void
+dbus_service_local_peer_left_notify(
+ DBusServiceLocalObject* self)
+{
+ if (self->peer_path) {
+ dbus_service_local_peer_notify(self, PEER_LEFT, self->peer_path);
+ g_free(self->peer_path);
+ self->peer_path = NULL;
+ }
+}
+
+/*==========================================================================*
+ * Connection
+ *==========================================================================*/
+
+static
+void
+dbus_service_connection_state_changed(
+ NfcPeerConnection* connection)
+{
+ DBusServiceConnection* self = DBUS_SERVICE_CONNECTION(connection);
+
+ if (self->cancel_accept && connection->state != NFC_LLC_CO_ACCEPTING) {
+ GDEBUG("Cancelling Accept D-Bus call");
+ g_cancellable_cancel(self->cancel_accept);
+ g_object_unref(self->cancel_accept);
+ self->cancel_accept = NULL;
+ }
+ NFC_PEER_CONNECTION_CLASS(dbus_service_connection_parent_class)->
+ state_changed(connection);
+}
+
+static
+void
+dbus_service_connection_accept_done(
+ GObject* proxy,
+ GAsyncResult* result,
+ gpointer user_data)
+{
+ DBusServiceConnection* self = DBUS_SERVICE_CONNECTION(user_data);
+ NfcPeerConnection* connection = NFC_PEER_CONNECTION(self);
+ gboolean accepted = FALSE;
+ GError* error = NULL;
+
+ if (self->cancel_accept) {
+ g_object_unref(self->cancel_accept);
+ self->cancel_accept = NULL;
+ }
+ if (org_sailfishos_nfc_local_service_call_accept_finish(self->proxy,
+ &accepted, NULL, result, &error)) {
+ nfc_peer_connection_accepted(connection);
+ } else {
+ GDEBUG("%s", GERRMSG(error));
+ g_error_free(error);
+ nfc_peer_connection_rejected(connection);
+ }
+ nfc_peer_connection_unref(connection);
+}
+
+static
+void
+dbus_service_connection_accept(
+ NfcPeerConnection* conn)
+{
+ DBusServiceConnection* self = DBUS_SERVICE_CONNECTION(conn);
+ NfcPeerSocket* socket = &self->socket;
+
+ /* Ask D-Bus client to accept the connection */
+ nfc_peer_connection_ref(conn);
+ self->cancel_accept = g_cancellable_new();
+ org_sailfishos_nfc_local_service_call_accept(self->proxy, conn->rsap,
+ g_variant_new_handle(0), socket->fdl, self->cancel_accept,
+ dbus_service_connection_accept_done, self);
+}
+
+static
+void
+dbus_service_connection_finalize(
+ GObject* object)
+{
+ DBusServiceConnection* self = DBUS_SERVICE_CONNECTION(object);
+
+ /*
+ * self->cancel_accept must be NULL because this object remains
+ * referenced for the entire duration of the Accept call.
+ */
+ GASSERT(!self->cancel_accept);
+ if (self->proxy) {
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_peer.c
^
|
@@ -0,0 +1,689 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "dbus_service.h"
+#include "dbus_service/org.sailfishos.nfc.Peer.h"
+
+#include <nfc_peer.h>
+#include <nfc_peer_service_impl.h>
+#include <nfc_peer_socket.h>
+
+#include <gutil_macros.h>
+#include <gutil_misc.h>
+
+#include <gio/gunixfdlist.h>
+
+enum {
+ PEER_INITIALIZED,
+ PEER_WELL_KNOWN_SERVICES_CHANGED,
+ PEER_EVENT_COUNT
+};
+
+enum {
+ CALL_GET_ALL,
+ CALL_GET_INTERFACE_VERSION,
+ CALL_GET_PRESENT,
+ CALL_GET_TECHNOLOGY,
+ CALL_GET_INTERFACES,
+ CALL_GET_WELL_KNOWN_SERVICES,
+ CALL_DEACTIVATE,
+ CALL_CONNECT_ACCESS_POINT,
+ CALL_CONNECT_SERVICE_NAME,
+ CALL_COUNT
+};
+
+typedef struct dbus_service_peer_call DBusServicePeerCall;
+typedef struct dbus_service_peer_priv DBusServicePeerPriv;
+
+typedef
+void
+(*DBusServicePeerCallFunc)(
+ GDBusMethodInvocation* call,
+ DBusServicePeerPriv* self);
+
+struct dbus_service_peer_call {
+ DBusServicePeerCall* next;
+ GDBusMethodInvocation* invocation;
+ DBusServicePeerCallFunc func;
+};
+
+typedef struct dbus_service_peer_call_queue {
+ DBusServicePeerCall* first;
+ DBusServicePeerCall* last;
+} DBusServicePeerCallQueue;
+
+typedef
+void
+(*DBusServicePeerAsyncConnectCompleteFunc)(
+ OrgSailfishosNfcPeer* iface,
+ GDBusMethodInvocation* call,
+ GUnixFDList* fdl,
+ GVariant* fd);
+
+typedef struct dbus_service_peer_async_connect {
+ OrgSailfishosNfcPeer* iface;
+ GDBusMethodInvocation* call;
+ NfcPeerConnection* connection;
+ DBusServicePeerAsyncConnectCompleteFunc complete;
+} DBusServicePeerAsyncConnect;
+
+struct dbus_service_peer_priv {
+ DBusServicePeer pub;
+ char* path;
+ DBusServicePeerCallQueue queue;
+ OrgSailfishosNfcPeer* iface;
+ gulong call_id[CALL_COUNT];
+ gulong peer_event_id[PEER_EVENT_COUNT];
+ NfcPeerService* peer_client;
+};
+
+#define NFC_DBUS_PEER_INTERFACE "org.sailfishos.nfc.Peer"
+#define NFC_DBUS_PEER_INTERFACE_VERSION (1)
+
+static const char* const dbus_service_peer_default_interfaces[] = {
+ NFC_DBUS_PEER_INTERFACE, NULL
+};
+
+static inline DBusServicePeerPriv* dbus_service_peer_cast(DBusServicePeer* pub)
+ { return G_LIKELY(pub) ? G_CAST(pub, DBusServicePeerPriv, pub) : NULL; }
+
+/*==========================================================================*
+ * Peer client
+ *==========================================================================*/
+
+typedef NfcPeerServiceClass DBusServicePeerClientClass;
+typedef struct dbus_service_peer_client {
+ NfcPeerService service;
+} DBusServicePeerClient;
+
+G_DEFINE_TYPE(DBusServicePeerClient, dbus_service_peer_client, \
+ NFC_TYPE_PEER_SERVICE)
+#define DBUS_SERVICE_TYPE_PEER_CLIENT dbus_service_peer_client_get_type()
+#define DBUS_SERVICE_PEER_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ DBUS_SERVICE_TYPE_PEER_CLIENT, DBusServicePeerClient))
+
+static
+NfcPeerConnection*
+dbus_service_peer_client_new_connect(
+ NfcPeerService* self,
+ guint8 rsap,
+ const char* name)
+{
+ return (NfcPeerConnection*)nfc_peer_socket_new_connect(self, rsap, name);
+}
+
+static
+void
+dbus_service_peer_client_init(
+ DBusServicePeerClient* self)
+{
+}
+
+static
+void
+dbus_service_peer_client_class_init(
+ DBusServicePeerClientClass* klass)
+{
+ klass->new_connect = dbus_service_peer_client_new_connect;
+}
+
+static
+NfcPeerService*
+dbus_service_peer_client_get(
+ DBusServicePeerPriv* self)
+{
+ if (!self->peer_client) {
+ DBusServicePeerClient* client = g_object_new
+ (DBUS_SERVICE_TYPE_PEER_CLIENT, NULL);
+
+ self->peer_client = NFC_PEER_SERVICE(client);
+ nfc_peer_service_init_base(self->peer_client, NULL);
+ if (!nfc_peer_register_service(self->pub.peer, self->peer_client)) {
+ nfc_peer_service_unref(self->peer_client);
+ self->peer_client = NULL;
+ }
+ }
+ return self->peer_client;
+}
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+dbus_service_peer_free_call(
+ DBusServicePeerCall* call)
+{
+ g_object_unref(call->invocation);
+ g_slice_free(DBusServicePeerCall, call);
+}
+
+static
+void
+dbus_service_peer_queue_call(
+ DBusServicePeerCallQueue* queue,
+ GDBusMethodInvocation* invocation,
+ DBusServicePeerCallFunc func)
+{
+ DBusServicePeerCall* call = g_slice_new0(DBusServicePeerCall);
+
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_plugin.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -14,8 +14,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -37,11 +37,12 @@
#include <nfc_core.h>
#include <nfc_adapter.h>
#include <nfc_manager.h>
+#include <nfc_peer_service.h>
#include <nfc_plugin_impl.h>
#include <gutil_idlepool.h>
+#include <gutil_macros.h>
#include <gutil_misc.h>
-#include <gutil_strv.h>
#include <stdlib.h>
@@ -50,6 +51,7 @@
enum {
EVENT_ADAPTER_ADDED,
EVENT_ADAPTER_REMOVED,
+ EVENT_MODE_CHANGED,
EVENT_COUNT
};
@@ -59,16 +61,32 @@
CALL_GET_ADAPTERS,
CALL_GET_ALL2,
CALL_GET_DAEMON_VERSION,
+ CALL_GET_ALL3,
+ CALL_GET_MODE,
+ CALL_REQUEST_MODE,
+ CALL_RELEASE_MODE,
+ CALL_REGISTER_LOCAL_SERVICE,
+ CALL_UNREGISTER_LOCAL_SERVICE,
CALL_COUNT
};
+typedef struct dbus_service_client {
+ char* dbus_name;
+ guint watch_id;
+ DBusServicePlugin* plugin;
+ GHashTable* peer_services; /* objpath => DBusServiceLocal */
+ GHashTable* mode_requests; /* id => NfcModeRequest */
+} DBusServiceClient;
+
typedef NfcPluginClass DBusServicePluginClass;
struct dbus_service_plugin {
NfcPlugin parent;
guint own_name_id;
+ guint last_mode_request_id;
GUtilIdlePool* pool;
GDBusConnection* connection;
GHashTable* adapters;
+ GHashTable* clients;
NfcManager* manager;
OrgSailfishosNfcDaemon* iface;
gulong event_id[EVENT_COUNT];
@@ -83,7 +101,7 @@
#define NFC_SERVICE "org.sailfishos.nfc.daemon"
#define NFC_DAEMON_PATH "/"
-#define NFC_DBUS_PLUGIN_INTERFACE_VERSION (2)
+#define NFC_DBUS_PLUGIN_INTERFACE_VERSION (3)
static
gboolean
@@ -111,6 +129,39 @@
}
static
+void
+dbus_service_plugin_peer_service_destroy(
+ gpointer user_data)
+{
+ DBusServiceLocal* local = user_data;
+ DBusServicePlugin* plugin = local->plugin;
+ NfcPeerService* service = &local->service;
+
+ local->plugin = NULL;
+ nfc_manager_unregister_service(plugin->manager, service);
+ nfc_peer_service_disconnect_all(service);
+ nfc_peer_service_unref(service);
+}
+
+static
+void
+dbus_service_plugin_client_destroy(
+ void* value)
+{
+ DBusServiceClient* client = value;
+
+ if (client->peer_services) {
+ g_hash_table_destroy(client->peer_services);
+ }
+ if (client->mode_requests) {
+ g_hash_table_destroy(client->mode_requests);
+ }
+ g_bus_unwatch_name(client->watch_id);
+ g_free(client->dbus_name);
+ gutil_slice_free(client);
+}
+
+static
int
dbus_service_plugin_compare_strings(
const void* p1,
@@ -150,13 +201,95 @@
dbus_service_plugin_get_adapter_paths(self));
}
+static
+void
+dbus_service_plugin_client_gone(
+ GDBusConnection* bus,
+ const char* name,
+ gpointer plugin)
+{
+ DBusServicePlugin* self = DBUS_SERVICE_PLUGIN(plugin);
+
+ GDEBUG("Name '%s' has disappeared", name);
+ g_hash_table_remove(self->clients, name);
+}
+
+static
+DBusServiceClient*
+dbus_service_plugin_client_new(
+ DBusServicePlugin* self,
+ const char* dbus_name)
+{
+ DBusServiceClient* client = g_slice_new0(DBusServiceClient);
+
+ client->dbus_name = g_strdup(dbus_name);
+ client->watch_id = g_bus_watch_name_on_connection(self->connection,
+ client->dbus_name, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL,
+ dbus_service_plugin_client_gone, self, NULL);
+ return client;
+}
+
+static
+DBusServiceClient*
+dbus_service_plugin_client_get(
+ DBusServicePlugin* self,
+ const char* dbus_name)
+{
+ DBusServiceClient* client = NULL;
+
+ if (self->clients) {
+ client = g_hash_table_lookup(self->clients, dbus_name);
+ } else {
+ self->clients = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ dbus_service_plugin_client_destroy);
+ }
+ if (!client) {
+ client = dbus_service_plugin_client_new(self, dbus_name);
+ g_hash_table_insert(self->clients, client->dbus_name, client);
+ }
+ return client;
+}
+
+static
+DBusServiceLocal*
+dbus_service_plugin_register_local_service(
+ DBusServicePlugin* self,
+ const char* peer_name,
+ const char* obj_path,
+ const char* dbus_name)
+{
+ DBusServiceLocal* local = dbus_service_local_new(self->connection,
+ obj_path, peer_name, dbus_name);
+
+ if (local) {
+ NfcPeerService* service = &local->service;
+
+ if (nfc_manager_register_service(self->manager, service)) {
+ DBusServiceClient* client = dbus_service_plugin_client_get
+ (self, dbus_name);
+
+ if (!client->peer_services) {
+ client->peer_services =
+ g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ dbus_service_plugin_peer_service_destroy);
+ }
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_tag.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -31,6 +32,7 @@
*/
#include "dbus_service.h"
+#include "dbus_service_util.h"
#include "dbus_service/org.sailfishos.nfc.Tag.h"
#include <nfc_tag.h>
@@ -40,6 +42,7 @@
#include <nfc_ndef.h>
#include <gutil_idlepool.h>
+#include <gutil_macros.h>
#include <gutil_misc.h>
enum {
@@ -64,16 +67,21 @@
CALL_DEACTIVATE,
CALL_ACQUIRE,
CALL_RELEASE,
+ CALL_GET_ALL3,
+ CALL_GET_POLL_PARAMETERS,
+ CALL_TRANSCEIVE,
CALL_COUNT
};
+typedef struct dbus_service_tag_priv DBusServiceTagPriv;
+typedef struct dbus_service_tag_call DBusServiceTagCall;
+
typedef
void
(*DBusServiceTagCallFunc)(
GDBusMethodInvocation* call,
- DBusServiceTag* self);
+ DBusServiceTagPriv* self);
-typedef struct dbus_service_tag_call DBusServiceTagCall;
struct dbus_service_tag_call {
DBusServiceTagCall* next;
GDBusMethodInvocation* invocation;
@@ -90,7 +98,7 @@
guint watch_id;
guint count;
NfcTargetSequence* seq;
- DBusServiceTag* tag;
+ DBusServiceTagPriv* tag;
} DBusServiceTagLock;
typedef struct dbus_service_tag_lock_waiter {
@@ -98,16 +106,20 @@
GSList* pending_calls; /* GDBusMethodInvocation references */
} DBusServiceTagLockWaiter;
-struct dbus_service_tag {
+typedef struct dbus_service_tag_async_call {
+ OrgSailfishosNfcTag* iface;
+ GDBusMethodInvocation* call;
+} DBusServiceTagAsyncCall;
+
+struct dbus_service_tag_priv {
+ DBusServiceTag pub;
char* path;
- GDBusConnection* connection;
OrgSailfishosNfcTag* iface;
GUtilIdlePool* pool;
- GSList* lock_waters;
+ GSList* lock_waiters;
DBusServiceTagLock* lock;
DBusServiceTagCallQueue queue;
GSList* ndefs;
- NfcTag* tag;
gulong target_event_id[TARGET_EVENT_COUNT];
gulong tag_event_id[TAG_EVENT_COUNT];
gulong call_id[CALL_COUNT];
@@ -117,21 +129,24 @@
};
#define NFC_DBUS_TAG_INTERFACE "org.sailfishos.nfc.Tag"
-#define NFC_DBUS_TAG_INTERFACE_VERSION (2)
+#define NFC_DBUS_TAG_INTERFACE_VERSION (4)
static const char* const dbus_service_tag_default_interfaces[] = {
NFC_DBUS_TAG_INTERFACE, NULL
};
+static inline DBusServiceTagPriv* dbus_service_tag_cast(DBusServiceTag* pub)
+ { return G_LIKELY(pub) ? G_CAST(pub, DBusServiceTagPriv, pub) : NULL; }
+
static
DBusServiceTagLockWaiter*
dbus_service_tag_find_waiter(
- DBusServiceTag* self,
+ DBusServiceTagPriv* self,
const char* name)
{
GSList* l;
- for (l = self->lock_waters; l; l = l->next) {
+ for (l = self->lock_waiters; l; l = l->next) {
DBusServiceTagLockWaiter* waiter = l->data;
if (!g_strcmp0(waiter->lock->name, name)) {
@@ -143,10 +158,14 @@
NfcTargetSequence*
dbus_service_tag_sequence(
- DBusServiceTag* self,
- const char* sender)
+ DBusServiceTag* pub,
+ GDBusMethodInvocation* call)
{
- if (G_LIKELY(self) && G_LIKELY(sender)) {
+ const char* sender = g_dbus_method_invocation_get_sender(call);
+
+ if (G_LIKELY(pub) && G_LIKELY(sender)) {
+ DBusServiceTagPriv* self = dbus_service_tag_cast(pub);
+
if (self->lock && !g_strcmp0(self->lock->name, sender)) {
return self->lock->seq;
} else {
@@ -162,6 +181,53 @@
}
static
+GVariant*
+dbus_service_tag_get_poll_parameters(
+ NfcTag* tag,
+ const NfcParamPoll* poll)
+{
+ GVariantBuilder builder;
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
+
+ if (G_LIKELY(tag) && G_UNLIKELY(poll)) {
+ const NfcTarget* target = tag->target;
+ const NfcParamPollA* poll_a = NULL;
+ const NfcParamPollB* poll_b = NULL;
+
+ if (G_LIKELY(target)) {
+ switch(tag->target->technology) {
+ case NFC_TECHNOLOGY_B:
+ poll_b = &poll->b;
+ dbus_service_dict_add_byte_array(&builder, "APPDATA",
+ poll_b->app_data, sizeof(poll_b->app_data));
+ if (poll_b->prot_info.bytes) {
+ dbus_service_dict_add_byte_array_data(&builder, "PROTINFO",
+ &poll_b->prot_info);
+ }
+ if (poll_b->nfcid0.bytes) {
+ dbus_service_dict_add_byte_array_data(&builder, "NFCID0",
+ &poll_b->nfcid0);
+ }
+ break;
+ case NFC_TECHNOLOGY_A:
+ poll_a = &poll->a;
+ dbus_service_dict_add_byte(&builder, "SEL_RES",
+ poll_a->sel_res);
+ if (poll_a->nfcid1.bytes) {
+ dbus_service_dict_add_byte_array_data(&builder, "NFCID1",
+ &poll_a->nfcid1);
+ }
+ break;
+ case NFC_TECHNOLOGY_F:
+ case NFC_TECHNOLOGY_UNKNOWN:
+ break;
+ }
+ }
+ }
+ return g_variant_builder_end(&builder);
+}
+
+static
void
dbus_service_tag_lock_cancel_acquire(
gpointer data)
@@ -180,7 +246,7 @@
gpointer user_data)
{
GDBusMethodInvocation* acquire = data;
- DBusServiceTag* dbus = user_data;
+ DBusServiceTagPriv* dbus = user_data;
org_sailfishos_nfc_tag_complete_acquire(dbus->iface, acquire);
g_object_unref(acquire);
@@ -227,7 +293,7 @@
NfcTarget* target,
void* user_data)
{
- DBusServiceTag* self = user_data;
+ DBusServiceTagPriv* self = user_data;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_tag_t2.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2020 Jolla Ltd.
+ * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -126,8 +126,7 @@
DBusServiceTagType2* self,
GDBusMethodInvocation* call)
{
- return dbus_service_tag_sequence(self->owner,
- g_dbus_method_invocation_get_sender(call));
+ return dbus_service_tag_sequence(self->owner, call);
}
/*==========================================================================*
@@ -528,8 +527,6 @@
NfcTagType2* t2,
DBusServiceTag* owner)
{
- GDBusConnection* connection = dbus_service_tag_connection(owner);
- const char* path = dbus_service_tag_path(owner);
DBusServiceTagType2* self = g_new0(DBusServiceTagType2, 1);
GError* error = NULL;
@@ -570,11 +567,11 @@
G_CALLBACK(dbus_service_tag_t2_handle_write_data), self);
if (g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON
- (self->iface), connection, path, &error)) {
- GDEBUG("Created D-Bus object %s (Type2)", path);
+ (self->iface), owner->connection, owner->path, &error)) {
+ GDEBUG("Created D-Bus object %s (Type2)", owner->path);
return self;
} else {
- GERR("%s: %s", path, GERRMSG(error));
+ GERR("%s: %s", owner->path, GERRMSG(error));
g_error_free(error);
dbus_service_tag_t2_free_unexported(self);
return NULL;
@@ -586,8 +583,7 @@
DBusServiceTagType2* self)
{
if (self) {
- GDEBUG("Removing D-Bus object %s (Type2)",
- dbus_service_tag_path(self->owner));
+ GDEBUG("Removing D-Bus object %s (Type2)", self->owner->path);
g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON
(self->iface));
dbus_service_tag_t2_free_unexported(self);
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_util.c
^
|
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "dbus_service_util.h"
+
+static
+void
+dbus_service_dict_add_value(
+ GVariantBuilder* builder,
+ const char* name,
+ GVariant* value)
+{
+ g_variant_builder_add(builder, "{sv}", name, value);
+}
+
+GVariant*
+dbus_service_dup_byte_array_as_variant(
+ const void* data,
+ guint size)
+{
+ return size ?
+ g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, data, size, 1) :
+ g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING, NULL, 0, TRUE,
+ NULL, NULL);
+}
+
+GVariant*
+dbus_service_dup_byte_array_data_as_variant(
+ const GUtilData* data)
+{
+ return data ?
+ dbus_service_dup_byte_array_as_variant(data->bytes, data->size) :
+ dbus_service_dup_byte_array_as_variant(NULL, 0);
+}
+
+void
+dbus_service_dict_add_byte(
+ GVariantBuilder* builder,
+ const char* name,
+ guint8 value)
+{
+ dbus_service_dict_add_value(builder, name, g_variant_new_byte(value));
+}
+
+void
+dbus_service_dict_add_byte_array(
+ GVariantBuilder* builder,
+ const char* name,
+ const void* data,
+ guint size)
+{
+ dbus_service_dict_add_value(builder, name,
+ dbus_service_dup_byte_array_as_variant(data, size));
+}
+
+void
+dbus_service_dict_add_byte_array_data(
+ GVariantBuilder* builder,
+ const char* name,
+ const GUtilData* data)
+{
+ dbus_service_dict_add_value(builder, name,
+ dbus_service_dup_byte_array_data_as_variant(data));
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/dbus_service_util.h
^
|
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DBUS_SERVICE_UTIL_H
+#define DBUS_SERVICE_UTIL_H
+
+#include <gutil_types.h>
+
+GVariant*
+dbus_service_dup_byte_array_as_variant(
+ const void* data,
+ guint size);
+
+GVariant*
+dbus_service_dup_byte_array_data_as_variant(
+ const GUtilData* data);
+
+void
+dbus_service_dict_add_byte(
+ GVariantBuilder* builder,
+ const char* name,
+ guint8 value);
+
+void
+dbus_service_dict_add_byte_array(
+ GVariantBuilder* builder,
+ const char* name,
+ const void* data,
+ guint size);
+
+void
+dbus_service_dict_add_byte_array_data(
+ GVariantBuilder* builder,
+ const char* name,
+ const GUtilData* data);
+
+#endif /* DBUS_SERVICE_UTIL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.Adapter.xml
^
|
@@ -59,5 +59,22 @@
<signal name="TagsChanged">
<arg name="tags" type="ao"/>
</signal>
+ <!-- Interface version 2 (since 1.1.0) -->
+ <method name="GetAll2">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="enabled" type="b" direction="out"/>
+ <arg name="powered" type="b" direction="out"/>
+ <arg name="supported_modes" type="u" direction="out"/>
+ <arg name="mode" type="u" direction="out"/>
+ <arg name="present" type="b" direction="out"/>
+ <arg name="tags" type="ao" direction="out"/>
+ <arg name="peers" type="ao" direction="out"/>
+ </method>
+ <method name="GetPeers">
+ <arg name="peers" type="ao" direction="out"/>
+ </method>
+ <signal name="PeersChanged">
+ <arg name="peers" type="ao"/>
+ </signal>
</interface>
</node>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.Daemon.xml
^
|
@@ -12,7 +12,6 @@
<method name="GetAdapters">
<arg name="adapters" type="ao" direction="out"/>
</method>
- <!-- Signals -->
<signal name="AdaptersChanged">
<arg name="adapters" type="ao"/>
</signal>
@@ -25,5 +24,46 @@
<method name="GetDaemonVersion">
<arg name="daemon_version" type="i" direction="out"/>
</method>
+ <!-- Interface version 3 (since 1.1.0) -->
+ <method name="GetAll3">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="adapters" type="ao" direction="out"/>
+ <arg name="daemon_version" type="i" direction="out"/>
+ <arg name="mode" type="u" direction="out"/>
+ </method>
+ <!--
+ Mode is a bitmask.
+
+ Polling bits:
+ 0x01 - P2P Initiator
+ 0x02 - Reader/Writer
+
+ Listening bits:
+ 0x04 - P2P Target
+ 0x08 - Card Emulation
+ -->
+ <method name="GetMode">
+ <arg name="mode" type="u" direction="out"/>
+ </method>
+ <signal name="ModeChanged">
+ <arg name="mode" type="u"/>
+ </signal>
+ <method name="RequestMode">
+ <arg name="enable" type="u" direction="in"/>
+ <arg name="disable" type="u" direction="in"/>
+ <arg name="id" type="u" direction="out"/>
+ </method>
+ <method name="ReleaseMode">
+ <arg name="id" type="u" direction="in"/>
+ </method>
+ <method name="RegisterLocalService">
+ <!-- Registers instance of org.sailfishos.nfc.LocalService -->
+ <arg name="path" type="o" direction="in"/>
+ <arg name="name" type="s" direction="in"/>
+ <arg name="sap" type="u" direction="out"/>
+ </method>
+ <method name="UnregisterLocalService">
+ <arg name="path" type="o" direction="in"/>
+ </method>
</interface>
</node>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.IsoDep.xml
^
|
@@ -3,6 +3,20 @@
<node>
<!-- ISO-DEP specific extensions to org.sailfishos.nfc.Tag -->
<interface name="org.sailfishos.nfc.IsoDep">
+ <!--
+ Activation Parameters:
+ NFC-A:
+ "T0" - "y", Format Byte T0
+ "TA" - "y", Interface Bytes TA (optional)
+ "TB" - "y", Interface Bytes TB (optional)
+ "TC" - "y", Interface Bytes TC (optional)
+ "HB" - "ay", Historical Bytes
+
+ NFC-B:
+ "MBLI" - "y", Maximum Buffer Length Index
+ "DID" - "y", Device ID
+ "HLR" - "ay", Higher Layer Response (optional)
+ -->
<method name="GetAll">
<arg name="version" type="i" direction="out"/>
</method>
@@ -24,5 +38,15 @@
<arg name="SW1" type="y" direction="out"/>
<arg name="SW2" type="y" direction="out"/>
</method>
+ <!-- Interface version 2 -->
+ <method name="GetAll2">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="parameters" type="a{sv}" direction="out"/>
+ </method>
+ <method name="GetActivationParameters">
+ <arg name="parameters" type="a{sv}" direction="out"/>
+ </method>
+ <!-- Interface version 3 -->
+ <method name="Reset"/>
</interface>
</node>
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.LocalService.xml
^
|
@@ -0,0 +1,22 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.sailfishos.nfc.LocalService">
+ <method name="Accept">
+ <annotation name="org.gtk.GDBus.C.UnixFD" value="1"/>
+ <arg name="rsap" type="u" direction="in"/>
+ <arg name="fd" type="h" direction="in"/>
+ <arg name="accepted" type="b" direction="out"/>
+ </method>
+ <method name="DatagramReceived">
+ <arg name="rsap" type="u" direction="in"/>
+ <arg name="data" type="ay" direction="in"/>
+ </method>
+ <method name="PeerArrived">
+ <arg name="path" type="o" direction="in"/>
+ </method>
+ <method name="PeerLeft">
+ <arg name="path" type="o" direction="in"/>
+ </method>
+ </interface>
+</node>
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.Peer.xml
^
|
@@ -0,0 +1,51 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.sailfishos.nfc.Peer">
+ <!--
+ Technologies:
+
+ 0 - Unknown
+ 1 - NFC-A
+ 4 - NFC-F
+ -->
+ <method name="GetAll">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="present" type="b" direction="out"/>
+ <arg name="technology" type="u" direction="out"/>
+ <arg name="interfaces" type="as" direction="out"/>
+ <arg name="wks" type="u" direction="out"/>
+ </method>
+ <method name="GetInterfaceVersion">
+ <arg name="version" type="i" direction="out"/>
+ </method>
+ <method name="GetPresent">
+ <arg name="present" type="b" direction="out"/>
+ </method>
+ <method name="GetTechnology">
+ <arg name="technology" type="u" direction="out"/>
+ </method>
+ <method name="GetInterfaces">
+ <arg name="interfaces" type="as" direction="out"/>
+ </method>
+ <method name="GetWellKnownServices">
+ <arg name="wks" type="u" direction="out"/>
+ </method>
+ <method name="Deactivate"/>
+ <method name="ConnectAccessPoint">
+ <annotation name="org.gtk.GDBus.C.UnixFD" value="1"/>
+ <arg name="rsap" type="u" direction="in"/>
+ <arg name="fd" type="h" direction="out"/>
+ </method>
+ <method name="ConnectServiceName">
+ <annotation name="org.gtk.GDBus.C.UnixFD" value="1"/>
+ <arg name="name" type="s" direction="in"/>
+ <arg name="fd" type="h" direction="out"/>
+ </method>
+ <!-- Signals -->
+ <signal name="Removed"/>
+ <signal name="WellKnownServicesChanged">
+ <arg name="wks" type="u"/>
+ </signal>
+ </interface>
+</node>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.Tag.xml
^
|
@@ -18,7 +18,6 @@
4 - Type 3 Tag
8 - Type 4A Tag (ISO-DEP, ISO 14443)
16 - Type 4B Tag,(ISO-DEP, ISO 14443)
- 32 - NFC-DEP Protocol (ISO 18092)
The above codes are bitmasks elsewhere, but here used as enum values.
-->
@@ -59,5 +58,28 @@
<arg name="wait" type="b" direction="in"/>
</method>
<method name="Release"/>
+ <!-- Interface version 3 -->
+ <method name="GetAll3">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="present" type="b" direction="out"/>
+ <arg name="technology" type="u" direction="out"/>
+ <arg name="protocol" type="u" direction="out"/>
+ <arg name="type" type="u" direction="out"/>
+ <arg name="interfaces" type="as" direction="out"/>
+ <arg name="ndef_records" type="ao" direction="out"/>
+ <arg name="parameters" type="a{sv}" direction="out"/>
+ </method>
+ <method name="GetPollParameters">
+ <arg name="parameters" type="a{sv}" direction="out"/>
+ </method>
+ <!-- Interface version 4 -->
+ <method name="Transceive">
+ <arg name="data" type="ay" direction="in">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg name="response" type="ay" direction="out">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ </method>
</interface>
</node>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.daemon.conf
^
|
@@ -3,9 +3,11 @@
<busconfig>
<policy user="root">
<allow own="org.sailfishos.nfc.daemon"/>
+ <allow send_interface="org.sailfishos.nfc.LocalService"/>
</policy>
<policy user="nfc">
<allow own="org.sailfishos.nfc.daemon"/>
+ <allow send_interface="org.sailfishos.nfc.LocalService"/>
</policy>
<policy context="default">
<allow send_destination="org.sailfishos.nfc.daemon"
@@ -15,6 +17,8 @@
<allow send_destination="org.sailfishos.nfc.daemon"
send_interface="org.sailfishos.nfc.Adapter"/>
<allow send_destination="org.sailfishos.nfc.daemon"
+ send_interface="org.sailfishos.nfc.Peer"/>
+ <allow send_destination="org.sailfishos.nfc.daemon"
send_interface="org.sailfishos.nfc.Tag"/>
<allow send_destination="org.sailfishos.nfc.daemon"
send_interface="org.sailfishos.nfc.TagType2"/>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/plugins/settings/settings_plugin.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -34,14 +34,10 @@
#include "settings/org.sailfishos.nfc.Settings.h"
#include <nfc_manager.h>
-#include <nfc_adapter.h>
#include <nfc_plugin_impl.h>
#include <gio/gio.h>
-#include <mce_display.h>
-#include <mce_log.h>
-
#include <dbusaccess_policy.h>
#include <dbusaccess_peer.h>
@@ -63,33 +59,17 @@
SETTINGS_DBUS_CALL_COUNT
};
-enum {
- DISPLAY_VALID,
- DISPLAY_STATE,
- MCE_EVENT_COUNT
-};
-
-enum {
- NFC_ADAPTER_ADDED,
- NFC_EVENT_COUNT
-};
-
typedef NfcPluginClass SettingsPluginClass;
typedef struct settings_plugin {
NfcPlugin parent;
NfcManager* manager;
- MceDisplay* display;
OrgSailfishosNfcSettings* iface;
DAPolicy* policy;
char* storage_dir;
char* storage_file;
guint own_name_id;
gulong dbus_call_id[SETTINGS_DBUS_CALL_COUNT];
- gulong mce_event_id[MCE_EVENT_COUNT];
- gulong nfc_event_id[NFC_EVENT_COUNT];
gboolean nfc_enabled;
- gboolean nfc_always_on;
- NFC_MODE auto_mode;
} SettingsPlugin;
G_DEFINE_TYPE(SettingsPlugin, settings_plugin, NFC_TYPE_PLUGIN)
@@ -142,9 +122,6 @@
static const char settings_default_policy[] =
DA_POLICY_VERSION ";group(privileged)=allow";
-#define mce_display_on(display) \
- ((display) && (display)->valid && (display)->state != MCE_DISPLAY_STATE_OFF)
-
static
GKeyFile*
settings_plugin_load_config(
@@ -226,7 +203,6 @@
{
GKeyFile* config = settings_plugin_load_config(self);
const gboolean enabled = settings_plugin_nfc_enabled(config);
- const gboolean always_on = settings_plugin_nfc_always_on(config);
gboolean save = FALSE;
if (enabled != self->nfc_enabled) {
@@ -235,12 +211,6 @@
self->nfc_enabled);
}
- if (always_on != self->nfc_always_on) {
- save = TRUE;
- g_key_file_set_boolean(config, SETTINGS_GROUP, SETTINGS_KEY_ALWAYS_ON,
- self->nfc_always_on);
- }
-
if (save) {
settings_plugin_save_config(self, config);
}
@@ -286,66 +256,6 @@
}
static
-gboolean
-settings_plugin_adapter_enabled(
- SettingsPlugin* self)
-{
- return self->nfc_enabled &&
- (self->nfc_always_on || mce_display_on(self->display));
-}
-
-static
-void
-settings_plugin_adapter_added(
- NfcManager* manager,
- NfcAdapter* adapter,
- void* plugin)
-{
- SettingsPlugin* self = SETTINGS_PLUGIN(plugin);
- const gboolean enable = settings_plugin_adapter_enabled(self);
-
- if (enable && self->auto_mode != NFC_MODE_NONE) {
- nfc_adapter_request_power(adapter, TRUE);
- nfc_adapter_request_mode(adapter, self->auto_mode);
- }
-}
-
-static
-void
-settings_plugin_update_nfc_state(
- SettingsPlugin* self)
-{
- const gboolean enable = settings_plugin_adapter_enabled(self);
-
- nfc_manager_set_enabled(self->manager, enable);
- if (enable && self->auto_mode != NFC_MODE_NONE) {
- nfc_manager_request_power(self->manager, TRUE);
- nfc_manager_request_mode(self->manager, self->auto_mode);
- }
-}
-
-static
-void
-settings_plugin_display_state_handler(
- MceDisplay* display,
- gpointer plugin)
-{
- settings_plugin_update_nfc_state(SETTINGS_PLUGIN(plugin));
-}
-
-static
-void
-settings_plugin_drop_display(
- SettingsPlugin* self)
-{
- if (self->display) {
- mce_display_remove_all_handlers(self->display, self->mce_event_id);
- mce_display_unref(self->display);
- self->display = NULL;
- }
-}
-
-static
void
settings_plugin_set_nfc_enabled(
SettingsPlugin* self,
@@ -353,24 +263,9 @@
{
if (self->nfc_enabled != enabled) {
self->nfc_enabled = enabled;
- /* We only need to follow display state when NFC is enabled */
- if (enabled) {
- GINFO("NFC enabled");
- if (!self->nfc_always_on) {
- self->display = mce_display_new();
- self->mce_event_id[DISPLAY_VALID] =
- mce_display_add_valid_changed_handler(self->display,
- settings_plugin_display_state_handler, self);
- self->mce_event_id[DISPLAY_STATE] =
- mce_display_add_state_changed_handler(self->display,
- settings_plugin_display_state_handler, self);
- }
- } else {
- GINFO("NFC disabled");
- settings_plugin_drop_display(self);
- }
+ GINFO("NFC %s", enabled ? "enabled" : "disabled");
org_sailfishos_nfc_settings_emit_enabled_changed(self->iface, enabled);
- settings_plugin_update_nfc_state(self);
+ nfc_manager_set_enabled(self->manager, enabled);
settings_plugin_update_config(self);
}
}
@@ -498,10 +393,6 @@
GVERBOSE("Starting");
self->manager = nfc_manager_ref(manager);
- self->nfc_event_id[NFC_ADAPTER_ADDED] =
- nfc_manager_add_adapter_added_handler(manager,
- settings_plugin_adapter_added, self);
-
self->iface = org_sailfishos_nfc_settings_skeleton_new();
self->dbus_call_id[SETTINGS_DBUS_CALL_GET_ALL] =
g_signal_connect(self->iface, "handle-get-all",
@@ -522,9 +413,11 @@
self, NULL);
config = settings_plugin_load_config(self);
- self->nfc_always_on = settings_plugin_nfc_always_on(config);
+ if (settings_plugin_nfc_always_on(config)) {
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/src/Makefile
^
|
@@ -9,7 +9,7 @@
#
PKGS = gio-unix-2.0 gio-2.0 libglibutil
-LIB_PKGS = $(PKGS) libmce-glib libdbusaccess libdbuslogserver-gio
+LIB_PKGS = $(PKGS) libdbusaccess
#
# Default target
@@ -32,6 +32,10 @@
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
+LIBDIR ?= usr/lib
+ABS_LIBDIR := $(shell echo /$(LIBDIR) | sed -r 's|/+|/|g')
+DEFAULT_PLUGIN_DIR := $(ABS_LIBDIR)/nfcd/plugins
+
#
# libnfc-core
#
@@ -63,6 +67,7 @@
DEBUG_DEFS = -DDEBUG
RELEASE_DEFS =
WARNINGS = -Wall -Wstrict-aliasing -Wunused-result
+DEFINES += -DDEFAULT_PLUGIN_DIR='"$(DEFAULT_PLUGIN_DIR)"'
INCLUDES = -I. -I$(NFC_CORE_DIR)/include -I$(NFC_PLUGINS_DIR)
FULL_CFLAGS = -fPIC $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
-MMD -MP $(shell pkg-config --cflags $(PKGS))
@@ -141,21 +146,21 @@
release: $(RELEASE_DEPS) $(RELEASE_EXE)
clean:
- make -C $(NFC_CORE_DIR) clean
- make -C $(NFC_PLUGINS_DIR) clean
+ $(MAKE) -C $(NFC_CORE_DIR) clean
+ $(MAKE) -C $(NFC_PLUGINS_DIR) clean
rm -fr $(BUILD_DIR) $(SRC_DIR)/*~
nfc_core_debug_lib:
- make -C $(NFC_CORE_DIR) debug
+ $(MAKE) -C $(NFC_CORE_DIR) debug
nfc_core_release_lib:
- make -C $(NFC_CORE_DIR) release
+ $(MAKE) -C $(NFC_CORE_DIR) release
nfc_plugins_debug_lib:
- make -C $(NFC_PLUGINS_DIR) debug
+ $(MAKE) -C $(NFC_PLUGINS_DIR) debug
nfc_plugins_release_lib:
- make -C $(NFC_PLUGINS_DIR) release
+ $(MAKE) -C $(NFC_PLUGINS_DIR) release
$(DEBUG_BUILD_DIR):
mkdir -p $@
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/src/main.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -33,7 +33,6 @@
#include "internal/nfc_manager_i.h"
#include "dbus_handlers/plugin.h"
-#include "dbus_log/plugin.h"
#include "dbus_neard/plugin.h"
#include "dbus_service/plugin.h"
#include "settings/plugin.h"
@@ -47,7 +46,6 @@
#include <locale.h>
static const NfcPluginDesc* const nfcd_builtin_plugins[] = {
- &NFC_PLUGIN_DESC(dbus_log),
&NFC_PLUGIN_DESC(dbus_handlers),
&NFC_PLUGIN_DESC(dbus_neard),
&NFC_PLUGIN_DESC(dbus_service),
@@ -65,7 +63,9 @@
gboolean dont_unload;
} NfcdOpt;
+#ifndef DEFAULT_PLUGIN_DIR
#define DEFAULT_PLUGIN_DIR "/usr/lib/nfcd/plugins"
+#endif
#define RET_OK (0)
#define RET_CMDLINE (1)
@@ -335,6 +335,7 @@
NfcdOpt opt;
gutil_log_default.name = "nfcd";
+ gutil_log_timestamp = TRUE;
setlocale(LC_ALL, "");
nfcd_opt_init(&opt);
if (nfcd_opt_parse(&opt, argc, argv)) {
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/src/nfcd.map
^
|
@@ -3,8 +3,11 @@
nfc_adapter_*;
nfc_core_*;
nfc_crc_*;
+ nfc_initiator_*;
+ nfc_llc_*;
nfc_manager_*;
nfc_ndef_rec_*;
+ nfc_peer_*;
nfc_plugin_*;
nfc_tag_*;
nfc_target_*;
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/test/Makefile
^
|
@@ -0,0 +1,6 @@
+# -*- Mode: makefile-gmake -*-
+
+all:
+%:
+ @$(MAKE) -C nfcdep-client $*
+ @$(MAKE) -C nfcdep-service $*
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/test/README
^
|
@@ -0,0 +1 @@
+Tests that can be run interactively on the device.
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/test/nfcdep-client/Makefile
^
|
@@ -0,0 +1,166 @@
+# -*- Mode: makefile-gmake -*-
+
+.PHONY: all debug release clean install
+
+#
+# Required packages
+#
+
+PKGS = gio-unix-2.0 gio-2.0 libglibutil
+LIB_PKGS = $(PKGS)
+
+#
+# Default target
+#
+
+all: debug release
+
+#
+# Sources
+#
+
+SRC = nfcdep-client.c
+
+GEN_SRC = \
+ org.sailfishos.nfc.Adapter.c \
+ org.sailfishos.nfc.Daemon.c \
+ org.sailfishos.nfc.Peer.c
+
+ALL_SRC = $(GEN_SRC) $(SRC)
+
+#
+# Directories
+#
+
+SRC_DIR = .
+BUILD_DIR = build
+SPEC_DIR = ../../plugins/dbus_service
+GEN_DIR = $(BUILD_DIR)
+DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
+RELEASE_BUILD_DIR = $(BUILD_DIR)/release
+
+#
+# Tools and flags
+#
+
+CC = $(CROSS_COMPILE)gcc
+LD = $(CC)
+DEBUG_FLAGS = -g
+RELEASE_FLAGS =
+DEBUG_DEFS = -DDEBUG
+RELEASE_DEFS =
+WARNINGS = -Wall -Wstrict-aliasing -Wunused-result
+INCLUDES = -I. -I../../core/include -I$(GEN_DIR)
+FULL_CFLAGS = -fPIC $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
+ -MMD -MP $(shell pkg-config --cflags $(PKGS))
+FULL_LDFLAGS = $(LDFLAGS)
+
+ifndef KEEP_SYMBOLS
+KEEP_SYMBOLS = 0
+endif
+
+ifneq ($(KEEP_SYMBOLS),0)
+RELEASE_FLAGS += -g
+SUBMAKE_OPTS += KEEP_SYMBOLS=1
+endif
+
+DEBUG_CFLAGS = $(DEBUG_FLAGS) -DDEBUG $(FULL_CFLAGS)
+RELEASE_CFLAGS = $(RELEASE_FLAGS) -O2 $(FULL_CFLAGS)
+DEBUG_LDFLAGS = $(DEBUG_FLAGS) $(FULL_LDFLAGS)
+RELEASE_LDFLAGS = $(RELEASE_FLAGS) $(FULL_LDFLAGS)
+
+LIBS = $(shell pkg-config --libs $(LIB_PKGS)) -ldl
+DEBUG_LIBS = $(LIBS)
+RELEASE_LIBS = $(LIBS)
+
+#
+# Files
+#
+
+DEBUG_OBJS = $(ALL_SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
+RELEASE_OBJS = $(ALL_SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
+
+#
+# Dependencies
+#
+
+DEPS = \
+ $(DEBUG_OBJS:%.o=%.d) \
+ $(RELEASE_OBJS:%.o=%.d)
+ifneq ($(MAKECMDGOALS),clean)
+ifneq ($(strip $(DEPS)),)
+-include $(DEPS)
+endif
+endif
+
+$(GEN_SRC:%=$(GEN_DIR)/%): | $(GEN_DIR)
+$(SRC): | $(GEN_SRC:%=$(GEN_DIR)/%)
+$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
+$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
+
+#
+# Rules
+#
+
+EXE = nfcdep-client
+DEBUG_EXE = $(DEBUG_BUILD_DIR)/$(EXE)
+RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
+
+debug: $(DEBUG_EXE)
+
+release: $(RELEASE_EXE)
+
+clean:
+ rm -fr $(BUILD_DIR) $(SRC_DIR)/*~
+
+nfc_core_debug_lib:
+ make -C $(NFC_CORE_DIR) debug
+
+nfc_core_release_lib:
+ make -C $(NFC_CORE_DIR) release
+
+$(GEN_DIR)/%.c: $(SPEC_DIR)/%.xml
+ gdbus-codegen --generate-c-code $(@:%.c=%) $<
+
+$(GEN_DIR):
+ mkdir -p $@
+
+$(DEBUG_BUILD_DIR):
+ mkdir -p $@
+
+$(RELEASE_BUILD_DIR):
+ mkdir -p $@
+
+$(DEBUG_BUILD_DIR)/%.o: $(GEN_DIR)/%.c
+ $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/%.o: $(GEN_DIR)/%.c
+ $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_BUILD_DIR)/%.o: $(SRC_DIR)/%.c
+ $(CC) -c $(WARN) $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/%.o: $(SRC_DIR)/%.c
+ $(CC) -c $(WARN) $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_EXE): $(DEBUG_OBJS)
+ $(LD) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) $(DEBUG_LIBS) -o $@
+
+$(RELEASE_EXE): $(RELEASE_OBJS)
+ $(LD) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) $(RELEASE_LIBS) -o $@
+ifeq ($(KEEP_SYMBOLS),0)
+ strip $@
+endif
+
+#
+# Install
+#
+
+INSTALL = install
+INSTALL_BIN_DIR = $(DESTDIR)/usr/bin
+
+install: $(INSTALL_BIN_DIR)
+ $(INSTALL) -m 755 $(RELEASE_EXE) $(INSTALL_BIN_DIR)
+
+$(INSTALL_BIN_DIR):
+ $(INSTALL) -d $@
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/test/nfcdep-client/nfcdep-client.c
^
|
@@ -0,0 +1,511 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_types.h"
+#include "org.sailfishos.nfc.Daemon.h"
+#include "org.sailfishos.nfc.Adapter.h"
+#include "org.sailfishos.nfc.Peer.h"
+
+#include <gutil_misc.h>
+#include <gutil_strv.h>
+#include <gutil_log.h>
+
+#include <glib-unix.h>
+#include <gio/gunixfdlist.h>
+
+#include <sys/socket.h>
+
+#define NFC_BUS G_BUS_TYPE_SYSTEM
+#define NFC_SERVICE "org.sailfishos.nfc.daemon"
+#define NFC_DAEMON_PATH "/"
+
+#define RET_OK (0)
+#define RET_CMDLINE (1)
+#define RET_ERR (2)
+
+typedef struct app_data {
+ char** peers;
+ GMainLoop* loop;
+ guint sap;
+ const char* sn;
+ const char* input_name;
+ int input_fd;
+ gboolean reading_file;
+ gboolean stopped;
+ GIOChannel* llc_io;
+ GIOChannel* input_io;
+ GIOChannel* stdout_io;
+ guint llc_read_id;
+ guint local_read_id;
+ gulong written;
+} AppData;
+
+static
+gboolean
+nfcdep_signal(
+ gpointer user_data)
+{
+ AppData* app = user_data;
+
+ if (!app->stopped) {
+ GDEBUG("Signal caught, shutting down...");
+ g_main_loop_quit(app->loop);
+ }
+ return G_SOURCE_CONTINUE;
+}
+
+static
+GIOChannel*
+nfcdep_channel_new(
+ int fd)
+{
+ GIOChannel* io = g_io_channel_unix_new(fd);
+
+ if (io) {
+ g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_channel_set_encoding(io, NULL, NULL);
+ g_io_channel_set_buffered(io, FALSE);
+ }
+ return io;
+}
+
+static
+gboolean
+nfcdep_write(
+ AppData* app,
+ const char* buf,
+ gsize size,
+ GIOChannel* out)
+{
+ gsize written = 0, total = 0;
+
+ while (total < size) {
+ GError* error = NULL;
+ GIOStatus status = g_io_channel_write_chars(out, buf + total,
+ size - total, &written, &error);
+
+ if (status == G_IO_STATUS_AGAIN) {
+ /* Need to block */
+ g_io_channel_set_flags(out, 0, NULL);
+ status = g_io_channel_write_chars(out, buf + total,
+ size - total, &written, &error);
+ g_io_channel_set_flags(out, G_IO_FLAG_NONBLOCK, NULL);
+ }
+
+ if (status == G_IO_STATUS_NORMAL) {
+ GVERBOSE("Written %u bytes", (guint) written);
+ app->written += written;
+ total += written;
+ written = 0;
+ } else {
+ if (error) {
+ GDEBUG("Write failed: %s", GERRMSG(error));
+ g_error_free(error);
+ }
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+static
+gboolean
+nfcdep_read(
+ AppData* app,
+ const char* what,
+ GIOChannel* in,
+ GIOChannel* out)
+{
+ char buf[512];
+ gsize bytes_read = 0;
+ GError* error = NULL;
+ GIOStatus status = g_io_channel_read_chars(in, buf, sizeof(buf),
+ &bytes_read, &error);
+
+ if (error) {
+ GDEBUG("%s read failed: %s", what, GERRMSG(error));
+ g_error_free(error);
+ return FALSE;
+ } else if (status == G_IO_STATUS_EOF) {
+ GDEBUG("%s hung up", what);
+ return FALSE;
+ } else {
+ GVERBOSE("%s produced %u bytes", what, (guint)bytes_read);
+ return nfcdep_write(app, buf, bytes_read, out);
+ }
+}
+
+static
+gboolean
+nfcdep_llc_read_cb(
+ GIOChannel* source,
+ GIOCondition condition,
+ gpointer user_data)
+{
+ AppData* app = user_data;
+
+ if (nfcdep_read(app, "Peer", app->llc_io, app->stdout_io)) {
+ return G_SOURCE_CONTINUE;
+ } else {
+ app->llc_read_id = 0;
+ g_main_loop_quit(app->loop);
+ return G_SOURCE_REMOVE;
+ }
+}
+
+static
+gboolean
+nfcdep_local_read_cb(
+ GIOChannel* source,
+ GIOCondition condition,
+ gpointer user_data)
+{
+ AppData* app = user_data;
+
+ if (nfcdep_read(app, app->input_name, app->input_io, app->llc_io)) {
+ return G_SOURCE_CONTINUE;
+ } else {
+ app->local_read_id = 0;
+
+ /*
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/test/nfcdep-service/Makefile
^
|
@@ -0,0 +1,165 @@
+# -*- Mode: makefile-gmake -*-
+
+.PHONY: all debug release clean install
+
+#
+# Required packages
+#
+
+PKGS = gio-unix-2.0 gio-2.0 libglibutil
+LIB_PKGS = $(PKGS)
+
+#
+# Default target
+#
+
+all: debug release
+
+#
+# Sources
+#
+
+SRC = nfcdep-service.c
+
+GEN_SRC = \
+ org.sailfishos.nfc.Daemon.c \
+ org.sailfishos.nfc.LocalService.c
+
+ALL_SRC = $(GEN_SRC) $(SRC)
+
+#
+# Directories
+#
+
+SRC_DIR = .
+BUILD_DIR = build
+SPEC_DIR = ../../plugins/dbus_service
+GEN_DIR = $(BUILD_DIR)
+DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
+RELEASE_BUILD_DIR = $(BUILD_DIR)/release
+
+#
+# Tools and flags
+#
+
+CC = $(CROSS_COMPILE)gcc
+LD = $(CC)
+DEBUG_FLAGS = -g
+RELEASE_FLAGS =
+DEBUG_DEFS = -DDEBUG
+RELEASE_DEFS =
+WARNINGS = -Wall -Wstrict-aliasing -Wunused-result
+INCLUDES = -I. -I$(GEN_DIR)
+FULL_CFLAGS = -fPIC $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
+ -MMD -MP $(shell pkg-config --cflags $(PKGS))
+FULL_LDFLAGS = $(LDFLAGS)
+
+ifndef KEEP_SYMBOLS
+KEEP_SYMBOLS = 0
+endif
+
+ifneq ($(KEEP_SYMBOLS),0)
+RELEASE_FLAGS += -g
+SUBMAKE_OPTS += KEEP_SYMBOLS=1
+endif
+
+DEBUG_CFLAGS = $(DEBUG_FLAGS) -DDEBUG $(FULL_CFLAGS)
+RELEASE_CFLAGS = $(RELEASE_FLAGS) -O2 $(FULL_CFLAGS)
+DEBUG_LDFLAGS = $(DEBUG_FLAGS) $(FULL_LDFLAGS)
+RELEASE_LDFLAGS = $(RELEASE_FLAGS) $(FULL_LDFLAGS)
+
+LIBS = $(shell pkg-config --libs $(LIB_PKGS)) -ldl
+DEBUG_LIBS = $(LIBS)
+RELEASE_LIBS = $(LIBS)
+
+#
+# Files
+#
+
+DEBUG_OBJS = $(ALL_SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
+RELEASE_OBJS = $(ALL_SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
+
+#
+# Dependencies
+#
+
+DEPS = \
+ $(DEBUG_OBJS:%.o=%.d) \
+ $(RELEASE_OBJS:%.o=%.d)
+ifneq ($(MAKECMDGOALS),clean)
+ifneq ($(strip $(DEPS)),)
+-include $(DEPS)
+endif
+endif
+
+$(GEN_SRC:%=$(GEN_DIR)/%): | $(GEN_DIR)
+$(SRC): | $(GEN_SRC:%=$(GEN_DIR)/%)
+$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
+$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
+
+#
+# Rules
+#
+
+EXE = nfcdep-service
+DEBUG_EXE = $(DEBUG_BUILD_DIR)/$(EXE)
+RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
+
+debug: $(DEBUG_EXE)
+
+release: $(RELEASE_EXE)
+
+clean:
+ rm -fr $(BUILD_DIR) $(SRC_DIR)/*~
+
+nfc_core_debug_lib:
+ make -C $(NFC_CORE_DIR) debug
+
+nfc_core_release_lib:
+ make -C $(NFC_CORE_DIR) release
+
+$(GEN_DIR)/%.c: $(SPEC_DIR)/%.xml
+ gdbus-codegen --generate-c-code $(@:%.c=%) $<
+
+$(GEN_DIR):
+ mkdir -p $@
+
+$(DEBUG_BUILD_DIR):
+ mkdir -p $@
+
+$(RELEASE_BUILD_DIR):
+ mkdir -p $@
+
+$(DEBUG_BUILD_DIR)/%.o: $(GEN_DIR)/%.c
+ $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/%.o: $(GEN_DIR)/%.c
+ $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_BUILD_DIR)/%.o: $(SRC_DIR)/%.c
+ $(CC) -c $(WARN) $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/%.o: $(SRC_DIR)/%.c
+ $(CC) -c $(WARN) $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_EXE): $(DEBUG_OBJS)
+ $(LD) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) $(DEBUG_LIBS) -o $@
+
+$(RELEASE_EXE): $(RELEASE_OBJS)
+ $(LD) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) $(RELEASE_LIBS) -o $@
+ifeq ($(KEEP_SYMBOLS),0)
+ strip $@
+endif
+
+#
+# Install
+#
+
+INSTALL = install
+INSTALL_BIN_DIR = $(DESTDIR)/usr/bin
+
+install: $(INSTALL_BIN_DIR)
+ $(INSTALL) -m 755 $(RELEASE_EXE) $(INSTALL_BIN_DIR)
+
+$(INSTALL_BIN_DIR):
+ $(INSTALL) -d $@
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/test/nfcdep-service/nfcdep-service.c
^
|
@@ -0,0 +1,444 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "org.sailfishos.nfc.Daemon.h"
+#include "org.sailfishos.nfc.LocalService.h"
+
+#include <gutil_misc.h>
+#include <gutil_strv.h>
+#include <gutil_log.h>
+
+#include <glib-unix.h>
+#include <gio/gunixfdlist.h>
+
+#include <sys/socket.h>
+
+#define NFC_BUS G_BUS_TYPE_SYSTEM
+#define NFC_SERVICE "org.sailfishos.nfc.daemon"
+#define NFC_DAEMON_PATH "/"
+
+#define RET_OK (0)
+#define RET_CMDLINE (1)
+#define RET_ERR (2)
+
+typedef struct app_data {
+ gboolean multiple;
+ GMainLoop* loop;
+ const char* path;
+ const char* sn;
+ gboolean stopped;
+ int output_fd;
+ GIOChannel* llc_io;
+ GIOChannel* stdin_io;
+ GIOChannel* output_io;
+ guint llc_read_id;
+ guint stdin_read_id;
+ gint64 start_time;
+ gint64 bytes_received;
+} AppData;
+
+enum service_calls {
+ CALL_ACCEPT,
+ SIGNAL_PEER_ARRIVED,
+ SIGNAL_PEER_LEFT,
+ CALL_COUNT
+};
+
+static
+gboolean
+nfcdep_signal(
+ gpointer user_data)
+{
+ AppData* app = user_data;
+
+ if (!app->stopped) {
+ GDEBUG("Signal caught, shutting down...");
+ g_main_loop_quit(app->loop);
+ }
+ return G_SOURCE_CONTINUE;
+}
+
+static
+GIOChannel*
+nfcdep_channel_new(
+ int fd)
+{
+ GIOChannel* io = g_io_channel_unix_new(fd);
+
+ if (io) {
+ g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_channel_set_encoding(io, NULL, NULL);
+ g_io_channel_set_buffered(io, FALSE);
+ }
+ return io;
+}
+
+static
+gboolean
+nfcdep_read(
+ AppData* app,
+ const char* what,
+ GIOChannel* in,
+ GIOChannel* out)
+{
+ char buf[512];
+ gsize bytes_read = 0;
+ GError* error = NULL;
+ GIOStatus status = g_io_channel_read_chars(in, buf, sizeof(buf),
+ &bytes_read, &error);
+
+ if (error) {
+ GDEBUG("%s read failed: %s", what, GERRMSG(error));
+ g_error_free(error);
+ return FALSE;
+ } else if (status == G_IO_STATUS_EOF) {
+ GDEBUG("%s hung up", what);
+ return FALSE;
+ } else {
+ GVERBOSE("%s produced %u bytes", what, (guint)bytes_read);
+ app->bytes_received += bytes_read;
+ if (bytes_read) {
+ gsize written = 0, total = 0;
+
+ while (total < bytes_read && g_io_channel_write_chars(out,
+ buf + total, bytes_read - total, &written, &error) ==
+ G_IO_STATUS_NORMAL) {
+ GVERBOSE("Written %u bytes", (guint) written);
+ total += written;
+ written = 0;
+ }
+ if (error) {
+ GDEBUG("Write failed: %s", GERRMSG(error));
+ g_error_free(error);
+ return FALSE;
+ }
+ }
+ return TRUE;
+ }
+}
+
+static
+void
+nfcdep_close_connection(
+ AppData* app)
+{
+ if (app->llc_io) {
+ gint64 end = g_get_real_time();
+
+ GDEBUG("%ld bytes received", (long) app->bytes_received);
+ if (end > app->start_time) {
+ GDEBUG("%ld bytes/sec", (long)(app->bytes_received *
+ G_TIME_SPAN_SECOND / (end - app->start_time)));
+ }
+ if (app->llc_read_id) {
+ g_source_remove(app->llc_read_id);
+ app->llc_read_id = 0;
+ }
+ g_io_channel_unref(app->llc_io);
+ app->llc_io = NULL;
+ }
+ if (app->stdin_io) {
+ if (app->stdin_read_id) {
+ g_source_remove(app->stdin_read_id);
+ app->stdin_read_id = 0;
+ }
+ g_io_channel_unref(app->stdin_io);
+ app->stdin_io = NULL;
+ }
+}
+
+static
+gboolean
+nfcdep_llc_read_cb(
+ GIOChannel* source,
+ GIOCondition condition,
+ gpointer user_data)
+{
+ AppData* app = user_data;
+
+ if (nfcdep_read(app, "Peer", app->llc_io, app->output_io)) {
+ return G_SOURCE_CONTINUE;
+ } else if (app->multiple) {
+ app->llc_read_id = 0;
+ nfcdep_close_connection(app);
+ return G_SOURCE_REMOVE;
+ } else {
+ g_main_loop_quit(app->loop);
+ return G_SOURCE_CONTINUE;
+ }
+}
+
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/tools/iso-dep/Makefile
^
|
@@ -115,10 +115,10 @@
rm -fr $(BUILD_DIR) $(SRC_DIR)/*~
nfc_core_debug_lib:
- make -C $(NFC_CORE_DIR) debug
+ $(MAKE) -C $(NFC_CORE_DIR) debug
nfc_core_release_lib:
- make -C $(NFC_CORE_DIR) release
+ $(MAKE) -C $(NFC_CORE_DIR) release
$(GEN_DIR)/%.c: $(SPEC_DIR)/%.xml
gdbus-codegen --generate-c-code $(@:%.c=%) $<
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/tools/ndef-read/Makefile
^
|
@@ -138,10 +138,10 @@
rm -fr $(BUILD_DIR) $(SRC_DIR)/*~
nfc_core_debug_lib:
- make -C $(NFC_CORE_DIR) debug
+ $(MAKE) -C $(NFC_CORE_DIR) debug
nfc_core_release_lib:
- make -C $(NFC_CORE_DIR) release
+ $(MAKE) -C $(NFC_CORE_DIR) release
$(GEN_DIR)/%.c: $(SPEC_DIR)/%.xml
gdbus-codegen --generate-c-code $(@:%.c=%) $<
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/tools/ndef-write/Makefile
^
|
@@ -139,10 +139,10 @@
rm -fr $(BUILD_DIR) $(SRC_DIR)/*~
nfc_core_debug_lib:
- make -C $(NFC_CORE_DIR) debug
+ $(MAKE) -C $(NFC_CORE_DIR) debug
nfc_core_release_lib:
- make -C $(NFC_CORE_DIR) release
+ $(MAKE) -C $(NFC_CORE_DIR) release
$(GEN_DIR)/%.c: $(SPEC_DIR)/%.xml
gdbus-codegen --generate-c-code $(@:%.c=%) $<
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/Makefile
^
|
@@ -3,14 +3,22 @@
all:
%:
@$(MAKE) -C core_adapter $*
+ @$(MAKE) -C core_initiator $*
@$(MAKE) -C core_crc $*
+ @$(MAKE) -C core_llc $*
+ @$(MAKE) -C core_llc_param $*
@$(MAKE) -C core_manager $*
@$(MAKE) -C core_ndef_rec $*
@$(MAKE) -C core_ndef_rec_sp $*
@$(MAKE) -C core_ndef_rec_t $*
@$(MAKE) -C core_ndef_rec_u $*
+ @$(MAKE) -C core_peer $*
+ @$(MAKE) -C core_peer_service $*
+ @$(MAKE) -C core_peer_services $*
+ @$(MAKE) -C core_peer_socket $*
@$(MAKE) -C core_plugin $*
@$(MAKE) -C core_plugins $*
+ @$(MAKE) -C core_snep $*
@$(MAKE) -C core_tag $*
@$(MAKE) -C core_tag_t2 $*
@$(MAKE) -C core_tag_t4 $*
@@ -25,8 +33,10 @@
@$(MAKE) -C plugins_dbus_handlers_type_text $*
@$(MAKE) -C plugins_dbus_handlers_type_uri $*
@$(MAKE) -C plugins_dbus_service_adapter $*
+ @$(MAKE) -C plugins_dbus_service_peer $*
@$(MAKE) -C plugins_dbus_service_plugin $*
@$(MAKE) -C plugins_dbus_service_tag $*
+ @$(MAKE) -C plugins_dbus_service_util $*
clean: unitclean
rm -f *~
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/common/Makefile
^
|
@@ -37,7 +37,7 @@
# Required packages
#
-PKGS += libglibutil glib-2.0 gobject-2.0
+PKGS += libglibutil glib-2.0 gobject-2.0 gio-2.0 gio-unix-2.0
ifneq ($(GEN_SRC),)
# Additional requirements for generated stubs
@@ -140,11 +140,11 @@
RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
COVERAGE_EXE = $(COVERAGE_BUILD_DIR)/$(EXE)
-debug: $(DEBUG_EXE)
+debug: debug_core_lib $(DEBUG_EXE)
-release: $(RELEASE_EXE)
+release: release_core_lib $(RELEASE_EXE)
-coverage: $(COVERAGE_EXE)
+coverage: coverage_core_lib $(COVERAGE_EXE)
unitclean:
rm -f *~
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/common/test_common.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -33,13 +33,27 @@
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
-#include <nfc_types.h>
+#include <gutil_types.h>
+
+/*
+ * For whatever reason, g_assert() is a special case and can be disabled
+ * with G_DISABLE_ASSERT macro, unlike all other g_assert_* macros. Make
+ * sure that it actually works.
+ */
+#ifdef G_DISABLE_ASSERT
+# error "g_assert is required by unit tests"
+#endif
#define TEST_FLAG_DEBUG (0x01)
typedef struct test_opt {
int flags;
} TestOpt;
+typedef struct test_tx {
+ GUtilData in;
+ GUtilData out;
+} TestTx;
+
/* Should be invoked after g_test_init */
void
test_init(
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/common/test_initiator.c
^
|
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_initiator.h"
+#include "nfc_initiator_impl.h"
+
+#include <gutil_log.h>
+
+typedef NfcInitiatorClass TestInitiatorClass;
+typedef struct test_initiator {
+ NfcInitiator initiator;
+ guint transmit_id;
+ guint response_id;
+ GSList* list;
+ gboolean stay_alive;
+} TestInitiator;
+
+#define THIS_TYPE (test_initiator_get_type())
+#define THIS(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, TestInitiator))
+#define PARENT_CLASS test_initiator_parent_class
+
+G_DEFINE_TYPE(TestInitiator, test_initiator, NFC_TYPE_INITIATOR)
+
+static
+GUtilData*
+test_initiator_next_data(
+ TestInitiator* self)
+{
+ if (self->list) {
+ GUtilData* expected = self->list->data;
+
+ self->list = g_slist_delete_link(self->list, self->list);
+ return expected;
+ }
+ return NULL;
+}
+
+static
+gboolean
+test_initiator_transmit(
+ gpointer user_data)
+{
+ TestInitiator* self = THIS(user_data);
+ NfcInitiator* initiator = &self->initiator;
+ GUtilData* data = test_initiator_next_data(self);
+
+ g_assert(self->transmit_id);
+ self->transmit_id = 0;
+ if (data) {
+ nfc_initiator_transmit(initiator, data->bytes, data->size);
+ g_free(data);
+ } else if (!self->stay_alive) {
+ nfc_initiator_gone(initiator);
+ }
+ return G_SOURCE_REMOVE;
+}
+
+static
+gboolean
+test_initiator_response_done(
+ gpointer user_data)
+{
+ TestInitiator* self = THIS(user_data);
+
+ g_assert(!self->transmit_id);
+ g_assert(self->response_id);
+ self->response_id = 0;
+ self->transmit_id = g_idle_add(test_initiator_transmit, self);
+ nfc_initiator_response_sent(&self->initiator, NFC_TRANSMIT_STATUS_OK);
+ return G_SOURCE_REMOVE;
+}
+
+static
+gboolean
+test_initiator_respond(
+ NfcInitiator* initiator,
+ const void* data,
+ guint len)
+{
+ TestInitiator* self = THIS(initiator);
+ GUtilData* expected = test_initiator_next_data(self);
+
+ if (expected) {
+ g_assert_cmpuint(expected->size, ==, len);
+ g_assert(!memcmp(data, expected->bytes, len));
+ g_free(expected);
+ self->response_id = g_idle_add(test_initiator_response_done, self);
+ return TRUE;
+ } else {
+ GDEBUG("Simulating response failure");
+ return FALSE;
+ }
+}
+
+static
+void
+test_initiator_finalize(
+ GObject* object)
+{
+ TestInitiator* self = THIS(object);
+
+ if (self->transmit_id) {
+ g_source_remove(self->transmit_id);
+ }
+ if (self->response_id) {
+ g_source_remove(self->response_id);
+ }
+ g_slist_free_full(self->list, g_free);
+ G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
+}
+
+static
+void
+test_initiator_init(
+ TestInitiator* self)
+{
+}
+
+static
+void
+test_initiator_class_init(
+ NfcInitiatorClass* klass)
+{
+ klass->respond = test_initiator_respond;
+ klass->deactivate = nfc_initiator_gone;
+ G_OBJECT_CLASS(klass)->finalize = test_initiator_finalize;
+}
+
+NfcInitiator*
+test_initiator_new(
+ void)
+{
+ return test_initiator_new_with_tx(NULL, 0);
+}
+
+NfcInitiator*
+test_initiator_new_with_tx(
+ const TestTx* tx_list,
+ gsize tx_count)
+{
+ return test_initiator_new_with_tx2(tx_list, tx_count, FALSE);
+}
+
+NfcInitiator*
+test_initiator_new_with_tx2(
+ const TestTx* tx_list,
+ gsize tx_count,
+ gboolean stay_alive)
+{
+ gsize i;
+ TestInitiator* self = g_object_new(THIS_TYPE, NULL);
+
+ self->stay_alive = stay_alive;
+ for (i = 0; i < tx_count; i++) {
+ const TestTx* tx = tx_list + i;
+ const GUtilData* in = &tx->in;
+ const GUtilData* out = &tx->out;
+
+ if (in->bytes) {
+ self->list = g_slist_append(self->list, test_clone_data(in));
+ if (out->bytes) {
+ self->list = g_slist_append(self->list, test_clone_data(out));
+ }
+ }
+ }
+ if (tx_count) {
+ self->transmit_id = g_idle_add(test_initiator_transmit, self);
+ }
+ return NFC_INITIATOR(self);
+}
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/common/test_initiator.h
^
|
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TEST_INITIATOR_H
+#define TEST_INITIATOR_H
+
+#include "nfc_types_p.h"
+#include "test_common.h"
+
+NfcInitiator*
+test_initiator_new(
+ void);
+
+NfcInitiator*
+test_initiator_new_with_tx(
+ const TestTx* tx_list,
+ gsize tx_count);
+
+NfcInitiator*
+test_initiator_new_with_tx2(
+ const TestTx* tx_list,
+ gsize tx_count,
+ gboolean stay_alive);
+
+#endif /* TEST_INITIATOR_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/common/test_service.c
^
|
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_service.h"
+
+#include "nfc_peer_service_impl.h"
+
+typedef NfcPeerServiceClass TestServiceClass;
+
+G_DEFINE_TYPE(TestService, test_service, NFC_TYPE_PEER_SERVICE)
+
+static
+void
+test_service_peer_arrived(
+ NfcPeerService* service,
+ NfcPeer* peer)
+{
+ TEST_SERVICE(service)->peer_arrived++;
+ NFC_PEER_SERVICE_CLASS(test_service_parent_class)->
+ peer_arrived(service, peer);
+}
+
+static
+void
+test_service_peer_left(
+ NfcPeerService* service,
+ NfcPeer* peer)
+{
+ TEST_SERVICE(service)->peer_left++;
+ NFC_PEER_SERVICE_CLASS(test_service_parent_class)->
+ peer_left(service, peer);
+}
+
+static
+void
+test_service_init(
+ TestService* self)
+{
+}
+
+static
+void
+test_service_class_init(
+ TestServiceClass* klass)
+{
+ klass->peer_arrived = test_service_peer_arrived;
+ klass->peer_left = test_service_peer_left;
+}
+
+TestService*
+test_service_new(
+ const char* name)
+{
+ TestService* test = g_object_new(TEST_TYPE_SERVICE, NULL);
+
+ nfc_peer_service_init_base(&test->service, name);
+ return test;
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/common/test_service.h
^
|
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TEST_SERVICE_H
+#define TEST_SERVICE_H
+
+#include <nfc_types_p.h>
+#include <nfc_peer_service_impl.h>
+
+typedef struct test_service {
+ NfcPeerService service;
+ int peer_arrived;
+ int peer_left;
+} TestService;
+
+GType test_service_get_type(void);
+#define TEST_TYPE_SERVICE (test_service_get_type())
+#define TEST_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_SERVICE, TestService))
+
+TestService*
+test_service_new(
+ const char* name);
+
+#endif /* TEST_SERVICE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/common/test_target.c
^
|
@@ -30,30 +30,94 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "test_common.h"
#include "test_target.h"
-#include "nfc_target_impl.h"
-typedef NfcTargetClass TestTargetClass;
-typedef NfcTarget TestTarget;
+#include <gutil_log.h>
+#define THIS_TYPE TEST_TYPE_TARGET
+#define THIS(obj) TEST_TARGET(obj)
+#define PARENT_CLASS test_target_parent_class
G_DEFINE_TYPE(TestTarget, test_target, NFC_TYPE_TARGET)
-#define TEST_TYPE_TARGET (test_target_get_type())
-NfcTarget*
-test_target_new(
- void)
+static
+GUtilData*
+test_target_next_data(
+ TestTarget* self)
{
- return g_object_new(TEST_TYPE_TARGET, NULL);
+ if (self->cmd_resp->len) {
+ GUtilData* data = self->cmd_resp->pdata[0];
+
+ self->cmd_resp->pdata[0] = NULL;
+ g_ptr_array_remove_index(self->cmd_resp, 0);
+ return data;
+ }
+ return NULL;
}
-NfcTarget*
-test_target_new_tech(
- NFC_TECHNOLOGY tech)
+static
+gboolean
+test_target_transmit_done(
+ gpointer user_data)
{
- NfcTarget* tag = test_target_new();
+ TestTarget* self = TEST_TARGET(user_data);
+ NfcTarget* target = &self->target;
- tag->technology = tech;
- return tag;
+ g_assert(self->transmit_id);
+ self->transmit_id = 0;
+ if (self->cmd_resp->len) {
+ GUtilData* data = test_target_next_data(self);
+
+ if (data) {
+ nfc_target_transmit_done(target, NFC_TRANSMIT_STATUS_OK,
+ data->bytes, data->size);
+ g_free(data);
+ } else {
+ nfc_target_transmit_done(target, NFC_TRANSMIT_STATUS_ERROR,
+ NULL, 0);
+ }
+ } else {
+ nfc_target_transmit_done(target, NFC_TRANSMIT_STATUS_ERROR, NULL, 0);
+ }
+ return G_SOURCE_REMOVE;
+}
+
+static
+gboolean
+test_target_transmit(
+ NfcTarget* target,
+ const void* data,
+ guint len)
+{
+ TestTarget* self = TEST_TARGET(target);
+ GUtilData* expected = test_target_next_data(self);
+
+ if (self->fail_transmit < 0 ||
+ (self->fail_transmit > 0 && --self->fail_transmit == 0)) {
+ GDEBUG("Simulating transmit failure");
+ g_free(expected);
+ return FALSE;
+ } else {
+ if (expected) {
+ g_assert_cmpuint(expected->size, ==, len);
+ g_assert(!memcmp(data, expected->bytes, len));
+ g_free(expected);
+ }
+ self->transmit_id = g_idle_add(test_target_transmit_done, self);
+ return TRUE;
+ }
+}
+
+static
+void
+test_target_cancel_transmit(
+ NfcTarget* target)
+{
+ TestTarget* self = TEST_TARGET(target);
+
+ g_assert(self->transmit_id);
+ g_source_remove(self->transmit_id);
+ self->transmit_id = 0;
}
static
@@ -63,12 +127,28 @@
{
nfc_target_gone(target);
}
-
+
static
void
test_target_init(
TestTarget* self)
{
+ self->fail_transmit = TEST_TARGET_FAIL_ALL;
+ self->cmd_resp = g_ptr_array_new_with_free_func(g_free);
+}
+
+static
+void
+test_target_finalize(
+ GObject* object)
+{
+ TestTarget* self = TEST_TARGET(object);
+
+ if (self->transmit_id) {
+ g_source_remove(self->transmit_id);
+ }
+ g_ptr_array_free(self->cmd_resp, TRUE);
+ G_OBJECT_CLASS(test_target_parent_class)->finalize(object);
}
static
@@ -76,7 +156,89 @@
test_target_class_init(
NfcTargetClass* klass)
{
+ klass->transmit = test_target_transmit;
+ klass->cancel_transmit = test_target_cancel_transmit;
klass->deactivate = test_target_deactivate;
+ G_OBJECT_CLASS(klass)->finalize = test_target_finalize;
+}
+
+NfcTarget*
+test_target_new(
+ int fail)
+{
+ TestTarget* self = g_object_new(TEST_TYPE_TARGET, NULL);
+
+ self->fail_transmit = fail;
+ return NFC_TARGET(self);
+}
+
+NfcTarget*
+test_target_new_tech(
+ NFC_TECHNOLOGY tech,
+ int fail)
+{
+ TestTarget* self = g_object_new(TEST_TYPE_TARGET, NULL);
+ NfcTarget* target = NFC_TARGET(self);
+
+ target->technology = tech;
+ self->fail_transmit = fail;
+ return target;
+}
+
+NfcTarget*
+test_target_new_tech_with_data(
+ NFC_TECHNOLOGY tech,
+ const void* cmd_bytes,
+ guint cmd_len,
+ const void* resp_bytes,
+ guint resp_len)
+{
+ TestTarget* self = g_object_new(TEST_TYPE_TARGET, NULL);
+
+ self->target.technology = tech;
+ self->fail_transmit = TEST_TARGET_FAIL_NONE;
+ g_ptr_array_add(self->cmd_resp, test_alloc_data(cmd_bytes, cmd_len));
+ g_ptr_array_add(self->cmd_resp, test_alloc_data(resp_bytes, resp_len));
+ return &self->target;
+}
+
+void
+test_target_add_data(
+ NfcTarget* target,
+ const void* cmd_bytes,
+ guint cmd_len,
+ const void* resp_bytes,
+ guint resp_len)
+{
+ TestTarget* self = TEST_TARGET(target);
+
+ self->fail_transmit = TEST_TARGET_FAIL_NONE;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/common/test_target.h
^
|
@@ -33,15 +33,59 @@
#ifndef TEST_TARGET_H
#define TEST_TARGET_H
-#include <nfc_types.h>
+#include "nfc_target_impl.h"
+
+typedef NfcTargetClass TestTargetClass;
+typedef struct test_target {
+ NfcTarget target;
+ guint transmit_id;
+ GPtrArray* cmd_resp;
+ int fail_transmit;
+} TestTarget;
+
+GType test_target_get_type(void);
+#define TEST_TYPE_TARGET (test_target_get_type())
+#define TEST_TARGET(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_TARGET, TestTarget))
+
+#define TEST_TARGET_FAIL_ALL (-1)
+#define TEST_TARGET_FAIL_NONE (FALSE)
NfcTarget*
test_target_new(
- void);
+ int fail);
NfcTarget*
test_target_new_tech(
- NFC_TECHNOLOGY tech);
+ NFC_TECHNOLOGY tech,
+ int fail);
+
+NfcTarget*
+test_target_new_tech_with_data(
+ NFC_TECHNOLOGY tech,
+ const void* cmd_bytes,
+ guint cmd_len,
+ const void* resp_bytes,
+ guint resp_len);
+
+#define test_target_new_with_data(cmd,cmd_len,resp,resp_len) \
+ test_target_new_tech_with_data(NFC_TECHNOLOGY_A,cmd,cmd_len,resp,resp_len)
+
+void
+test_target_add_data(
+ NfcTarget* target,
+ const void* cmd_bytes,
+ guint cmd_len,
+ const void* resp_bytes,
+ guint resp_len);
+
+NfcTarget*
+test_target_new_with_tx(
+ const TestTx* tx_list,
+ gsize tx_count);
+
+#define test_target_tx_remaining(target) \
+ (TEST_TARGET(target)->cmd_resp->len)
#endif /* TEST_TARGET_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_adapter/Makefile
^
|
@@ -2,6 +2,6 @@
EXE = test_core_adapter
-COMMON_SRC = test_main.c test_target.c
+COMMON_SRC = test_main.c test_initiator.c test_target.c
include ../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_adapter/test_core_adapter.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,18 +30,25 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "test_common.h"
-#include "test_target.h"
-
#include "nfc_adapter_p.h"
#include "nfc_adapter_impl.h"
+#include "nfc_peer_services.h"
+#include "nfc_initiator_impl.h"
+#include "nfc_initiator_p.h"
#include "nfc_target_impl.h"
#include "nfc_tag_t2.h"
+#include "nfc_peer.h"
+
+#include "test_common.h"
+#include "test_target.h"
+#include "test_initiator.h"
#include <gutil_log.h>
static TestOpt test_opt;
+static const guint8 symm_data[] = { 0x00, 0x00 };
+
static
void
test_adapter_inc(
@@ -61,6 +68,16 @@
(*(int*)user_data)++;
}
+static
+void
+test_adapter_peer_inc(
+ NfcAdapter* adapter,
+ NfcPeer* peer,
+ void* user_data)
+{
+ (*(int*)user_data)++;
+}
+
/*==========================================================================*
* Test adapter
*==========================================================================*/
@@ -220,29 +237,38 @@
{
/* Public interfaces are NULL tolerant */
g_assert(!nfc_adapter_ref(NULL));
+ g_assert(!nfc_adapter_peers(NULL));
g_assert(!nfc_adapter_request_mode(NULL, 0));
g_assert(!nfc_adapter_add_tag_t2(NULL, NULL, NULL));
g_assert(!nfc_adapter_add_tag_t4a(NULL, NULL, NULL, NULL));
g_assert(!nfc_adapter_add_tag_t4b(NULL, NULL, NULL, NULL));
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- g_assert(!nfc_adapter_add_other_tag(NULL, NULL));
- G_GNUC_END_IGNORE_DEPRECATIONS
+ g_assert(!nfc_adapter_add_peer_initiator_a(NULL, NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_initiator_f(NULL, NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_target_a(NULL, NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_target_f(NULL, NULL, NULL, NULL));
g_assert(!nfc_adapter_add_target_presence_handler(NULL, NULL, NULL));
g_assert(!nfc_adapter_add_tag_added_handler(NULL, NULL, NULL));
g_assert(!nfc_adapter_add_tag_removed_handler(NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_added_handler(NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_removed_handler(NULL, NULL, NULL));
g_assert(!nfc_adapter_add_powered_changed_handler(NULL, NULL, NULL));
g_assert(!nfc_adapter_add_power_requested_handler(NULL, NULL, NULL));
g_assert(!nfc_adapter_add_mode_changed_handler(NULL, NULL, NULL));
g_assert(!nfc_adapter_add_mode_requested_handler(NULL, NULL, NULL));
g_assert(!nfc_adapter_add_enabled_changed_handler(NULL, NULL, NULL));
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ g_assert(!nfc_adapter_add_other_tag(NULL, NULL));
+ G_GNUC_END_IGNORE_DEPRECATIONS
nfc_adapter_set_name(NULL, NULL);
+ nfc_adapter_set_services(NULL, NULL);
nfc_adapter_mode_notify(NULL, 0, FALSE);
nfc_adapter_target_notify(NULL, FALSE);
nfc_adapter_power_notify(NULL, FALSE, FALSE);
nfc_adapter_set_enabled(NULL, TRUE);
nfc_adapter_request_power(NULL, TRUE);
nfc_adapter_remove_tag(NULL, NULL);
+ nfc_adapter_remove_peer(NULL, NULL);
nfc_adapter_remove_handler(NULL, 0);
nfc_adapter_remove_handlers(NULL, NULL, 0);
nfc_adapter_unref(NULL);
@@ -259,6 +285,7 @@
{
TestAdapter* test = test_adapter_new();
NfcAdapter* adapter = &test->adapter;
+ NfcPeerServices* services = nfc_peer_services_new();
const char* name = "test";
g_assert(!nfc_adapter_add_target_presence_handler(adapter, NULL, NULL));
@@ -269,21 +296,29 @@
g_assert(!nfc_adapter_add_mode_changed_handler(adapter, NULL, NULL));
g_assert(!nfc_adapter_add_mode_requested_handler(adapter, NULL, NULL));
g_assert(!nfc_adapter_add_enabled_changed_handler(adapter, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_added_handler(adapter, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_removed_handler(adapter, NULL, NULL));
g_assert(!nfc_adapter_add_tag_t2(adapter, NULL, NULL));
g_assert(!nfc_adapter_add_tag_t4a(adapter, NULL, NULL, NULL));
g_assert(!nfc_adapter_add_tag_t4b(adapter, NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_initiator_a(adapter, NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_initiator_f(adapter, NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_target_a(adapter, NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_peer_target_f(adapter, NULL, NULL, NULL));
+ g_assert(!nfc_adapter_add_other_tag2(adapter, NULL, NULL));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert(!nfc_adapter_add_other_tag(adapter, NULL));
G_GNUC_END_IGNORE_DEPRECATIONS
- g_assert(!nfc_adapter_add_other_tag2(adapter, NULL, NULL));
nfc_adapter_remove_handler(adapter, 0);
nfc_adapter_set_name(adapter, name);
+ nfc_adapter_set_services(adapter, services);
g_assert(!g_strcmp0(adapter->name, name));
g_assert(nfc_adapter_ref(adapter) == adapter);
nfc_adapter_unref(adapter);
nfc_adapter_unref(adapter);
+ nfc_peer_services_unref(services);
}
/*==========================================================================*
@@ -581,8 +616,8 @@
void)
{
TestAdapter* test = test_adapter_new();
- NfcTarget* target0 = test_target_new_tech(NFC_TECHNOLOGY_A);
- NfcTarget* target1 = test_target_new();
+ NfcTarget* target0 = test_target_new_tech(NFC_TECHNOLOGY_A, FALSE);
+ NfcTarget* target1 = test_target_new(FALSE);
NfcAdapter* adapter = &test->adapter;
NfcTag* tag0;
NfcTag* tag1;
@@ -608,12 +643,17 @@
/* Test "presence_changed" signal */
nfc_adapter_target_notify(adapter, TRUE);
- nfc_adapter_target_notify(adapter, TRUE);
- g_assert(adapter->target_present);
- g_assert(presence_changed_count == 1);
+ g_assert(!adapter->target_present);
+ g_assert_cmpint(presence_changed_count, == ,0);
memset(&poll, 0, sizeof(poll));
tag0 = nfc_adapter_add_tag_t2(adapter, target0, &poll.a);
+ g_assert(adapter->target_present);
+ g_assert_cmpint(presence_changed_count, == ,1);
+
+ nfc_adapter_target_notify(adapter, TRUE); /* Has no effect */
+ g_assert_cmpint(presence_changed_count, == ,1);
+
tag1 = nfc_adapter_add_other_tag2(adapter, target1, NULL);
g_assert(tag0);
g_assert(tag1);
@@ -626,15 +666,15 @@
nfc_adapter_target_notify(adapter, FALSE);
g_assert(nfc_adapter_request_mode(adapter, NFC_MODE_NONE));
g_assert(adapter->target_present);
- g_assert(presence_changed_count == 1);
+ g_assert_cmpint(presence_changed_count, == ,1);
/* Remove the tags */
nfc_target_gone(target0);
nfc_adapter_remove_tag(adapter, tag1->name);
g_assert(!adapter->target_present);
- g_assert(presence_changed_count == 2);
- g_assert(tag_added == 2);
- g_assert(tag_removed == 2);
+ g_assert_cmpint(presence_changed_count, == ,2);
+ g_assert_cmpint(tag_added, == ,2);
+ g_assert_cmpint(tag_removed, == ,2);
/* These have no effect */
nfc_adapter_remove_tag(adapter, NULL);
@@ -651,6 +691,164 @@
}
/*==========================================================================*
+ * peer
+ *==========================================================================*/
+
+static
+void
+test_peer(
+ void)
+{
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_crc/test_core_crc.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018 Jolla Ltd.
- * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -14,8 +14,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -30,10 +30,11 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "test_common.h"
-
+#include "nfc_types_p.h"
#include "nfc_crc.h"
+#include "test_common.h"
+
static TestOpt test_opt;
typedef struct test_crc16 {
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_initiator/Makefile
^
|
@@ -0,0 +1,5 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_core_initiator
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_initiator/test_core_initiator.c
^
|
@@ -0,0 +1,690 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_common.h"
+
+#include "nfc_initiator_p.h"
+#include "nfc_initiator_impl.h"
+
+#include <gutil_log.h>
+
+static TestOpt test_opt;
+
+static const GUtilData test_in = { (const void*)"in", 2 };
+static const GUtilData test_out = { (const void*)"out", 3 };
+
+static
+void
+test_initiator_inc(
+ NfcInitiator* initiator,
+ void* user_data)
+{
+ (*(int*)user_data)++;
+}
+
+/*==========================================================================*
+ * Test initiator
+ *==========================================================================*/
+
+typedef NfcInitiatorClass TestInitiator1Class;
+typedef struct test_initiator1 {
+ NfcInitiator initiator;
+ GPtrArray* resp;
+ guint flags;
+
+#define TEST_INITIATOR_FAIL_RESPONSE (0x01)
+#define TEST_INITIATOR_DONT_COMPLETE (0x02)
+
+} TestInitiator1;
+
+#define TEST_TYPE_INITIATOR1 (test_initiator1_get_type())
+#define TEST_INITIATOR1(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_INITIATOR1, TestInitiator1))
+#define PARENT_CLASS test_initiator1_parent_class
+G_DEFINE_TYPE(TestInitiator1, test_initiator1, NFC_TYPE_INITIATOR)
+
+static
+gboolean
+test_initiator1_respond(
+ NfcInitiator* initiator,
+ const void* data,
+ guint len)
+{
+ TestInitiator1* self = TEST_INITIATOR1(initiator);
+
+ g_ptr_array_add(self->resp, test_alloc_data(data, len));
+ if (self->flags & TEST_INITIATOR_FAIL_RESPONSE) {
+ /* Default callback return FALSE */
+ return NFC_INITIATOR_CLASS(test_initiator1_parent_class)->respond
+ (initiator, data, len);
+ } else if (self->flags & TEST_INITIATOR_DONT_COMPLETE) {
+ GDEBUG("Queueing response");
+ return TRUE;
+ } else {
+ nfc_initiator_response_sent(initiator, NFC_TRANSMIT_STATUS_OK);
+ return TRUE;
+ }
+}
+
+static
+void
+test_initiator1_deactivate(
+ NfcInitiator* initiator)
+{
+ /* Base class does nothing */
+ g_assert(initiator->present);
+ NFC_INITIATOR_CLASS(test_initiator1_parent_class)->deactivate(initiator);
+ g_assert(initiator->present);
+ nfc_initiator_gone(initiator);
+ g_assert(!initiator->present);
+}
+
+static
+void
+test_initiator1_finalize(
+ GObject* object)
+{
+ TestInitiator1* self = TEST_INITIATOR1(object);
+
+ g_ptr_array_free(self->resp, TRUE);
+ G_OBJECT_CLASS(test_initiator1_parent_class)->finalize(object);
+}
+
+static
+void
+test_initiator1_init(
+ TestInitiator1* self)
+{
+ self->resp = g_ptr_array_new_with_free_func(g_free);
+}
+
+static
+void
+test_initiator1_class_init(
+ TestInitiator1Class* klass)
+{
+ klass->respond = test_initiator1_respond;
+ klass->deactivate = test_initiator1_deactivate;
+ G_OBJECT_CLASS(klass)->finalize = test_initiator1_finalize;
+}
+
+static
+NfcInitiator*
+test_initiator1_new(
+ guint flags)
+{
+ TestInitiator1* self = g_object_new(TEST_TYPE_INITIATOR1, NULL);
+
+ self->flags = flags;
+ return NFC_INITIATOR(self);
+}
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null(
+ void)
+{
+ NfcInitiator* init = test_initiator1_new(0);
+
+ /* Public interfaces are NULL tolerant */
+ g_assert(!nfc_initiator_ref(NULL));
+ g_assert(!nfc_initiator_add_transmission_handler(NULL, NULL, NULL));
+ g_assert(!nfc_initiator_add_transmission_handler(init, NULL, NULL));
+ g_assert(!nfc_initiator_add_gone_handler(init, NULL, NULL));
+ g_assert(!nfc_initiator_add_gone_handler(NULL, NULL, NULL));
+ nfc_initiator_deactivate(NULL);
+ nfc_initiator_remove_handler(NULL, 0);
+ nfc_initiator_remove_handler(init, 0);
+ nfc_initiator_remove_handlers(NULL, NULL, 0);
+ nfc_initiator_remove_handlers(init, NULL, 0);
+ nfc_initiator_transmit(NULL, NULL, 0);
+ nfc_initiator_response_sent(NULL, NFC_TRANSMIT_STATUS_ERROR);
+ nfc_initiator_gone(NULL);
+ nfc_initiator_unref(NULL);
+
+ g_assert(!nfc_transmission_respond(NULL, NULL, 0, NULL, NULL));
+ g_assert(!nfc_transmission_ref(NULL));
+ nfc_transmission_unref(NULL);
+
+ nfc_initiator_unref(init);
+}
+
+/*==========================================================================*
+ * basic
+ *==========================================================================*/
+
+static
+void
+test_basic_transmission_ok(
+ NfcTransmission* t,
+ gboolean ok,
+ void* user_data)
+{
+ g_assert(ok);
+ (*(int*)user_data)++;
+}
+
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_llc/Makefile
^
|
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_core_llc
+
+COMMON_SRC = test_main.c test_target.c test_initiator.c
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_llc/test_core_llc.c
^
|
@@ -0,0 +1,2252 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_llc.h"
+#include "nfc_llc_io.h"
+#include "nfc_llc_param.h"
+#include "nfc_peer_services.h"
+#include "nfc_peer_service_p.h"
+#include "nfc_peer_service_impl.h"
+#include "nfc_peer_connection_p.h"
+#include "nfc_peer_connection_impl.h"
+#include "nfc_initiator.h"
+#include "nfc_target_impl.h"
+
+#include "test_common.h"
+#include "test_target.h"
+#include "test_initiator.h"
+
+#include <gutil_log.h>
+
+static TestOpt test_opt;
+
+#define TEST_PREFIX "/core/llc/"
+#define TEST_(name) TEST_PREFIX name
+
+static const guint8 symm_pdu_data[] = { 0x00, 0x00 };
+static const guint8 connect_urn_nfc_sn_handover_data[] = {
+ 0x05, 0x21, 0x02, 0x02, 0x07, 0xff, 0x05, 0x01,
+ 0x0f, 0x06, 0x13, 0x75, 0x72, 0x6e, 0x3a, 0x6e,
+ 0x66, 0x63, 0x3a, 0x73, 0x6e, 0x3a, 0x68, 0x61,
+ 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72
+};
+static const guint8 connect_2_data[] = {
+ 0x11, 0x20, 0x02, 0x02, 0x07, 0xff, 0x05, 0x01,
+ /*^ DSAP = 2 */
+ 0x0f
+};
+static const guint8 connect_sdp_empty_data[] = {
+ 0x05, 0x20
+};
+static const guint8 llc_param_tlv_data[] = {
+ 0x01, 0x01, 0x11, 0x02, 0x02, 0x07, 0xff, 0x03,
+ 0x02, 0x00, 0x13, 0x04, 0x01, 0xff, 0x07, 0x01,
+ 0x03
+};
+static const GUtilData llc_param_tlv = {
+ TEST_ARRAY_AND_SIZE(llc_param_tlv_data)
+};
+
+static
+void
+test_llc_quit_loop_cb(
+ NfcLlc* llc,
+ void* user_data)
+{
+ g_main_loop_quit((GMainLoop*)user_data);
+}
+
+static
+void
+test_llc_quit_when_dead_cb(
+ NfcPeerConnection* conn,
+ void* user_data)
+{
+ GDEBUG("Connection state %d", conn->state);
+
+ if (conn->state == NFC_LLC_CO_DEAD) {
+ g_main_loop_quit((GMainLoop*)user_data);
+ }
+}
+
+/*==========================================================================*
+ * Test connection
+ *==========================================================================*/
+
+typedef NfcPeerConnectionClass TestConnectionClass;
+typedef struct test_connection TestConnection;
+typedef void (*TestConnectionHookFunc)(TestConnection* conn, void* user_data);
+typedef struct test_connection_hook {
+ TestConnectionHookFunc proc;
+ void* user_data;
+} TestConnectionHook;
+
+struct test_connection {
+ NfcPeerConnection connection;
+ TestConnectionHook state_change_hook;
+ TestConnectionHook finalize_hook;
+ gboolean accept_connection;
+ GByteArray* received;
+};
+
+G_DEFINE_TYPE(TestConnection, test_connection, NFC_TYPE_PEER_CONNECTION)
+#define TEST_TYPE_CONNECTION (test_connection_get_type())
+#define TEST_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_CONNECTION, TestConnection))
+#define TEST_CONNECTION_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), \
+ TEST_TYPE_CONNECTION, TestConnectionClass)
+
+static
+void
+test_connection_accept(
+ NfcPeerConnection* conn)
+{
+ TestConnection* test = TEST_CONNECTION(conn);
+
+ if (test->accept_connection) {
+ nfc_peer_connection_accepted(conn);
+ } else {
+ nfc_peer_connection_rejected(conn);
+ }
+}
+
+static
+void
+test_connection_state_changed(
+ NfcPeerConnection* conn)
+{
+ TestConnection* test = TEST_CONNECTION(conn);
+
+ if (test->state_change_hook.proc) {
+ test->state_change_hook.proc(test, test->state_change_hook.user_data);
+ }
+ NFC_PEER_CONNECTION_CLASS(test_connection_parent_class)->
+ state_changed(conn);
+}
+
+static
+void
+test_connection_data_received(
+ NfcPeerConnection* conn,
+ const void* data,
+ guint len)
+{
+ TestConnection* test = TEST_CONNECTION(conn);
+
+ g_byte_array_append(test->received, data, len);
+ NFC_PEER_CONNECTION_CLASS(test_connection_parent_class)->
+ data_received(conn, data, len);
+}
+
+static
+void
+test_connection_init(
+ TestConnection* test)
+{
+ test->received = g_byte_array_new();
+}
+
+static
+void
+test_connection_finalize(
+ GObject* object)
+{
+ TestConnection* test = TEST_CONNECTION(object);
+
+ if (test->finalize_hook.proc) {
+ test->finalize_hook.proc(test, test->finalize_hook.user_data);
+ }
+ g_byte_array_free(test->received, TRUE);
+ G_OBJECT_CLASS(test_connection_parent_class)->finalize(object);
+}
+
+static
+void
+test_connection_class_init(
+ TestConnectionClass* klass)
+{
+ klass->accept = test_connection_accept;
+ klass->state_changed = test_connection_state_changed;
+ klass->data_received = test_connection_data_received;
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_llc_param/Makefile
^
|
@@ -0,0 +1,5 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_core_llc_param
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_llc_param/test_core_llc_param.c
^
|
@@ -0,0 +1,738 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_common.h"
+
+#include "nfc_llc_param.h"
+
+static TestOpt test_opt;
+
+#define TEST_(name) "/core/llc_param/" name
+#define TESTE_(name) TEST_("encode/" name)
+#define TESTD_(name) TEST_("decode/" name)
+
+typedef struct test_single_param_data {
+ const char* name;
+ GUtilData tlv;
+ NfcLlcParam param;
+} TestSingleParamData;
+
+static const guint8 tlv_version_1_0[] = {
+ NFC_LLC_PARAM_VERSION, 0x01, NFC_LLCP_VERSION_1_0
+};
+static const guint8 tlv_wks[] = {
+ NFC_LLC_PARAM_WKS, 0x02, 0x01, 0x03
+};
+static const guint8 tlv_lto[] = {
+ NFC_LLC_PARAM_LTO, 0x01, 0x01
+};
+static const guint8 tlv_sn[] = {
+ NFC_LLC_PARAM_SN, 0x0f,
+ 'u', 'r', 'n', ':', 'n', 'f', 'c', ':',
+ 's', 'n', ':', 's', 'n', 'e', 'p'
+};
+static const guint8 tlv_empty_sn[] = {
+ NFC_LLC_PARAM_SN, 0x00
+};
+static const guint8 tlv_opt[] = {
+ NFC_LLC_PARAM_OPT, 0x01, NFC_LLC_OPT_CL | NFC_LLC_OPT_CO
+};
+static const guint8 tlv_empty_sdreq[] = {
+ NFC_LLC_PARAM_SDREQ, 0x01, 0x0a
+};
+static const guint8 tlv_sdreq[] = {
+ NFC_LLC_PARAM_SDREQ, 0x10, 0x0a, 'u', 'r', 'n', ':',
+ 'n', 'f', 'c', ':', 's', 'n', ':', 's', 'n', 'e', 'p'
+};
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null(
+ void)
+{
+ g_assert(!nfc_llc_param_encode(NULL, NULL, 0));
+ g_assert(!nfc_llc_param_decode(NULL));
+ nfc_llc_param_free(NULL);
+}
+
+/*==========================================================================*
+ * empty
+ *==========================================================================*/
+
+static
+void
+test_empty(
+ void)
+{
+ GUtilData tlv;
+ NfcLlcParam** params;
+ static const guint8 data[] = { 0x00, 0x00 };
+ GByteArray* bytes;
+
+ memset(&tlv, 0, sizeof(tlv));
+ params = nfc_llc_param_decode(&tlv);
+ g_assert(params);
+ g_assert(!params[0]);
+ nfc_llc_param_free(params);
+
+ TEST_BYTES_SET(tlv, data);
+ params = nfc_llc_param_decode(&tlv);
+ g_assert(params);
+ g_assert(!params[0]);
+
+ /* Encoding empty (but non-NULL) list produces empty (but non-NULL)
+ * byte array */
+ bytes = nfc_llc_param_encode(nfc_llc_param_constify(params), NULL, 0);
+ g_assert(bytes);
+ g_assert(!bytes->len);
+ g_byte_array_free(bytes, TRUE);
+
+ nfc_llc_param_free(params);
+}
+
+/*==========================================================================*
+ * find
+ *==========================================================================*/
+
+static
+void
+test_find(
+ void)
+{
+ GUtilData tlv;
+ NfcLlcParam** params;
+ const NfcLlcParam* param;
+
+ g_assert(!nfc_llc_param_find(NULL, NFC_LLC_PARAM_VERSION));
+
+ TEST_BYTES_SET(tlv, tlv_version_1_0);
+ params = nfc_llc_param_decode(&tlv);
+ g_assert(params);
+ param = params[0];
+ g_assert(param);
+ g_assert(param->type == NFC_LLC_PARAM_VERSION);
+ g_assert(!params[1]);
+
+ g_assert(nfc_llc_param_find(nfc_llc_param_constify(params),
+ NFC_LLC_PARAM_VERSION) == param);
+ g_assert(!nfc_llc_param_find(nfc_llc_param_constify(params),
+ NFC_LLC_PARAM_SN));
+
+ nfc_llc_param_free(params);
+}
+
+/*==========================================================================*
+ * count
+ *==========================================================================*/
+
+static
+void
+test_count(
+ void)
+{
+ const NfcLlcParam* params[2];
+ static NfcLlcParam param = { NFC_LLC_PARAM_VERSION, .value.version =
+ NFC_LLCP_VERSION_1_0 };
+
+ params[0] = NULL;
+ g_assert(!nfc_llc_param_count(NULL));
+ g_assert(!nfc_llc_param_count(params));
+
+ params[0] = ¶m;
+ params[1] = NULL;
+ g_assert_cmpuint(nfc_llc_param_count(params), == ,1);
+}
+
+/*==========================================================================*
+ * truncate
+ *==========================================================================*/
+
+static
+void
+test_truncate(
+ void)
+{
+ static NfcLlcParam param1 = { NFC_LLC_PARAM_VERSION, .value.version =
+ NFC_LLCP_VERSION_1_0 };
+ static NfcLlcParam param2 = { NFC_LLC_PARAM_VERSION, .value.version =
+ NFC_LLCP_VERSION_1_1 };
+ static const guint8 tlv[] = {
+ NFC_LLC_PARAM_VERSION, 0x01, NFC_LLCP_VERSION_1_0,
+ NFC_LLC_PARAM_VERSION, 0x01, NFC_LLCP_VERSION_1_1
+ };
+ const NfcLlcParam* params[3];
+ GByteArray* bytes = NULL;
+
+ /* Nothing fits at all */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_manager/Makefile
^
|
@@ -2,4 +2,6 @@
EXE = test_core_manager
+COMMON_SRC = test_main.c test_service.c
+
include ../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_manager/test_core_manager.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,8 +30,10 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "test_service.h"
#include "test_common.h"
+#include "nfc_manager_p.h"
#include "internal/nfc_manager_i.h"
#include "nfc_adapter_impl.h"
@@ -181,13 +183,20 @@
g_assert(!nfc_manager_add_adapter(NULL, NULL));
g_assert(!nfc_manager_add_adapter_added_handler(NULL, NULL, NULL));
g_assert(!nfc_manager_add_adapter_removed_handler(NULL, NULL, NULL));
+ g_assert(!nfc_manager_add_service_registered_handler(NULL, NULL, NULL));
+ g_assert(!nfc_manager_add_service_unregistered_handler(NULL, NULL, NULL));
g_assert(!nfc_manager_add_enabled_changed_handler(NULL, NULL, NULL));
+ g_assert(!nfc_manager_add_mode_changed_handler(NULL, NULL, NULL));
g_assert(!nfc_manager_add_stopped_handler(NULL, NULL, NULL));
+ g_assert(!nfc_manager_mode_request_new(NULL, 0, 0));
+ nfc_manager_mode_request_free(NULL);
nfc_manager_stop(NULL, 0);
nfc_manager_set_enabled(NULL, FALSE);
nfc_manager_request_power(NULL, FALSE);
nfc_manager_request_mode(NULL, NFC_MODE_NONE);
+ nfc_manager_register_service(NULL, NULL);
+ nfc_manager_unregister_service(NULL, NULL);
nfc_manager_remove_adapter(NULL, NULL);
nfc_manager_remove_handler(NULL, 0);
nfc_manager_remove_handlers(NULL, NULL, 0);
@@ -217,6 +226,10 @@
g_assert(plugins);
g_assert(!plugins[0]);
+ /* NULL services are ignored */
+ g_assert(!nfc_manager_register_service(manager, NULL));
+ nfc_manager_unregister_service(manager, NULL);
+
/* No adapters */
g_assert(!nfc_manager_get_adapter(manager, "foo"));
id = nfc_manager_add_adapter_removed_handler(manager,
@@ -259,6 +272,8 @@
g_assert(!nfc_manager_add_adapter(manager, NULL));
g_assert(!nfc_manager_add_adapter_added_handler(manager, NULL, NULL));
g_assert(!nfc_manager_add_adapter_removed_handler(manager, NULL, NULL));
+ g_assert(!nfc_manager_add_service_registered_handler(manager, NULL, NULL));
+ g_assert(!nfc_manager_add_service_unregistered_handler(manager, NULL,NULL));
g_assert(!nfc_manager_add_enabled_changed_handler(manager, NULL, NULL));
g_assert(!nfc_manager_add_stopped_handler(manager, NULL, NULL));
nfc_manager_remove_handler(manager, 0);
@@ -348,6 +363,155 @@
}
/*==========================================================================*
+ * mode
+ *==========================================================================*/
+
+static
+void
+test_mode(
+ void)
+{
+ NfcPluginsInfo pi;
+ NfcManager* manager;
+ int count = 0;
+ gulong id;
+ NfcModeRequest* enable_p2p;
+ NfcModeRequest* enable_all;
+ NfcModeRequest* enable_all2;
+ NfcModeRequest* disable_p2p;
+
+ memset(&pi, 0, sizeof(pi));
+ manager = nfc_manager_new(&pi);
+ nfc_manager_request_mode(manager, NFC_MODE_READER_WRITER);
+
+ /* Add the listener */
+ g_assert(!nfc_manager_add_mode_changed_handler(manager, NULL, NULL));
+ id = nfc_manager_add_mode_changed_handler(manager,
+ test_manager_inc, &count);
+
+ /* Core is refusing to create mode requests with no mode */
+ g_assert(!nfc_manager_mode_request_new(manager, 0, 0));
+
+ /* Enable P2P modes (NFC_MODE_P2P_INITIATOR disable bit gets ignored) */
+ enable_p2p = nfc_manager_mode_request_new(manager, NFC_MODES_P2P,
+ NFC_MODE_P2P_INITIATOR);
+ g_assert_cmpint(manager->mode, == ,NFC_MODES_P2P | NFC_MODE_READER_WRITER);
+ g_assert_cmpint(count, == ,1);
+ count = 0;
+
+ /* Try to disable those but they stay enabled */
+ disable_p2p = nfc_manager_mode_request_new(manager, 0, NFC_MODES_P2P);
+ g_assert_cmpint(manager->mode, == ,NFC_MODES_P2P | NFC_MODE_READER_WRITER);
+ g_assert_cmpint(count, == ,0);
+
+ /* Add another enable request on top of that */
+ enable_all = nfc_manager_mode_request_new(manager, NFC_MODES_ALL, 0);
+ g_assert_cmpint(manager->mode, == , NFC_MODES_ALL);
+ g_assert_cmpint(count, == ,1);
+ count = 0;
+
+ /* And the same request (no changes are signaled this time) */
+ enable_all2 = nfc_manager_mode_request_new(manager, NFC_MODES_ALL, 0);
+ g_assert_cmpint(manager->mode, == , NFC_MODES_ALL);
+ g_assert_cmpint(count, == ,0);
+
+ /* P2P modes get disabled when we release enable_p2p request */
+ nfc_manager_mode_request_free(enable_p2p);
+ g_assert_cmpint(manager->mode, == ,NFC_MODE_READER_WRITER |
+ NFC_MODE_CARD_EMILATION);
+ g_assert_cmpint(count, == ,1);
+ count = 0;
+
+ /* And re-enabled when we release disable_p2p */
+ nfc_manager_mode_request_free(disable_p2p);
+ g_assert_cmpint(manager->mode, == , NFC_MODES_ALL);
+ g_assert_cmpint(count, == ,1);
+ count = 0;
+
+ /* enable_all2 remains active after we release enable_all */
+ nfc_manager_mode_request_free(enable_all);
+ g_assert_cmpint(manager->mode, == , NFC_MODES_ALL);
+ g_assert_cmpint(count, == ,0);
+
+ /* We are back to the default when all requests are released */
+ nfc_manager_mode_request_free(enable_all2);
+ g_assert_cmpint(manager->mode, == , NFC_MODE_READER_WRITER);
+ g_assert_cmpint(count, == ,1);
+ count = 0;
+
+ nfc_manager_remove_handler(manager, id);
+ nfc_manager_unref(manager);
+}
+
+/*==========================================================================*
+ * service
+ *==========================================================================*/
+
+static
+void
+test_service_cb(
+ NfcManager* manager,
+ NfcPeerService* service,
+ void* user_data)
+{
+ (*(int*)user_data)++;
+}
+
+static
+void
+test_service(
+ void)
+{
+ NfcPluginsInfo pi;
+ NfcManager* manager;
+ NfcPeerService* service = NFC_PEER_SERVICE(test_service_new("foo"));
+ int registered = 0, unregistered = 0;
+
+ memset(&pi, 0, sizeof(pi));
+ manager = nfc_manager_new(&pi);
+
+ /* Empty list by default */
+ g_assert(manager->services);
+ g_assert(!manager->services[0]);
+
+ /* Some (non-zero) LLCP version must be there */
+ g_assert(manager->llcp_version);
+
+ /* Register the handlers */
+ g_assert(nfc_manager_add_service_registered_handler(manager,
+ test_service_cb, ®istered));
+ g_assert(nfc_manager_add_service_unregistered_handler(manager,
+ test_service_cb, &unregistered));
+
+ /* Register the service */
+ g_assert(nfc_manager_register_service(manager, service));
+ g_assert_cmpint(registered, == ,1);
+ g_assert_cmpint(unregistered, == ,0);
+ g_assert(manager->services[0] == service);
+ g_assert(!manager->services[1]);
+
+ /* Service can only be registered once */
+ g_assert(!nfc_manager_register_service(manager, service));
+ g_assert_cmpint(registered, == ,1);
+ g_assert_cmpint(unregistered, == ,0);
+
+ /* Then unregister it */
+ nfc_manager_unregister_service(manager, service);
+ g_assert_cmpint(registered, == ,1);
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_peer/Makefile
^
|
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_core_peer
+
+COMMON_SRC = test_main.c test_target.c test_initiator.c
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_peer/test_core_peer.c
^
|
@@ -0,0 +1,944 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_peer_p.h"
+#include "nfc_target.h"
+#include "nfc_initiator.h"
+#include "nfc_peer_services.h"
+#include "nfc_peer_service_impl.h"
+#include "nfc_peer_socket.h"
+#include "nfc_ndef.h"
+
+#include "test_common.h"
+#include "test_target.h"
+#include "test_initiator.h"
+
+#include <gutil_log.h>
+
+static TestOpt test_opt;
+
+static const guint8 initial_llcp_params [] = {
+ 0x46, 0x66, 0x6d, 0x01, 0x01, 0x11, 0x02, 0x02,
+ 0x07, 0xff, 0x03, 0x02, 0x00, 0x13, 0x04, 0x01,
+ 0xff
+};
+
+static const NfcParamNfcDepTarget target_params = {
+ { TEST_ARRAY_AND_SIZE(initial_llcp_params) }
+};
+
+static const NfcParamNfcDepInitiator initiator_params = {
+ { TEST_ARRAY_AND_SIZE(initial_llcp_params) }
+};
+
+static const guint8 symm_data[] = { 0x00, 0x00 };
+
+static
+void
+test_peer_quit_loop_cb(
+ NfcPeer* peer,
+ void* user_data)
+{
+ g_main_loop_quit((GMainLoop*)user_data);
+}
+
+static
+void
+test_peer_not_reached_cb(
+ NfcPeer* peer,
+ void* user_data)
+{
+ g_assert_not_reached();
+}
+
+static
+void
+test_peer_inc(
+ NfcPeer* peer,
+ void* user_data)
+{
+ (*((int*)user_data))++;
+}
+
+/*==========================================================================*
+ * Test service
+ *==========================================================================*/
+
+typedef NfcPeerServiceClass TestServiceClass;
+typedef struct test_service {
+ NfcPeerService service;
+ gboolean fail_connect;
+ int peer_in;
+ int peer_out;
+} TestService;
+
+G_DEFINE_TYPE(TestService, test_service, NFC_TYPE_PEER_SERVICE)
+#define TEST_TYPE_SERVICE (test_service_get_type())
+#define TEST_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_SERVICE, TestService))
+
+static
+void
+test_service_peer_arrived(
+ NfcPeerService* service,
+ NfcPeer* peer)
+{
+ TEST_SERVICE(service)->peer_in++;
+}
+
+static
+void
+test_service_peer_left(
+ NfcPeerService* service,
+ NfcPeer* peer)
+{
+ TEST_SERVICE(service)->peer_out++;
+}
+
+static
+NfcPeerConnection*
+test_service_new_connect(
+ NfcPeerService* service,
+ guint8 rsap,
+ const char* name)
+{
+ return TEST_SERVICE(service)->fail_connect ? NULL :
+ NFC_PEER_CONNECTION(nfc_peer_socket_new_connect(service, rsap, name));
+}
+
+static
+void
+test_service_init(
+ TestService* self)
+{
+}
+
+static
+void
+test_service_class_init(
+ TestServiceClass* klass)
+{
+ klass->peer_arrived = test_service_peer_arrived;
+ klass->peer_left = test_service_peer_left;
+ klass->new_connect = test_service_new_connect;
+}
+
+static
+TestService*
+test_service_client_new(
+ void)
+{
+ NfcPeerService* service = g_object_new(TEST_TYPE_SERVICE, NULL);
+
+ nfc_peer_service_init_base(service, NULL);
+ return TEST_SERVICE(service);
+}
+
+static
+TestService*
+test_service_client_new_fail(
+ void)
+{
+ TestService* self = g_object_new(TEST_TYPE_SERVICE, NULL);
+ NfcPeerService* service = &self->service;
+
+ nfc_peer_service_init_base(service, NULL);
+ service->sap = NFC_LLC_SAP_UNNAMED;
+ self->fail_connect = TRUE;
+ return self;
+}
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null(
+ void)
+{
+ /* Public interfaces are NULL tolerant */
+ g_assert(!nfc_peer_new_target(NULL, NFC_TECHNOLOGY_A, NULL, NULL));
+ g_assert(!nfc_peer_new_initiator(NULL, NFC_TECHNOLOGY_A, NULL, NULL));
+ g_assert(!nfc_peer_ref(NULL));
+ g_assert(!nfc_peer_connect(NULL, NULL, 0, NULL, NULL, NULL));
+ g_assert(!nfc_peer_connect_sn(NULL, NULL, NULL, NULL, NULL, NULL));
+ g_assert(!nfc_peer_add_wks_changed_handler(NULL, NULL, NULL));
+ g_assert(!nfc_peer_add_ndef_changed_handler(NULL, NULL, NULL));
+ g_assert(!nfc_peer_add_initialized_handler(NULL, NULL, NULL));
+ g_assert(!nfc_peer_add_gone_handler(NULL, NULL, NULL));
+ g_assert(!nfc_peer_register_service(NULL, NULL));
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_peer_service/Makefile
^
|
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_core_peer_service
+
+COMMON_SRC = test_main.c test_service.c
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_peer_service/test_core_peer_service.c
^
|
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_common.h"
+#include "test_service.h"
+
+#include "nfc_peer_service_p.h"
+#include "nfc_llc.h"
+
+#include <gutil_log.h>
+
+static TestOpt test_opt;
+
+#define TEST_(name) "/core/peer_service/" name
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null(
+ void)
+{
+ g_assert(!nfc_peer_service_ref(NULL));
+ nfc_peer_service_unref(NULL);
+ nfc_peer_service_disconnect_all(NULL);
+}
+
+/*==========================================================================*
+ * basic
+ *==========================================================================*/
+
+static
+void
+test_basic(
+ void)
+{
+ TestService* test_service = test_service_new("foo");
+ NfcPeerService* service = NFC_PEER_SERVICE(test_service);
+
+ g_assert_cmpuint(service->sap, == ,0);
+
+ /* Default implementation doesn't support connections */
+ g_assert(!nfc_peer_service_new_connect(service, 0, NULL));
+ g_assert(!nfc_peer_service_new_accept(service, 0));
+
+ g_assert(nfc_peer_service_ref(service) == service);
+ nfc_peer_service_unref(service);
+ nfc_peer_service_unref(service);
+}
+
+/*==========================================================================*
+ * snep_sap
+ *==========================================================================*/
+
+static
+void
+test_snep_sap(
+ void)
+{
+ TestService* test_service = test_service_new(NFC_LLC_NAME_SNEP);
+ NfcPeerService* service = NFC_PEER_SERVICE(test_service);
+
+ /* NFC_LLC_SAP_SNEP is automatically assigned */
+ g_assert_cmpuint(service->sap, == ,NFC_LLC_SAP_SNEP);
+ nfc_peer_service_unref(service);
+}
+
+/*==========================================================================*
+ * Common
+ *==========================================================================*/
+
+int main(int argc, char* argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+ g_test_add_func(TEST_("null"), test_null);
+ g_test_add_func(TEST_("basic"), test_basic);
+ g_test_add_func(TEST_("snep_sap"), test_snep_sap);
+ test_init(&test_opt, argc, argv);
+ return g_test_run();
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_peer_services/Makefile
^
|
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_core_peer_services
+
+COMMON_SRC = test_main.c test_service.c
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_peer_services/test_core_peer_services.c
^
|
@@ -0,0 +1,307 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_service.h"
+#include "test_common.h"
+
+#include "nfc_peer_services.h"
+#include "nfc_peer_service_impl.h"
+
+#include <gutil_log.h>
+
+static TestOpt test_opt;
+
+#define TEST_(name) "/core/peer_services/" name
+
+static
+guint
+test_services_count(
+ NfcPeerServices* services)
+{
+ guint n = 0;
+
+ if (services) {
+ NfcPeerService* const* ptr = services->list;
+
+ while (*ptr++) n++;
+ }
+ return n;
+}
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null(
+ void)
+{
+ g_assert(!nfc_peer_services_ref(NULL));
+ nfc_peer_services_unref(NULL);
+ g_assert(!nfc_peer_services_copy(NULL));
+ g_assert(!nfc_peer_services_find_sn(NULL, NULL));
+ g_assert(!nfc_peer_services_find_sap(NULL, 0));
+ g_assert(!nfc_peer_services_add(NULL, NULL));
+ g_assert(!nfc_peer_services_remove(NULL, NULL));
+ nfc_peer_services_peer_arrived(NULL, NULL);
+ nfc_peer_services_peer_left(NULL, NULL);
+}
+
+/*==========================================================================*
+ * basic
+ *==========================================================================*/
+
+static
+void
+test_basic(
+ void)
+{
+ NfcPeerServices* services = nfc_peer_services_new();
+ TestService* ts1 = test_service_new("foo");
+ TestService* ts2 = test_service_new("bar");
+ TestService* ts3 = test_service_new("");
+ TestService* ts4 = test_service_new(NULL);
+ TestService* ts5 = test_service_new("foo"); /* Duplicate name */
+ NfcPeerService* s1 = NFC_PEER_SERVICE(ts1);
+ NfcPeerService* s2 = NFC_PEER_SERVICE(ts2);
+ NfcPeerService* s3 = NFC_PEER_SERVICE(ts3);
+ NfcPeerService* s4 = NFC_PEER_SERVICE(ts4);
+ NfcPeerService* s5 = NFC_PEER_SERVICE(ts5);
+
+ g_assert(services->list);
+ g_assert_cmpuint(test_services_count(services), == ,0);
+ g_assert(nfc_peer_services_ref(services) == services);
+ nfc_peer_services_unref(services);
+
+ /* Make sure that add a) works and b) doesn't add the same thing twice */
+ g_assert(!nfc_peer_services_add(services, NULL));
+ g_assert(nfc_peer_services_add(services, s1));
+ g_assert(!nfc_peer_services_add(services, s5)); /* Duplicate name */
+ g_assert_cmpuint(s1->sap, == ,NFC_LLC_SAP_NAMED);
+ g_assert(!s5->sap);
+ g_assert_cmpuint(test_services_count(services), == ,1);
+ g_assert(!nfc_peer_services_add(services, s1));
+ g_assert_cmpuint(test_services_count(services), == ,1);
+ g_assert(nfc_peer_services_add(services, s2));
+ g_assert_cmpuint(test_services_count(services), == ,2);
+ g_assert_cmpuint(s2->sap, == ,NFC_LLC_SAP_NAMED + 1);
+ g_assert(nfc_peer_services_add(services, s3));
+ g_assert_cmpuint(test_services_count(services), == ,3);
+ g_assert_cmpuint(s3->sap, == ,NFC_LLC_SAP_UNNAMED);
+ g_assert(nfc_peer_services_add(services, s4));
+ g_assert_cmpuint(test_services_count(services), == ,4);
+ g_assert_cmpuint(s4->sap, == ,NFC_LLC_SAP_UNNAMED + 1);
+
+ /* Search */
+ g_assert(nfc_peer_services_find_sn(services, "foo") == s1);
+ g_assert(nfc_peer_services_find_sn(services, "bar") == s2);
+ g_assert(!nfc_peer_services_find_sn(services, NFC_LLC_NAME_SDP));
+ g_assert(!nfc_peer_services_find_sn(services, NULL));
+ g_assert(!nfc_peer_services_find_sn(services, ""));
+ g_assert(!nfc_peer_services_find_sap(services, 0));
+ g_assert(!nfc_peer_services_find_sap(services, NFC_LLC_SAP_SDP));
+ g_assert(!nfc_peer_services_find_sap(services, NFC_LLC_SAP_SNEP));
+ g_assert(!nfc_peer_services_find_sap(services, s4->sap + 1));
+ g_assert(nfc_peer_services_find_sap(services, s1->sap) == s1);
+ g_assert(nfc_peer_services_find_sap(services, s2->sap) == s2);
+ g_assert(nfc_peer_services_find_sap(services, s3->sap) == s3);
+ g_assert(nfc_peer_services_find_sap(services, s4->sap) == s4);
+
+ /* Notifications (those don't check peer pointer, so it can be NULL) */
+ nfc_peer_services_peer_arrived(services, NULL);
+ g_assert_cmpuint(ts1->peer_arrived, == ,1);
+ g_assert_cmpuint(ts2->peer_arrived, == ,1);
+ g_assert_cmpuint(ts3->peer_arrived, == ,1);
+ g_assert_cmpuint(ts4->peer_arrived, == ,1);
+
+ nfc_peer_services_peer_left(services, NULL);
+ g_assert_cmpuint(ts1->peer_left, == ,1);
+ g_assert_cmpuint(ts2->peer_left, == ,1);
+ g_assert_cmpuint(ts3->peer_left, == ,1);
+ g_assert_cmpuint(ts4->peer_left, == ,1);
+
+ /* Test removal */
+ g_assert(!nfc_peer_services_remove(services, NULL));
+ g_assert(nfc_peer_services_remove(services, s1));
+ g_assert(!nfc_peer_services_remove(services, s1));
+ g_assert_cmpuint(test_services_count(services), == ,3);
+ g_assert(!nfc_peer_services_find_sn(services, "foo"));
+ g_assert(nfc_peer_services_remove(services, s2));
+ g_assert(!nfc_peer_services_remove(services, s2));
+ g_assert_cmpuint(test_services_count(services), == ,2);
+ g_assert(!nfc_peer_services_find_sn(services, "bar"));
+ g_assert(nfc_peer_services_remove(services, s3));
+ g_assert(!nfc_peer_services_remove(services, s3));
+ g_assert_cmpuint(test_services_count(services), == ,1);
+ g_assert(nfc_peer_services_remove(services, s4));
+ g_assert(!nfc_peer_services_remove(services, s4));
+ g_assert_cmpuint(test_services_count(services), == ,0);
+
+ /* These do nothing with empty list */
+ nfc_peer_services_peer_arrived(services, NULL);
+ nfc_peer_services_peer_left(services, NULL);
+
+ /* Add some services back */
+ nfc_peer_services_add(services, s1);
+ nfc_peer_services_add(services, s2);
+
+ /* And deallocate everything */
+ nfc_peer_service_unref(s1);
+ nfc_peer_service_unref(s2);
+ nfc_peer_service_unref(s3);
+ nfc_peer_service_unref(s4);
+ nfc_peer_service_unref(s5);
+ nfc_peer_services_unref(services);
+}
+
+/*==========================================================================*
+ * copy
+ *==========================================================================*/
+
+static
+void
+test_copy(
+ void)
+{
+ NfcPeerServices* services = nfc_peer_services_new();
+ NfcPeerServices* copy = nfc_peer_services_copy(services);
+ TestService* ts1 = test_service_new("foo");
+ TestService* ts2 = test_service_new("bar");
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_peer_socket/Makefile
^
|
@@ -0,0 +1,5 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_core_peer_socket
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_peer_socket/test_core_peer_socket.c
^
|
@@ -0,0 +1,940 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_types_p.h"
+#include "nfc_target_impl.h"
+#include "nfc_peer_connection_impl.h"
+#include "nfc_peer_services.h"
+#include "nfc_peer_service_p.h"
+#include "nfc_peer_service_impl.h"
+#include "nfc_peer_socket.h"
+#include "nfc_llc_param.h"
+#include "nfc_llc_io.h"
+#include "nfc_llc.h"
+#include "nfc_ndef.h"
+
+#include "test_common.h"
+
+#include <gutil_log.h>
+
+#include <sys/socket.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+static TestOpt test_opt;
+
+#define TEST_(name) "/core/peer_socket/" name
+
+#define TEST_SERVICE_NAME "test"
+
+static const guint8 param_tlv_data[] = {
+ 0x01, 0x01, 0x11, 0x02, 0x02, 0x07, 0xff, 0x03,
+ 0x02, 0x00, 0x13, 0x04, 0x01, 0xff, 0x07, 0x01,
+ 0x03
+};
+static const GUtilData param_tlv = { TEST_ARRAY_AND_SIZE(param_tlv_data) };
+static const guint8 symm_data[] = { 0x00, 0x00 };
+
+static
+void
+test_int_inc(
+ gpointer data)
+{
+ (*((int*)data))++;
+}
+
+static
+void
+test_connection_dead_quit_loop_cb(
+ NfcPeerConnection* connection,
+ void* user_data)
+{
+ if (connection->state == NFC_LLC_CO_DEAD) {
+ GDEBUG("Done");
+ g_main_loop_quit((GMainLoop*)user_data);
+ }
+}
+
+/*==========================================================================*
+ * Test service
+ *==========================================================================*/
+
+typedef
+void
+(*TestServiceAcceptFunc)(
+ NfcPeerService* service,
+ NfcPeerSocket* socket,
+ void* user_data);
+
+typedef NfcPeerServiceClass TestServiceClass;
+typedef struct test_service {
+ NfcPeerService service;
+ TestServiceAcceptFunc accept_fn;
+ void* accept_data;
+} TestService;
+
+G_DEFINE_TYPE(TestService, test_service, NFC_TYPE_PEER_SERVICE)
+#define TEST_TYPE_SERVICE (test_service_get_type())
+#define TEST_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_SERVICE, TestService))
+
+static
+NfcPeerConnection*
+test_service_new_connect(
+ NfcPeerService* self,
+ guint8 rsap,
+ const char* name)
+{
+ NfcPeerSocket* s = nfc_peer_socket_new_connect(self, rsap, name);
+
+ return s ? NFC_PEER_CONNECTION(s) : NULL;
+}
+
+static
+NfcPeerConnection*
+test_service_new_accept(
+ NfcPeerService* service,
+ guint8 rsap)
+{
+ TestService* self = TEST_SERVICE(service);
+ NfcPeerSocket* s = nfc_peer_socket_new_accept(service, rsap);
+
+ if (s) {
+ if (self->accept_fn) {
+ self->accept_fn(service, s, self->accept_data);
+ }
+ return NFC_PEER_CONNECTION(s);
+ } else {
+ return NULL;
+ }
+}
+
+static
+void
+test_service_init(
+ TestService* self)
+{
+}
+
+static
+void
+test_service_class_init(
+ TestServiceClass* klass)
+{
+ klass->new_connect = test_service_new_connect;
+ klass->new_accept = test_service_new_accept;
+}
+
+static
+NfcPeerService*
+test_service_client_new(
+ guint8 sap)
+{
+ TestService* self = g_object_new(TEST_TYPE_SERVICE, NULL);
+ NfcPeerService* service = &self->service;
+
+ nfc_peer_service_init_base(service, NULL);
+ service->sap = sap;
+ return service;
+}
+
+static
+NfcPeerService*
+test_service_server_new(
+ const char* name,
+ guint8 sap,
+ TestServiceAcceptFunc accept_fn,
+ void* accept_data)
+{
+ TestService* self = g_object_new(TEST_TYPE_SERVICE, NULL);
+ NfcPeerService* service = &self->service;
+
+ self->accept_fn = accept_fn;
+ self->accept_data = accept_data;
+ nfc_peer_service_init_base(service, name);
+ service->sap = sap;
+ return service;
+}
+
+/*==========================================================================*
+ * Test target
+ *==========================================================================*/
+
+typedef NfcTargetClass TestTargetClass;
+typedef struct test_target {
+ NfcTarget target;
+ guint transmit_id;
+ GPtrArray* cmd_resp;
+} TestTarget;
+
+G_DEFINE_TYPE(TestTarget, test_target, NFC_TYPE_TARGET)
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_plugin/test_core_plugin.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,10 +30,10 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "test_common.h"
-
-#include "nfc_plugin_impl.h"
#include "nfc_plugin_p.h"
+#include "nfc_plugin_impl.h"
+
+#include "test_common.h"
#include <gutil_log.h>
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_snep/Makefile
^
|
@@ -0,0 +1,5 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_core_snep
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_snep/test_core_snep.c
^
|
@@ -0,0 +1,680 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_types_p.h"
+#include "nfc_ndef.h"
+#include "nfc_snep_server.h"
+#include "nfc_target_impl.h"
+#include "nfc_peer_services.h"
+#include "nfc_llc.h"
+#include "nfc_llc_io.h"
+#include "nfc_llc_param.h"
+
+#include "test_common.h"
+
+#include <gutil_log.h>
+
+static TestOpt test_opt;
+
+#define TEST_(name) "/core/snep/" name
+
+static
+void
+test_llc_quit_loop_cb(
+ NfcLlc* llc,
+ void* user_data)
+{
+ g_main_loop_quit((GMainLoop*)user_data);
+}
+
+static
+void
+test_snep_event_counter(
+ NfcSnepServer* snep,
+ void* user_data)
+{
+ (*((int*)user_data))++;
+}
+
+/*==========================================================================*
+ * Test target
+ *==========================================================================*/
+
+typedef NfcTargetClass TestTargetClass;
+typedef struct test_target {
+ NfcTarget target;
+ guint transmit_id;
+ GPtrArray* cmd_resp;
+} TestTarget;
+
+G_DEFINE_TYPE(TestTarget, test_target, NFC_TYPE_TARGET)
+#define TEST_TYPE_TARGET (test_target_get_type())
+#define TEST_TARGET(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_TARGET, TestTarget))
+
+static
+GUtilData*
+test_target_next_data(
+ TestTarget* self)
+{
+ if (self->cmd_resp->len) {
+ GUtilData* data = self->cmd_resp->pdata[0];
+
+ self->cmd_resp->pdata[0] = NULL;
+ g_ptr_array_remove_index(self->cmd_resp, 0);
+ return data;
+ }
+ return NULL;
+}
+
+static
+void
+test_target_cancel_transmit(
+ NfcTarget* target)
+{
+ TestTarget* self = TEST_TARGET(target);
+
+ g_assert(self->transmit_id);
+ g_source_remove(self->transmit_id);
+ self->transmit_id = 0;
+}
+
+static
+gboolean
+test_target_transmit_done(
+ gpointer user_data)
+{
+ TestTarget* self = TEST_TARGET(user_data);
+ NfcTarget* target = &self->target;
+
+ g_assert(self->transmit_id);
+ self->transmit_id = 0;
+ if (self->cmd_resp->len) {
+ GUtilData* data = test_target_next_data(self);
+
+ if (data) {
+ nfc_target_transmit_done(target, NFC_TRANSMIT_STATUS_OK,
+ data->bytes, data->size);
+ g_free(data);
+ } else {
+ nfc_target_transmit_done(target, NFC_TRANSMIT_STATUS_OK, NULL, 0);
+ }
+ } else {
+ nfc_target_transmit_done(target, NFC_TRANSMIT_STATUS_ERROR, NULL, 0);
+ }
+ return G_SOURCE_REMOVE;
+}
+
+static
+gboolean
+test_target_transmit(
+ NfcTarget* target,
+ const void* data,
+ guint len)
+{
+ TestTarget* self = TEST_TARGET(target);
+ GUtilData* expected = test_target_next_data(self);
+
+ if (expected) {
+ g_assert_cmpuint(expected->size, ==, len);
+ g_assert(!memcmp(data, expected->bytes, len));
+ g_free(expected);
+ }
+ self->transmit_id = g_idle_add(test_target_transmit_done, self);
+ return TRUE;
+}
+
+static
+void
+test_target_init(
+ TestTarget* self)
+{
+ self->cmd_resp = g_ptr_array_new_with_free_func(g_free);
+}
+
+static
+void
+test_target_finalize(
+ GObject* object)
+{
+ TestTarget* self = TEST_TARGET(object);
+
+ if (self->transmit_id) {
+ g_source_remove(self->transmit_id);
+ }
+ g_ptr_array_free(self->cmd_resp, TRUE);
+ G_OBJECT_CLASS(test_target_parent_class)->finalize(object);
+}
+
+static
+void
+test_target_class_init(
+ NfcTargetClass* klass)
+{
+ klass->transmit = test_target_transmit;
+ klass->cancel_transmit = test_target_cancel_transmit;
+ G_OBJECT_CLASS(klass)->finalize = test_target_finalize;
+}
+
+static
+void
+test_target_add_cmd_data(
+ TestTarget* self,
+ const GUtilData* data)
+{
+ g_ptr_array_add(self->cmd_resp, test_clone_data(data));
+}
+
+static
+void
+test_target_add_cmd(
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_tag/test_core_tag.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,13 +31,13 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "test_common.h"
-#include "test_target.h"
-
#include "nfc_tag_p.h"
#include "nfc_target_p.h"
#include "nfc_target_impl.h"
+#include "test_common.h"
+#include "test_target.h"
+
#include <gutil_log.h>
static TestOpt test_opt;
@@ -80,7 +81,7 @@
void)
{
NfcTag* tag = g_object_new(NFC_TYPE_TAG, NULL);
- NfcTarget* target = test_target_new();
+ NfcTarget* target = test_target_new(FALSE);
NfcParamPoll poll;
const char* name = "test";
int init_count = 0;
@@ -145,7 +146,7 @@
static const GUtilData nfcid1_data = { TEST_ARRAY_AND_SIZE(nfcid1) };
NfcTag* tag = g_object_new(NFC_TYPE_TAG, NULL);
- NfcTarget* target = test_target_new_tech(NFC_TECHNOLOGY_A);
+ NfcTarget* target = test_target_new_tech(NFC_TECHNOLOGY_A, FALSE);
NfcParamPoll poll;
const NfcParamPollA* poll_a;
@@ -184,21 +185,32 @@
{
static const guint8 nfcid0[] = {0x01, 0x01, 0x02, 0x04};
static const GUtilData nfcid0_data = { TEST_ARRAY_AND_SIZE(nfcid0) };
+ static const guint8 app_data[] = {0x05, 0x06, 0x07, 0x08};
+ static const guint8 prot_info[] = {0x09, 0x0A, 0x0B, 0x0C, 0x0D};
+ static const GUtilData prot_info_data = { TEST_ARRAY_AND_SIZE(prot_info) };
+ static const guint8 app_data_empty[] = {0x00, 0x00, 0x00, 0x00};
NfcTag* tag = g_object_new(NFC_TYPE_TAG, NULL);
- NfcTarget* target = test_target_new_tech(NFC_TECHNOLOGY_B);
+ NfcTarget* target = test_target_new_tech(NFC_TECHNOLOGY_B, FALSE);
NfcParamPoll poll;
const NfcParamPollB* poll_b;
memset(&poll, 0, sizeof(poll));
poll.b.nfcid0 = nfcid0_data;
+ poll.b.prot_info = prot_info_data;
+ memcpy(poll.b.app_data, app_data, sizeof(app_data));
nfc_tag_init_base(tag, target, &poll);
g_assert(tag->target == target);
g_assert(tag->present == TRUE);
poll_b = &nfc_tag_param(tag)->b;
g_assert(poll_b);
+ g_assert(poll_b->nfcid0.bytes != poll.b.nfcid0.bytes);
+ g_assert(poll_b->prot_info.bytes != poll.b.prot_info.bytes);
g_assert_cmpuint(poll_b->nfcid0.size, == ,sizeof(nfcid0));
g_assert(!memcmp(poll_b->nfcid0.bytes, nfcid0, sizeof(nfcid0)));
+ g_assert_cmpuint(poll_b->prot_info.size, == ,sizeof(prot_info));
+ g_assert(!memcmp(poll_b->prot_info.bytes, prot_info, sizeof(prot_info)));
+ g_assert(!memcmp(poll_b->app_data, app_data, sizeof(app_data)));
nfc_tag_unref(tag);
/* Make sure NULL nfcid0 is handled */
@@ -211,6 +223,59 @@
g_assert(!poll_b->nfcid0.bytes);
nfc_tag_unref(tag);
+ /* Make sure no prot_info and no app_data is handled */
+ tag = g_object_new(NFC_TYPE_TAG, NULL);
+ memset(&poll, 0, sizeof(poll));
+ poll.b.nfcid0 = nfcid0_data;
+ nfc_tag_init_base(tag, target, &poll);
+ g_assert(tag->target == target);
+ g_assert(tag->present == TRUE);
+ poll_b = &nfc_tag_param(tag)->b;
+ g_assert(poll_b);
+ g_assert_cmpuint(poll_b->nfcid0.size, == ,sizeof(nfcid0));
+ g_assert(!memcmp(poll_b->nfcid0.bytes, nfcid0, sizeof(nfcid0)));
+ g_assert_cmpuint(poll_b->prot_info.size, == ,0);
+ g_assert(!poll_b->prot_info.bytes);
+ g_assert(!memcmp(poll_b->app_data, app_data_empty, sizeof(app_data_empty)));
+ nfc_tag_unref(tag);
+
+ /* Make sure no app_data is handled properly */
+ tag = g_object_new(NFC_TYPE_TAG, NULL);
+ memset(&poll, 0, sizeof(poll));
+ poll.b.nfcid0 = nfcid0_data;
+ poll.b.prot_info = prot_info_data;
+ nfc_tag_init_base(tag, target, &poll);
+ g_assert(tag->target == target);
+ g_assert(tag->present == TRUE);
+ poll_b = &nfc_tag_param(tag)->b;
+ g_assert(poll_b);
+ g_assert(poll_b->nfcid0.bytes != poll.b.nfcid0.bytes);
+ g_assert(poll_b->prot_info.bytes != poll.b.prot_info.bytes);
+ g_assert_cmpuint(poll_b->nfcid0.size, == ,sizeof(nfcid0));
+ g_assert(!memcmp(poll_b->nfcid0.bytes, nfcid0, sizeof(nfcid0)));
+ g_assert_cmpuint(poll_b->prot_info.size, == ,sizeof(prot_info));
+ g_assert(!memcmp(poll_b->prot_info.bytes, prot_info, sizeof(prot_info)));
+ g_assert(!memcmp(poll_b->app_data, app_data_empty, sizeof(app_data_empty)));
+ nfc_tag_unref(tag);
+
+ /* Make sure NULL prot_info is handled */
+ tag = g_object_new(NFC_TYPE_TAG, NULL);
+ memset(&poll, 0, sizeof(poll));
+ poll.b.nfcid0 = nfcid0_data;
+ memcpy(poll.b.app_data, app_data, sizeof(app_data));
+ nfc_tag_init_base(tag, target, &poll);
+ g_assert(tag->target == target);
+ g_assert(tag->present == TRUE);
+ poll_b = &nfc_tag_param(tag)->b;
+ g_assert(poll_b);
+ g_assert(poll_b->nfcid0.bytes != poll.b.nfcid0.bytes);
+ g_assert_cmpuint(poll_b->nfcid0.size, == ,sizeof(nfcid0));
+ g_assert(!memcmp(poll_b->nfcid0.bytes, nfcid0, sizeof(nfcid0)));
+ g_assert_cmpuint(poll_b->prot_info.size, == ,0);
+ g_assert(!poll_b->prot_info.bytes);
+ g_assert(!memcmp(poll_b->app_data, app_data, sizeof(app_data)));
+ nfc_tag_unref(tag);
+
nfc_target_unref(target);
}
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_tag_t2/test_core_tag_t2.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,12 +31,12 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "test_common.h"
-
-#include "nfc_ndef.h"
#include "nfc_tag_p.h"
#include "nfc_tag_t2.h"
#include "nfc_target_impl.h"
+#include "nfc_ndef.h"
+
+#include "test_common.h"
#include <gutil_log.h>
#include <gutil_misc.h>
@@ -233,7 +234,7 @@
};
/*
- * Serial: 9a 85 5c 80
+ * UID: 04 ea 3d 9a 85 5c 80
* Data size: 872 bytes
*/
static const guint8 test_data_ntag216[] = { /* "https://www.merproject.org" */
@@ -684,11 +685,8 @@
void* user_data)
{
NfcTagType2* t2 = NFC_TAG_T2(tag);
- GUtilData serial;
- serial.bytes = test_data_empty + 4;
- serial.size = 4;
- g_assert(gutil_data_equal(&t2->serial, &serial));
+ g_assert(gutil_data_equal(&t2->serial, &t2->nfcid1));
g_main_loop_quit((GMainLoop*)user_data);
}
@@ -747,15 +745,10 @@
void* user_data)
{
NfcTagType2* t2 = NFC_TAG_T2(tag);
- TestTarget* test = TEST_TARGET(tag->target);
- GUtilData serial;
g_assert(tag->flags & NFC_TAG_FLAG_INITIALIZED);
- /* Serial should be there */
- serial.bytes = test->storage + 4;
- serial.size = 4;
- g_assert(gutil_data_equal(&t2->serial, &serial));
+ g_assert(gutil_data_equal(&t2->serial, &t2->nfcid1));
/* But no NDEF and no size */
g_assert(!tag->ndef);
@@ -796,7 +789,7 @@
NfcTagType2* t2 = NFC_TAG_T2(tag);
g_assert(tag->flags & NFC_TAG_FLAG_INITIALIZED);
- g_assert(!t2->serial.size);
+ g_assert(gutil_data_equal(&t2->serial, &t2->nfcid1));
g_assert(!t2->data_size);
g_assert(!tag->ndef);
g_main_loop_quit((GMainLoop*)user_data);
@@ -838,16 +831,11 @@
void* user_data)
{
NfcTagType2* t2 = NFC_TAG_T2(tag);
- TestTarget* test = TEST_TARGET(tag->target);
- GUtilData serial;
g_assert(tag->flags & NFC_TAG_FLAG_INITIALIZED);
g_assert(t2->data_size);
- /* Serial should be there */
- serial.bytes = test->storage + 4;
- serial.size = 4;
- g_assert(gutil_data_equal(&t2->serial, &serial));
+ g_assert(gutil_data_equal(&t2->serial, &t2->nfcid1));
/* But no NDEF */
g_assert(!tag->ndef);
@@ -909,12 +897,9 @@
TestTarget* test = TEST_TARGET(tag->target);
NfcTagType2* t2 = NFC_TAG_T2(tag);
NfcNdefRec* rec = tag->ndef;
- GUtilData serial;
guint8* buf;
- serial.bytes = test_data_google + 4;
- serial.size = 4;
- g_assert(gutil_data_equal(&t2->serial, &serial));
+ g_assert(gutil_data_equal(&t2->serial, &t2->nfcid1));
g_assert(t2->data_size == test->data.size - TEST_DATA_OFFSET);
g_assert(rec);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_tag_t4/Makefile
^
|
@@ -2,4 +2,6 @@
EXE = test_core_tag_t4
+COMMON_SRC = test_main.c test_target.c
+
include ../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_tag_t4/test_core_tag_t4.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,12 +31,13 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "test_common.h"
-
-#include "nfc_ndef.h"
#include "nfc_tag_p.h"
#include "nfc_tag_t4_p.h"
#include "nfc_target_impl.h"
+#include "nfc_ndef.h"
+
+#include "test_common.h"
+#include "test_target.h"
#include <gutil_log.h>
@@ -173,6 +175,8 @@
0x73, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, /* Data */
0x90, 0x00 /* SW1|SW2 */
};
+static gint reset_count = 0;
+static gint reset_free_count = 0;
static
void
@@ -183,144 +187,26 @@
g_main_loop_quit((GMainLoop*)user_data);
}
-/*==========================================================================*
- * Test target
- *==========================================================================*/
-
-typedef NfcTargetClass TestTargetClass;
-typedef struct test_target {
- NfcTarget target;
- guint transmit_id;
- GPtrArray* cmd_resp;
- int fail_transmit;
-} TestTarget;
-
-G_DEFINE_TYPE(TestTarget, test_target, NFC_TYPE_TARGET)
-#define TEST_TYPE_TARGET (test_target_get_type())
-#define TEST_TARGET(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
- TEST_TYPE_TARGET, TestTarget))
-
-static
-GUtilData*
-test_target_next_data(
- TestTarget* self)
-{
- if (self->cmd_resp->len) {
- GUtilData* data = self->cmd_resp->pdata[0];
-
- self->cmd_resp->pdata[0] = NULL;
- g_ptr_array_remove_index(self->cmd_resp, 0);
- return data;
- }
- return NULL;
-}
-
-static
-void
-test_target_cancel_transmit(
- NfcTarget* target)
-{
- TestTarget* self = TEST_TARGET(target);
-
- g_assert(self->transmit_id);
- g_source_remove(self->transmit_id);
- self->transmit_id = 0;
-}
-
-static
-gboolean
-test_target_transmit_done(
- gpointer user_data)
-{
- TestTarget* self = TEST_TARGET(user_data);
- NfcTarget* target = &self->target;
-
- g_assert(self->transmit_id);
- self->transmit_id = 0;
- if (self->cmd_resp->len) {
- GUtilData* data = test_target_next_data(self);
-
- if (data) {
- nfc_target_transmit_done(target, NFC_TRANSMIT_STATUS_OK,
- data->bytes, data->size);
- g_free(data);
- } else {
- nfc_target_transmit_done(target, NFC_TRANSMIT_STATUS_OK, NULL, 0);
- }
- } else {
- nfc_target_transmit_done(target, NFC_TRANSMIT_STATUS_ERROR, NULL, 0);
- }
- return G_SOURCE_REMOVE;
-}
-
-static
-gboolean
-test_target_transmit(
- NfcTarget* target,
- const void* data,
- guint len)
-{
- TestTarget* self = TEST_TARGET(target);
- GUtilData* expected = test_target_next_data(self);
-
- if (self->fail_transmit > 0 && --self->fail_transmit == 0) {
- GDEBUG("Simulating transmit failure");
- g_free(expected);
- return FALSE;
- } else {
- if (expected) {
- g_assert_cmpuint(expected->size, ==, len);
- g_assert(!memcmp(data, expected->bytes, len));
- g_free(expected);
- }
- self->transmit_id = g_idle_add(test_target_transmit_done, self);
- return TRUE;
- }
-}
-
-static
-void
-test_target_init(
- TestTarget* self)
-{
- self->cmd_resp = g_ptr_array_new_with_free_func(g_free);
-}
-
-static
-void
-test_target_finalize(
- GObject* object)
-{
- TestTarget* self = TEST_TARGET(object);
-
- if (self->transmit_id) {
- g_source_remove(self->transmit_id);
- }
- g_ptr_array_free(self->cmd_resp, TRUE);
- G_OBJECT_CLASS(test_target_parent_class)->finalize(object);
-}
-
static
void
-test_target_class_init(
- NfcTargetClass* klass)
+test_tag_reset_cb(
+ NfcTagType4* t4,
+ gboolean ok,
+ void* user_data)
{
- klass->transmit = test_target_transmit;
- klass->cancel_transmit = test_target_cancel_transmit;
- G_OBJECT_CLASS(klass)->finalize = test_target_finalize;
+ g_assert(ok);
+ g_assert(user_data);
+ ++reset_count;
+ test_tag_quit_loop_cb(&t4->tag, user_data);
}
static
void
-test_target_add_cmd(
- TestTarget* self,
- const void* cmd_bytes,
- guint cmd_len,
- const void* resp_bytes,
- guint resp_len)
+test_tag_reset_free1(
+ void* user_data)
{
- g_ptr_array_add(self->cmd_resp, test_alloc_data(cmd_bytes, cmd_len));
- g_ptr_array_add(self->cmd_resp, test_alloc_data(resp_bytes, resp_len));
+ g_assert(user_data);
+ ++reset_free_count;
}
/*==========================================================================*
@@ -360,6 +246,7 @@
g_assert(!test->reactivate_id);
if (test->fail_reactivate) {
+ GDEBUG("Failing reactivation");
return FALSE;
} else {
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/core_target/test_core_target.c
^
|
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2018-2020 Jolla Ltd.
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -40,8 +41,6 @@
static TestOpt test_opt;
-#define TEST_TIMEOUT (10) /* seconds */
-
static
void
test_quit_loop(
@@ -62,27 +61,6 @@
}
static
-gboolean
-test_timeout(
- gpointer loop)
-{
- g_assert_not_reached();
- return G_SOURCE_REMOVE;
-}
-
-static
-guint
-test_setup_timeout(
- GMainLoop* loop)
-{
- if (!(test_opt.flags & TEST_FLAG_DEBUG)) {
- return g_timeout_add_seconds(TEST_TIMEOUT, test_timeout, loop);
- } else {
- return 0;
- }
-}
-
-static
void
test_sequence_started(
NfcTarget* target,
@@ -397,9 +375,11 @@
g_assert(!nfc_target_transmit(NULL, NULL, 0, NULL, NULL, NULL, NULL));
g_assert(!nfc_target_add_gone_handler(NULL, NULL, NULL));
g_assert(!nfc_target_add_sequence_handler(NULL, NULL, NULL));
+ g_assert(!nfc_target_generate_id(NULL));
nfc_target_deactivate(NULL);
g_assert(!nfc_target_can_reactivate(NULL));
- g_assert(!nfc_target_reactivate(NULL, NULL, NULL));
+ g_assert(!nfc_target_reactivate(NULL, NULL, NULL, NULL, NULL));
+ nfc_target_set_transmit_timeout(NULL, 0);
nfc_target_set_reactivate_timeout(NULL, 0);
nfc_target_remove_handler(NULL, 0);
g_assert(!nfc_target_cancel_transmit(NULL, 0));
@@ -439,7 +419,7 @@
/* Reactivation is not supported by this target */
g_assert(!nfc_target_can_reactivate(target));
- g_assert(!nfc_target_reactivate(target, NULL, NULL));
+ g_assert(!nfc_target_reactivate(target, NULL, NULL, NULL, NULL));
nfc_target_reactivated(target); /* Does nothing */
/* Deactivate only sets the flag */
@@ -495,9 +475,13 @@
GUtilData resp1, resp2;
TestTarget* test = test_target_new();
NfcTarget* target = &test->target;
- guint timeout_id = 0, id1, id2, id3;
+ guint id1, id2, id3;
GMainLoop* loop = g_main_loop_new(NULL, TRUE);
+ if (!(test_opt.flags & TEST_FLAG_DEBUG)) {
+ nfc_target_set_transmit_timeout(target, TEST_TIMEOUT_SEC * 1000);
+ }
+
TEST_BYTES_SET(resp1, data1);
TEST_BYTES_SET(resp2, data2);
test->transmit_responses = g_slist_append(g_slist_append(
@@ -515,11 +499,7 @@
g_assert(id2);
g_assert(id3);
- timeout_id = test_setup_timeout(loop);
- g_main_loop_run(loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run(&test_opt, loop);
g_assert(test->succeeded == 2);
g_assert(!resp1.bytes);
@@ -571,9 +551,13 @@
GUtilData resp1, resp2, resp3;
TestTarget* test = test_target_new();
NfcTarget* target = &test->target;
- guint timeout_id = 0, id1, id2, id3, id4;
+ guint id1, id2, id3, id4;
GMainLoop* loop = g_main_loop_new(NULL, TRUE);
+ if (!(test_opt.flags & TEST_FLAG_DEBUG)) {
+ nfc_target_set_transmit_timeout(target, -1);
+ }
+
TEST_BYTES_SET(resp1, data1);
TEST_BYTES_SET(resp2, data2);
TEST_BYTES_SET(resp3, data3);
@@ -596,11 +580,7 @@
g_assert(id3);
g_assert(id4);
- timeout_id = test_setup_timeout(loop);
- g_main_loop_run(loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run(&test_opt, loop);
g_assert(test->succeeded == 1);
g_assert(test->failed == 2);
@@ -691,7 +671,7 @@
GUtilData resp1, resp2;
TestTarget* test = test_target_new();
NfcTarget* target = &test->target;
- guint timeout_id = 0, id1, id2;
+ guint id1, id2;
GMainLoop* loop = g_main_loop_new(NULL, TRUE);
TEST_BYTES_SET(resp1, data1);
@@ -709,11 +689,7 @@
g_assert(id2);
g_idle_add_full(G_PRIORITY_HIGH, test_transmit_destroy_quit, loop, NULL);
- timeout_id = test_setup_timeout(loop);
- g_main_loop_run(loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run(&test_opt, loop);
g_assert(!test->failed);
g_assert(resp1.bytes);
@@ -773,12 +749,13 @@
GUtilData resp1, resp2, resp3;
TestTarget* test = test_target_new();
NfcTarget* target = &test->target;
- guint timeout_id = 0, id1, id2, id3, id4;
+ guint id1, id2, id3, id4;
GMainLoop* loop = g_main_loop_new(NULL, TRUE);
NfcTargetSequence* seq;
int sequence_started = 0, sequence_finished = 0;
gulong id[2];
+ nfc_target_set_transmit_timeout(target, 0);
id[0] = nfc_target_add_sequence_handler(target,
test_sequence_started, &sequence_started);
id[1] = nfc_target_add_sequence_handler(target,
@@ -815,11 +792,7 @@
g_assert(id3);
g_assert(id4);
- timeout_id = test_setup_timeout(loop);
- g_main_loop_run(loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run(&test_opt, loop);
g_assert(sequence_started == 1);
g_assert(sequence_finished == 1);
@@ -847,7 +820,7 @@
GUtilData resp1, resp2, resp3;
TestTarget* test = test_target_new();
NfcTarget* target = &test->target;
- guint timeout_id = 0, id1, id2, id3, id4;
+ guint id1, id2, id3, id4;
GMainLoop* loop = g_main_loop_new(NULL, TRUE);
NfcTargetSequence* seq1;
NfcTargetSequence* seq2;
@@ -892,11 +865,7 @@
g_assert(id3);
g_assert(id4);
- timeout_id = test_setup_timeout(loop);
- g_main_loop_run(loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run(&test_opt, loop);
/* Two starts, one finish */
g_assert(sequence_started == 2);
@@ -925,19 +894,14 @@
/* Reactivation is supported */
g_assert(nfc_target_can_reactivate(target));
- /* Immediate reactivation failure */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/coverage/run
^
|
@@ -6,13 +6,21 @@
TESTS="\
core_adapter \
core_crc \
+core_initiator \
+core_llc \
+core_llc_param \
core_manager \
core_ndef_rec \
core_ndef_rec_sp \
core_ndef_rec_t \
core_ndef_rec_u \
+core_peer \
+core_peer_service \
+core_peer_services \
+core_peer_socket \
core_plugin \
core_plugins \
+core_snep \
core_tag \
core_tag_t2 \
core_tag_t4 \
@@ -27,8 +35,10 @@
plugins_dbus_handlers_type_text \
plugins_dbus_handlers_type_uri \
plugins_dbus_service_adapter \
+plugins_dbus_service_peer \
plugins_dbus_service_plugin \
-plugins_dbus_service_tag"
+plugins_dbus_service_tag \
+plugins_dbus_service_util"
function err() {
echo "*** ERROR!" $1
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_handlers/test_plugins_dbus_handlers.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,6 +30,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "nfc_types_p.h"
+
#include "dbus_handlers/dbus_handlers.h"
#include "test_common.h"
@@ -111,8 +113,6 @@
/* Typical start callback */
g_assert(g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON
(test->dbus_handler), server, TEST_PATH, NULL));
- g_assert(g_bus_own_name_on_connection(server, TEST_SERVICE,
- G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, test, NULL));
test->handlers = dbus_handlers_new(client, test->dir);
g_assert(test->handlers);
@@ -184,8 +184,6 @@
g_assert(g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON
(test->dbus_handler), server, TEST_PATH, NULL));
- g_assert(g_bus_own_name_on_connection(server, TEST_SERVICE,
- G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, test, NULL));
/* dbus_handlers_new will fail without config dir */
g_assert(!dbus_handlers_new(client, NULL));
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_handlers_config/test_plugins_dbus_handlers_config.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,6 +30,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "nfc_types_p.h"
+
#include "dbus_handlers/dbus_handlers.h"
#include "test_common.h"
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_handlers_type_generic/test_plugins_dbus_handlers_type_generic.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,6 +30,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "nfc_types_p.h"
+
#include "dbus_handlers/dbus_handlers.h"
#include "test_common.h"
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_handlers_type_mediatype/test_plugins_dbus_handlers_type_mediatype.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,6 +30,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "nfc_types_p.h"
+
#include "dbus_handlers/dbus_handlers.h"
#include "test_common.h"
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_handlers_type_sp/test_plugins_dbus_handlers_type_sp.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2019 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
@@ -31,6 +31,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "nfc_types_p.h"
+
#include "dbus_handlers/dbus_handlers.h"
#include "test_common.h"
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_handlers_type_text/test_plugins_dbus_handlers_type_text.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,13 +30,13 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "test_common.h"
-
-#include "nfc_system.h"
#include "nfc_util.h"
+#include "nfc_system.h"
#include "dbus_handlers/dbus_handlers.h"
+#include "test_common.h"
+
#include <glib/gstdio.h>
static TestOpt test_opt;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_handlers_type_uri/test_plugins_dbus_handlers_type_uri.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,6 +30,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "nfc_types_p.h"
+
#include "dbus_handlers/dbus_handlers.h"
#include "test_common.h"
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_service_adapter/Makefile
^
|
@@ -2,6 +2,7 @@
EXE = test_plugins_dbus_service_adapter
-COMMON_SRC = test_dbus.c test_main.c test_adapter.c test_target.c
+COMMON_SRC = test_dbus.c test_main.c test_adapter.c test_target.c \
+ test_initiator.c
include ../common/Makefile.plugins
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_service_adapter/test_plugins_dbus_service_adapter.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,21 +30,26 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "test_common.h"
-#include "test_adapter.h"
-#include "test_target.h"
-#include "test_dbus.h"
-
-#include "dbus_service/dbus_service.h"
-
-#include "internal/nfc_manager_i.h"
-#include "nfc_plugins.h"
#include "nfc_adapter_p.h"
+#include "nfc_plugins.h"
#include "nfc_adapter_impl.h"
+#include "nfc_peer.h"
+#include "nfc_initiator_impl.h"
#include "nfc_target_impl.h"
#include "nfc_tag.h"
+#include "internal/nfc_manager_i.h"
+
+#include "dbus_service/dbus_service.h"
+
+#include "test_common.h"
+#include "test_adapter.h"
+#include "test_target.h"
+#include "test_initiator.h"
+#include "test_dbus.h"
+
#define NFC_ADAPTER_INTERFACE "org.sailfishos.nfc.Adapter"
+#define NFC_ADAPTER_INTERFACE_VERSION (2)
static TestOpt test_opt;
@@ -52,6 +57,7 @@
GMainLoop* loop;
NfcManager* manager;
NfcAdapter* adapter;
+ NfcInitiator* initiator;
DBusServiceAdapter* service;
} TestData;
@@ -77,6 +83,7 @@
{
nfc_adapter_unref(test->adapter);
nfc_manager_unref(test->manager);
+ nfc_initiator_unref(test->initiator);
dbus_service_adapter_free(test->service);
g_main_loop_unref(test->loop);
}
@@ -106,6 +113,7 @@
test_null(
void)
{
+ g_assert(!dbus_service_adapter_find_peer(NULL, NULL));
dbus_service_adapter_free(NULL);
}
@@ -175,10 +183,11 @@
GDEBUG("version=%d, enabled=%d, powered=%d, modes=%0x04X, mode=0x%04X, "
"target_present=%d, %u tags", version, enabled, powered, modes, mode,
target_present, g_strv_length(tags));
- g_assert(version >= 1);
+ g_assert(version >= NFC_ADAPTER_INTERFACE_VERSION);
g_assert(enabled);
g_assert(!powered);
g_assert(!target_present);
+ g_assert(tags);
g_variant_unref(var);
g_strfreev(tags);
test_quit_later(test->loop);
@@ -211,6 +220,71 @@
}
/*==========================================================================*
+ * get_all2
+ *==========================================================================*/
+
+static
+void
+test_get_all2_done(
+ GObject* object,
+ GAsyncResult* result,
+ gpointer user_data)
+{
+ TestData* test = user_data;
+ gint version = 0;
+ gboolean enabled = FALSE, powered = TRUE, target_present = FALSE;
+ guint modes, mode;
+ gchar** tags = NULL;
+ gchar** peers = NULL;
+ GVariant* var = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object),
+ result, NULL);
+
+ g_assert(var);
+ g_variant_get(var, "(ibbuub^ao^ao)", &version, &enabled, &powered,
+ &modes, &mode, &target_present, &tags, &peers);
+ GDEBUG("version=%d, enabled=%d, powered=%d, modes=%0x04X, mode=0x%04X, "
+ "target_present=%d, %u tags, %u peers", version, enabled, powered,
+ modes, mode, target_present, g_strv_length(tags),
+ g_strv_length(peers));
+ g_assert(version >= NFC_ADAPTER_INTERFACE_VERSION);
+ g_assert(enabled);
+ g_assert(!powered);
+ g_assert(!target_present);
+ g_assert(tags);
+ g_assert(peers);
+ g_variant_unref(var);
+ g_strfreev(tags);
+ g_strfreev(peers);
+ test_quit_later(test->loop);
+}
+
+static
+void
+test_get_all2_start(
+ GDBusConnection* client,
+ GDBusConnection* server,
+ void* user_data)
+{
+ test_start_and_get((TestData*)user_data, client, server,
+ "GetAll2", test_get_all2_done);
+}
+
+static
+void
+test_get_all2(
+ void)
+{
+ TestData test;
+ TestDBus* dbus;
+
+ test_data_init(&test);
+ dbus = test_dbus_new(test_get_all2_start, &test);
+ test_run(&test_opt, test.loop);
+ test_data_cleanup(&test);
+ test_dbus_free(dbus);
+}
+
+/*==========================================================================*
* get_interface_version
*==========================================================================*/
@@ -550,7 +624,7 @@
g_assert(test->service);
/* Add second tag after creating DBusServiceAdapter */
- target = test_target_new();
+ target = test_target_new(FALSE);
memset(&poll, 0, sizeof(poll));
g_assert(nfc_adapter_add_other_tag2(test->adapter, target, &poll));
nfc_target_unref(target);
@@ -574,7 +648,7 @@
test_data_init(&test);
/* Add one tag before creating DBusServiceAdapter */
- target = test_target_new();
+ target = test_target_new(FALSE);
memset(&poll, 0, sizeof(poll));
g_assert(nfc_adapter_add_other_tag2(test.adapter, target, &poll));
nfc_target_unref(target);
@@ -586,6 +660,65 @@
}
/*==========================================================================*
+ * get_peers
+ *==========================================================================*/
+
+static
+void
+test_get_peers_done(
+ GObject* object,
+ GAsyncResult* result,
+ gpointer user_data)
+{
+ TestData* test = user_data;
+ gchar** peers = NULL;
+ GVariant* var = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object),
+ result, NULL);
+
+ g_assert(var);
+ g_variant_get(var, "(^ao)", &peers);
+ g_assert(peers);
+ GDEBUG("%u peer(s)", g_strv_length(peers));
+ g_variant_unref(var);
+ g_strfreev(peers);
+ test_quit_later_n(test->loop, 100); /* Allow everything to complete */
+}
+
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_service_peer/Makefile
^
|
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_plugins_dbus_service_peer
+
+COMMON_SRC = test_dbus.c test_main.c test_adapter.c test_initiator.c
+
+include ../common/Makefile.plugins
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_service_peer/test_plugins_dbus_service_peer.c
^
|
@@ -0,0 +1,562 @@
+/*
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nfc_types_p.h"
+#include "nfc_adapter.h"
+#include "nfc_initiator.h"
+#include "nfc_plugins.h"
+#include "nfc_peer.h"
+#include "nfc_peer_service.h"
+#include "internal/nfc_manager_i.h"
+
+#include "dbus_service/dbus_service.h"
+
+#include "test_common.h"
+#include "test_adapter.h"
+#include "test_initiator.h"
+#include "test_dbus.h"
+
+#define NFC_PEER_INTERFACE "org.sailfishos.nfc.Peer"
+#define NFC_PEER_INTERFACE_VERSION (1)
+#define NFC_PEER_DEFAULT_WKS \
+ ((1 << NFC_LLC_SAP_SDP) | \
+ (1 << NFC_LLC_SAP_SNEP) | \
+ 0x01)
+
+static TestOpt test_opt;
+
+typedef struct test_data {
+ GMainLoop* loop;
+ NfcManager* manager;
+ NfcAdapter* adapter;
+ NfcPeer* peer;
+ DBusServicePeer* service;
+} TestData;
+
+static
+void
+test_data_init(
+ TestData* test)
+{
+ static const guint8 atr_req_general_bytes [] = {
+ 0x46, 0x66, 0x6d, 0x01, 0x01, 0x11, 0x02, 0x02,
+ 0x07, 0xff, 0x03, 0x02, 0x00, 0x13, 0x04, 0x01,
+ 0xff
+ };
+ static const NfcParamNfcDepTarget peer_target_param = {
+ { TEST_ARRAY_AND_SIZE(atr_req_general_bytes) }
+ };
+ static const guint8 symm_data[] = { 0x00, 0x00 };
+ static const TestTx tx[] = {
+ {
+ { TEST_ARRAY_AND_SIZE(symm_data) },
+ { TEST_ARRAY_AND_SIZE(symm_data) }
+ }
+ };
+ NfcPluginsInfo pi;
+ NfcInitiator* initiator;
+
+ memset(test, 0, sizeof(*test));
+ memset(&pi, 0, sizeof(pi));
+ g_assert((test->manager = nfc_manager_new(&pi)) != NULL);
+ g_assert((test->adapter = test_adapter_new()) != NULL);
+ g_assert(nfc_manager_add_adapter(test->manager, test->adapter));
+ initiator = test_initiator_new_with_tx2(TEST_ARRAY_AND_COUNT(tx), TRUE);
+ test->peer = nfc_peer_ref(nfc_adapter_add_peer_target_a(test->adapter,
+ initiator, NULL, &peer_target_param));
+ g_assert(test->peer);
+ nfc_initiator_unref(initiator);
+ test->loop = g_main_loop_new(NULL, TRUE);
+}
+
+static
+void
+test_data_cleanup(
+ TestData* test)
+{
+ dbus_service_peer_free(test->service);
+ nfc_peer_unref(test->peer);
+ nfc_adapter_unref(test->adapter);
+ nfc_manager_unref(test->manager);
+ g_main_loop_unref(test->loop);
+}
+
+static
+void
+test_start_and_get(
+ TestData* test,
+ GDBusConnection* client,
+ GDBusConnection* server,
+ const char* method,
+ GAsyncReadyCallback callback)
+{
+ test->service = dbus_service_peer_new(test->peer, "/nfc0", server);
+ g_assert(test->service);
+ g_dbus_connection_call(client, NULL, test->service->path,
+ NFC_PEER_INTERFACE, method, NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, callback, test);
+}
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null(
+ void)
+{
+ dbus_service_peer_free(NULL);
+}
+
+/*==========================================================================*
+ * get_all
+ *==========================================================================*/
+
+static
+void
+test_get_all_done(
+ GObject* object,
+ GAsyncResult* result,
+ gpointer user_data)
+{
+ TestData* test = user_data;
+ gint version = 0;
+ gboolean present = FALSE;
+ gchar** ifaces = NULL;
+ guint tech, wks;
+ GVariant* var = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object),
+ result, NULL);
+
+ g_assert(var);
+ g_variant_get(var, "(ibu^asu)", &version, &present, &tech, &ifaces, &wks);
+ GDEBUG("version=%d, present=%d, tech=%u, %u interface(s), wks=0x%02x",
+ version, present, tech, g_strv_length(ifaces), wks);
+ g_assert(version >= NFC_PEER_INTERFACE_VERSION);
+ g_assert(present);
+ g_assert_cmpuint(g_strv_length(ifaces), > ,0);
+ g_assert_cmpstr(ifaces[0], == ,NFC_PEER_INTERFACE);
+ g_assert_cmpuint(tech, == ,NFC_TECHNOLOGY_A);
+ g_assert_cmpuint(wks, == ,NFC_PEER_DEFAULT_WKS);
+ g_strfreev(ifaces);
+ g_variant_unref(var);
+ test_quit_later(test->loop);
+}
+
+static
+void
+test_get_all_start(
+ GDBusConnection* client,
+ GDBusConnection* server,
+ void* user_data)
+{
+ TestData* test = user_data;
+
+ test_start_and_get(test, client, server, "GetAll", test_get_all_done);
+}
+
+static
+void
+test_get_all(
+ void)
+{
+ TestData test;
+ TestDBus* dbus;
+
+ test_data_init(&test);
+ dbus = test_dbus_new(test_get_all_start, &test);
+ test_run(&test_opt, test.loop);
+ test_data_cleanup(&test);
+ test_dbus_free(dbus);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_service_plugin/Makefile
^
|
@@ -4,4 +4,6 @@
COMMON_SRC = test_dbus.c test_main.c test_adapter.c test_target.c
+EXTRA_EXE_LDFLAGS = -u nfc_core_version
+
include ../common/Makefile.plugins
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_service_plugin/test_plugins_dbus_service_plugin.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,32 +30,39 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "test_common.h"
-#include "test_adapter.h"
-#include "test_dbus.h"
+#include "nfc_types_p.h"
+#include "internal/nfc_manager_i.h"
+#include "nfc_adapter.h"
+#include "nfc_version.h"
#include "dbus_service/dbus_service.h"
#include "dbus_service/plugin.h"
-#include "internal/nfc_manager_i.h"
-#include "nfc_adapter.h"
-#include "nfc_version.h"
+#include "test_common.h"
+#include "test_adapter.h"
+#include "test_dbus.h"
+#define NFC_DAEMON_PATH "/"
#define NFC_DAEMON_INTERFACE "org.sailfishos.nfc.Daemon"
+#define NFC_DAEMON_INTERFACE_VERSION (3)
static TestOpt test_opt;
static GDBusConnection* test_server;
+static DBusServicePlugin* test_plugin;
+static const char* dbus_sender = ":1.0";
typedef struct test_data {
GMainLoop* loop;
NfcManager* manager;
NfcAdapter* adapter;
+ GDBusConnection* client; /* Owned by TestDBus */
} TestData;
static
void
-test_data_init(
- TestData* test)
+test_data_init2(
+ TestData* test,
+ gboolean add_adapter)
{
NfcPluginsInfo pi;
static const NfcPluginDesc* const test_builtin_plugins[] = {
@@ -68,12 +75,22 @@
pi.builtins = test_builtin_plugins;
g_assert((test->manager = nfc_manager_new(&pi)) != NULL);
g_assert((test->adapter = test_adapter_new()) != NULL);
- g_assert(nfc_manager_add_adapter(test->manager, test->adapter));
+ if (add_adapter) {
+ g_assert(nfc_manager_add_adapter(test->manager, test->adapter));
+ }
test->loop = g_main_loop_new(NULL, TRUE);
}
static
void
+test_data_init(
+ TestData* test)
+{
+ test_data_init2(test, TRUE);
+}
+
+static
+void
test_data_cleanup(
TestData* test)
{
@@ -104,15 +121,43 @@
const char* method,
GAsyncReadyCallback callback)
{
- g_dbus_connection_call(client, NULL, "/", NFC_DAEMON_INTERFACE,
+ g_dbus_connection_call(client, NULL, NFC_DAEMON_PATH, NFC_DAEMON_INTERFACE,
method, NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, callback, test);
}
+static
+void
+test_call_register_local_service(
+ GDBusConnection* client,
+ const char* path,
+ const char* name,
+ GAsyncReadyCallback callback,
+ TestData* test)
+{
+ g_dbus_connection_call(client, NULL, NFC_DAEMON_PATH, NFC_DAEMON_INTERFACE,
+ "RegisterLocalService", g_variant_new ("(os)", path, name), NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, callback, test);
+}
+
+static
+void
+test_call_unregister_local_service(
+ GDBusConnection* client,
+ const char* path,
+ GAsyncReadyCallback callback,
+ TestData* test)
+{
+ g_dbus_connection_call(client, NULL, NFC_DAEMON_PATH, NFC_DAEMON_INTERFACE,
+ "UnregisterLocalService", g_variant_new ("(o)", path), NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, callback, test);
+}
+
/*==========================================================================*
* Stubs
*==========================================================================*/
#define TEST_NAME_OWN_ID (1)
+#define TEST_NAME_WATCH_ID (2)
typedef struct test_bus_acquired_data {
char* name;
@@ -140,6 +185,7 @@
{
TestBusAcquiredData* data = user_data;
+ g_assert(data->plugin == test_plugin);
g_free(data->name);
g_free(data);
}
@@ -154,7 +200,7 @@
{
TestBusAcquiredData* data = g_new(TestBusAcquiredData, 1);
- data->plugin = plugin;
+ data->plugin = test_plugin = plugin;
data->name = g_strdup(name);
data->bus_acquired = bus_acquired;
data->name_acquired = name_acquired;
@@ -167,9 +213,73 @@
dbus_service_name_unown(
guint id)
{
+ g_assert(test_plugin);
+ test_plugin = NULL;
g_assert(id == TEST_NAME_OWN_ID);
}
+const gchar*
+g_dbus_method_invocation_get_sender(
+ GDBusMethodInvocation* call)
+{
+ return dbus_sender;
+}
+
+guint
+g_bus_watch_name_on_connection(
+ GDBusConnection* connection,
+ const gchar* name,
+ GBusNameWatcherFlags flags,
+ GBusNameAppearedCallback name_appeared_handler,
+ GBusNameVanishedCallback name_vanished_handler,
+ gpointer user_data,
+ GDestroyNotify user_data_free_func)
+{
+ g_assert_cmpstr(name, == ,dbus_sender);
+ return TEST_NAME_WATCH_ID;
+}
+
+void
+g_bus_unwatch_name(
+ guint watcher_id)
+{
+ g_assert_cmpuint(watcher_id, == ,TEST_NAME_WATCH_ID);
+}
+
+/*==========================================================================*
+ * no_peers
+ *==========================================================================*/
+
+static
+void
+test_no_peers_start(
+ GDBusConnection* client,
+ GDBusConnection* server,
+ void* user_data)
+{
+ TestData* test = user_data;
+
+ g_assert(test_plugin);
+ g_assert(!dbus_service_plugin_find_peer(test_plugin, NULL));
+ test_quit_later(test->loop);
+}
+
+static
+void
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_service_tag/test_plugins_dbus_service_tag.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,24 +31,27 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "nfc_adapter_p.h"
+#include "nfc_target_p.h"
+#include "nfc_tag_p.h"
+#include "nfc_plugins.h"
+#include "nfc_ndef.h"
+
+#include "internal/nfc_manager_i.h"
+
+#include "dbus_service/dbus_service.h"
+#include "dbus_service/dbus_service_util.h"
+
#include "test_common.h"
#include "test_adapter.h"
#include "test_target.h"
#include "test_dbus.h"
-#include "dbus_service/dbus_service.h"
-
-#include "internal/nfc_manager_i.h"
-#include "nfc_plugins.h"
-#include "nfc_adapter_p.h"
-#include "nfc_target_p.h"
-#include "nfc_tag_p.h"
-
#include <gutil_idlepool.h>
#define NFC_SERVICE "org.sailfishos.nfc.daemon"
#define NFC_TAG_INTERFACE "org.sailfishos.nfc.Tag"
-#define MIN_INTERFACE_VERSION (2)
+#define MIN_INTERFACE_VERSION (4)
static TestOpt test_opt;
static const char test_sender_1[] = ":1.1";
@@ -80,7 +84,7 @@
g_assert((test->manager = nfc_manager_new(&pi)) != NULL);
g_assert((test->adapter = test_adapter_new()) != NULL);
- target = test_target_new();
+ target = test_target_new(FALSE);
memset(&poll, 0, sizeof(poll));
g_assert(nfc_adapter_add_other_tag2(test->adapter, target, &poll));
nfc_target_unref(target);
@@ -167,11 +171,12 @@
static
void
test_complete_ok(
- GDBusConnection* connection,
+ GObject* conn,
GAsyncResult* result)
{
GError* error = NULL;
- GVariant* out = g_dbus_connection_call_finish(connection, result, &error);
+ GVariant* out = g_dbus_connection_call_finish(G_DBUS_CONNECTION(conn),
+ result, &error);
g_assert(out);
g_variant_unref(out);
@@ -179,17 +184,34 @@
static
void
+test_get_interface_version_complete_ok(
+ GObject* conn,
+ GAsyncResult* result)
+{
+ gint version = 0;
+ GVariant* var = g_dbus_connection_call_finish(G_DBUS_CONNECTION(conn),
+ result, NULL);
+
+ g_assert(var);
+ g_variant_get(var, "(i)", &version);
+ GDEBUG("version=%d", version);
+ g_assert(version >= MIN_INTERFACE_VERSION);
+ g_variant_unref(var);
+}
+
+static
+void
test_complete_error(
- GDBusConnection* connection,
+ GObject* connection,
GAsyncResult* result,
DBusServiceError code)
{
GError* error = NULL;
- /* This call is expected to fail with org.sailfishos.nfc.Error.Aborted */
- g_assert(!g_dbus_connection_call_finish(connection, result, &error));
- g_assert(error->domain == DBUS_SERVICE_ERROR);
- g_assert(error->code == code);
+ /* This call is expected to fail */
+ g_assert(!g_dbus_connection_call_finish(G_DBUS_CONNECTION(connection),
+ result, &error));
+ g_assert_error(error, DBUS_SERVICE_ERROR, code);
g_error_free(error);
}
@@ -331,7 +353,6 @@
void)
{
dbus_service_tag_free(NULL);
- g_assert(!dbus_service_tag_sequence(NULL, NULL));
}
/*==========================================================================*
@@ -452,20 +473,13 @@
static
void
test_get_interface_version_done(
- GObject* object,
+ GObject* connection,
GAsyncResult* result,
gpointer user_data)
{
TestData* test = user_data;
- gint version = 0;
- GVariant* var = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object),
- result, NULL);
- g_assert(var);
- g_variant_get(var, "(i)", &version);
- GDEBUG("version=%d", version);
- g_assert(version >= MIN_INTERFACE_VERSION);
- g_variant_unref(var);
+ test_get_interface_version_complete_ok(connection, result);
test_quit_later(test->loop);
}
@@ -750,12 +764,12 @@
}
/*==========================================================================*
- * get_records
+ * get_ndef_records0
*==========================================================================*/
static
void
-test_get_records_done(
+test_get_ndef_records0_done(
GObject* object,
GAsyncResult* result,
gpointer user_data)
@@ -777,7 +791,7 @@
static
void
-test_get_records_start(
+test_get_ndef_records0_start(
GDBusConnection* client,
GDBusConnection* server,
void* user_data)
@@ -786,19 +800,76 @@
nfc_tag_set_initialized(test->adapter->tags[0]);
test_start_and_get(test, client, server,
- "GetNdefRecords", test_get_records_done);
+ "GetNdefRecords", test_get_ndef_records0_done);
+}
+
+static
+void
+test_get_ndef_records0(
+ void)
+{
+ TestData test;
+ TestDBus* dbus;
+
+ test_data_init(&test);
+ dbus = test_dbus_new(test_get_ndef_records0_start, &test);
+ test_run(&test_opt, test.loop);
+ test_data_cleanup(&test);
+ test_dbus_free(dbus);
+}
+
+/*==========================================================================*
+ * get_ndef_records1
+ *==========================================================================*/
+
+static
+void
+test_get_ndef_records1_done(
+ GObject* object,
+ GAsyncResult* result,
+ gpointer user_data)
+{
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_service_util/Makefile
^
|
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_plugins_dbus_service_util
+
+COMMON_SRC = test_main.c
+
+include ../common/Makefile.plugins
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.1.2.tar.bz2/unit/plugins_dbus_service_util/test_plugins_dbus_service_util.c
^
|
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_common.h"
+#include "dbus_service/dbus_service_util.h"
+
+static TestOpt test_opt;
+
+/*==========================================================================*
+ * byte_array
+ *==========================================================================*/
+
+static
+void
+test_byte_array(
+ void)
+{
+ static const guint8 value = 42;
+ static const GUtilData data = { &value, sizeof(value) };
+ GVariant* var = dbus_service_dup_byte_array_as_variant(NULL, 0);
+
+ /* Empty variant */
+ g_assert(var);
+ g_assert_cmpstr(g_variant_get_type_string(var), == ,"ay");
+ g_assert(!g_variant_get_size(var));
+ g_variant_unref(g_variant_take_ref(var));
+
+ var = dbus_service_dup_byte_array_data_as_variant(NULL);
+ g_assert(var);
+ g_assert_cmpstr(g_variant_get_type_string(var), == ,"ay");
+ g_assert(!g_variant_get_size(var));
+ g_variant_unref(g_variant_take_ref(var));
+
+ /* Variant containing some data */
+ var = dbus_service_dup_byte_array_data_as_variant(&data);
+ g_assert_cmpstr(g_variant_get_type_string(var), == ,"ay");
+ g_assert_cmpuint(g_variant_get_size(var), == ,data.size);
+ g_assert(!memcmp(g_variant_get_data(var), data.bytes, data.size));
+ g_variant_unref(g_variant_take_ref(var));
+}
+
+/*==========================================================================*
+ * dict
+ *==========================================================================*/
+
+static
+void
+test_dict_check_data(
+ GVariant* var,
+ const char* name,
+ const GUtilData* data)
+{
+ guint8 y = 0;
+ GVariantIter* it = NULL;
+ const guint8* bytes = data->bytes;
+ guint i;
+
+ g_assert_cmpuint(g_variant_n_children(var), == ,1);
+ g_assert(g_variant_lookup(var, name, "ay", &it));
+ for (i = 0; g_variant_iter_loop(it, "y", &y); i++) {
+ g_assert_cmpuint(y, == ,bytes[i]);
+ }
+ g_assert_cmpuint(i, == ,data->size);
+ g_variant_iter_free(it);
+ g_variant_unref(g_variant_ref_sink(var));
+}
+
+static
+void
+test_dict(
+ void)
+{
+ static const char name[] = "value";
+ static const guint8 value = 42;
+ static const GUtilData data = { &value, sizeof(value) };
+ guint8 y = 0;
+ GVariantBuilder builder;
+ GVariant* var;
+
+ /* Byte */
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
+ dbus_service_dict_add_byte(&builder, name, value);
+ var = g_variant_builder_end(&builder);
+ g_assert_cmpuint(g_variant_n_children(var), == ,1);
+ g_assert(g_variant_lookup(var, name, "y", &y));
+ g_assert_cmpuint(y, == ,value);
+ g_variant_unref(g_variant_take_ref(var));
+
+ /* Byte array */
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
+ dbus_service_dict_add_byte_array(&builder, name, data.bytes, data.size);
+ test_dict_check_data(g_variant_builder_end(&builder), name, &data);
+
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
+ dbus_service_dict_add_byte_array_data(&builder, name, &data);
+ test_dict_check_data(g_variant_builder_end(&builder), name, &data);
+}
+
+/*==========================================================================*
+ * Common
+ *==========================================================================*/
+
+#define TEST_(name) "/plugins/dbus_service/util/" name
+
+int main(int argc, char* argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+ g_test_add_func(TEST_("byte_array"), test_byte_array);
+ g_test_add_func(TEST_("dict"), test_dict);
+ test_init(&test_opt, argc, argv);
+ return g_test_run();
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|