[-]
[+]
|
Changed |
_service:tar_git:nfcd.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd.spec
^
|
|
[-]
[+]
|
Deleted |
_service:tar_git:nfcd-1.0.30.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.30.tar.bz2/plugins/dbus_log/dbus_log_plugin.c
^
|
@@ -1,391 +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.
- */
-
-#include "plugin.h"
-
-#include <nfc_manager.h>
-#include <nfc_plugin_impl.h>
-
-#include <dbuslog_server_gio.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
-DBUSLOG_LEVEL
-dbus_log_plugin_convert_to_dbus_level(
- int level)
-{
- switch (level) {
- case GLOG_LEVEL_ALWAYS:
- return DBUSLOG_LEVEL_ALWAYS;
- case GLOG_LEVEL_ERR:
- return DBUSLOG_LEVEL_ERROR;
- case GLOG_LEVEL_WARN:
- return DBUSLOG_LEVEL_WARNING;
- case GLOG_LEVEL_INFO:
- return DBUSLOG_LEVEL_INFO;
- case GLOG_LEVEL_DEBUG:
- return DBUSLOG_LEVEL_DEBUG;
- case GLOG_LEVEL_VERBOSE:
- return DBUSLOG_LEVEL_VERBOSE;
- default:
- return DBUSLOG_LEVEL_UNDEFINED;
- }
-}
-
-static
-int
-dbus_log_plugin_convert_from_dbus_level(
- DBUSLOG_LEVEL level)
-{
- switch (level) {
- case DBUSLOG_LEVEL_ALWAYS:
- return GLOG_LEVEL_ALWAYS;
- case DBUSLOG_LEVEL_ERROR:
- return GLOG_LEVEL_ERR;
- case DBUSLOG_LEVEL_WARNING:
- return GLOG_LEVEL_WARN;
- case DBUSLOG_LEVEL_INFO:
- return GLOG_LEVEL_INFO;
- case DBUSLOG_LEVEL_DEBUG:
- return GLOG_LEVEL_DEBUG;
- case DBUSLOG_LEVEL_VERBOSE:
- return GLOG_LEVEL_VERBOSE;
- default:
- return GLOG_LEVEL_NONE;
- }
-}
-
-static
-void
-dbus_log_plugin_func(
- DBusLogPlugin* self,
- const GLogModule* log,
- int level,
- const char* format,
- va_list va)
-{
- dbus_log_server_logv(self->logserver,
- dbus_log_plugin_convert_to_dbus_level(level), log->name, format, va);
- 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_plugin_convert_to_dbus_level(log->level), flags);
-}
-
-/*==========================================================================*
- * Events
|
[-]
[+]
|
Deleted |
_service:tar_git:nfcd-1.0.30.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.0.47.tar.bz2/Makefile
^
|
@@ -7,6 +7,9 @@
test:
@$(MAKE) -C unit $@
+pkgconfig:
+ @$(MAKE) -C core $@
+
install:
@$(MAKE) -C src $@
@$(MAKE) -C core $@
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/Makefile
^
|
@@ -1,6 +1,6 @@
# -*- Mode: makefile-gmake -*-
-.PHONY: clean all debug release
+.PHONY: clean all debug release pkgconfig
.PHONY: print_debug_lib print_release_lib
.PHONY: print_debug_path print_release_path
@@ -89,10 +89,7 @@
RELEASE_FLAGS =
COVERAGE_FLAGS = -g
-ifndef KEEP_SYMBOLS
-KEEP_SYMBOLS = 0
-endif
-
+KEEP_SYMBOLS ?= 0
ifneq ($(KEEP_SYMBOLS),0)
RELEASE_FLAGS += -g
endif
@@ -147,6 +144,8 @@
coverage_lib: $(COVERAGE_LIB)
+pkgconfig: $(PKGCONFIG)
+
clean:
rm -f *~ $(SRC_DIR)/*~ $(INCLUDE_DIR)/*~ $(INCLUDE_DIR)/internal/*~
rm -fr $(BUILD_DIR)
@@ -185,21 +184,25 @@
ranlib $@
$(PKGCONFIG): $(PKGCONFIG_TEMPLATE) $(VERSION_FILE)
- sed -e "s/\[version\]/$(PCVERSION)/g" $(PKGCONFIG_TEMPLATE) > $@
+ sed -e 's|@version@|$(PCVERSION)|g' $(PKGCONFIG_TEMPLATE) > $@
#
# Install
#
+LIBDIR ?= usr/lib
+ABS_LIBDIR := $(shell echo /$(LIBDIR) | sed -r 's|/+|/|g')
+
INSTALL = install
INSTALL_DIRS = $(INSTALL) -d
+INSTALL_FILES = $(INSTALL) -m 644
INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/nfcd
-INSTALL_PKGCONFIG_DIR = $(DESTDIR)/usr/lib/pkgconfig
+INSTALL_PKGCONFIG_DIR = $(DESTDIR)$(ABS_LIBDIR)/pkgconfig
-install: $(INSTALL_INCLUDE_DIR) $(INSTALL_PKGCONFIG_DIR) $(PKGCONFIG)
- $(INSTALL) -m 644 $(INCLUDE_DIR)/*.h $(INSTALL_INCLUDE_DIR)
- $(INSTALL) -m 644 $(PKGCONFIG) $(INSTALL_PKGCONFIG_DIR)
+install: $(INSTALL_INCLUDE_DIR) $(INSTALL_PKGCONFIG_DIR)
+ $(INSTALL_FILES) $(INCLUDE_DIR)/*.h $(INSTALL_INCLUDE_DIR)
+ $(INSTALL_FILES) $(PKGCONFIG) $(INSTALL_PKGCONFIG_DIR)
$(INSTALL_INCLUDE_DIR):
$(INSTALL_DIRS) $@
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/include/internal/nfc_manager_i.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018 Jolla Ltd.
- * Copyright (C) 2018 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:
*
@@ -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,17 +37,15 @@
#include "nfc_types_i.h"
-/* Add _ prefix so that they don't get exported */
-#define nfc_manager_new _nfc_manager_new
-#define nfc_manager_start _nfc_manager_start
-
NfcManager*
nfc_manager_new(
- const NfcPluginsInfo* info);
+ const NfcPluginsInfo* info)
+ G_GNUC_INTERNAL;
gboolean
nfc_manager_start(
- NfcManager* manager);
+ NfcManager* manager)
+ G_GNUC_INTERNAL;
#endif /* NFC_MANAGER_INTERNAL_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/include/nfc_adapter.h
^
|
@@ -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:
*
@@ -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
@@ -108,20 +108,27 @@
nfc_adapter_add_tag_t4a(
NfcAdapter* adapter,
NfcTarget* target,
- const NfcParamPollA* tech_param,
+ const NfcParamPollA* poll_a,
const NfcParamIsoDepPollA* iso_dep_param); /* Since 1.0.20 */
NfcTag*
nfc_adapter_add_tag_t4b(
NfcAdapter* adapter,
NfcTarget* target,
- const NfcParamPollB* tech_param,
+ const NfcParamPollB* poll_b,
const NfcParamIsoDepPollB* iso_dep_param); /* Since 1.0.20 */
NfcTag*
nfc_adapter_add_other_tag(
NfcAdapter* adapter,
- NfcTarget* target);
+ NfcTarget* target)
+ G_GNUC_DEPRECATED_FOR(nfc_adapter_add_other_tag2);
+
+NfcTag*
+nfc_adapter_add_other_tag2(
+ NfcAdapter* adapter,
+ NfcTarget* target,
+ const NfcParamPoll* poll); /* Since 1.0.33 */
void
nfc_adapter_remove_tag(
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/include/nfc_tag.h
^
|
@@ -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:
*
@@ -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
@@ -62,16 +62,6 @@
#define NFC_TAG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_TAG, NfcTag))
-struct nfc_param_poll_a {
- guint8 sel_res; /* (SAK)*/
- GUtilData nfcid1;
-};
-
-struct nfc_param_poll_b {
- guint fsc; /* FSC (FSCI converted to bytes) */
- GUtilData nfcid0;
-};
-
typedef
void
(*NfcTagFunc)(
@@ -86,6 +76,10 @@
nfc_tag_unref(
NfcTag* tag);
+const NfcParamPoll*
+nfc_tag_param(
+ NfcTag* tag); /* Since 1.0.33 */
+
void
nfc_tag_deactivate(
NfcTag* tag);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -54,7 +55,7 @@
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();
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -42,15 +43,13 @@
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;
-};
-
-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 */
+ const NfcParamIsoDep* iso_dep;
};
GType nfc_tag_t4_get_type();
@@ -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,
@@ -106,6 +147,14 @@
GDestroyNotify destroy,
void* user_data);
+gboolean
+nfc_isodep_reset(
+ NfcTagType4* tag,
+ NfcTargetSequence* seq,
+ NfcTagType4ResetRespFunc resp,
+ GDestroyNotify destroy,
+ void* user_data); /* Since 1.0.44 */
+
G_END_DECLS
#endif /* NFC_TAG_T4_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/include/nfc_target.h
^
|
@@ -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:
*
@@ -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
@@ -71,6 +71,33 @@
NfcTarget* target,
void* user_data);
+typedef
+void
+(*NfcTargetTransmitFunc)(
+ NfcTarget* target,
+ NFC_TRANSMIT_STATUS status,
+ const void* data,
+ guint len,
+ void* user_data);
+
+NfcTarget*
+nfc_target_ref(
+ NfcTarget* target);
+
+void
+nfc_target_unref(
+ NfcTarget* target);
+
+/*
+ * -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 */
+
gulong
nfc_target_add_sequence_handler(
NfcTarget* target,
@@ -107,6 +134,26 @@
nfc_target_sequence_free(
NfcTargetSequence* seq); /* Since 1.0.17 */
+/*
+ * These functions can be used for sending internal requests (e.g. presence
+ * check) to take advantage of queueing provided by NfcTarget:
+ */
+
+guint
+nfc_target_transmit(
+ NfcTarget* target,
+ const void* data,
+ guint len,
+ NfcTargetSequence* seq,
+ NfcTargetTransmitFunc complete,
+ GDestroyNotify destroy,
+ void* user_data);
+
+gboolean
+nfc_target_cancel_transmit(
+ NfcTarget* target,
+ guint id);
+
G_END_DECLS
#endif /* NFC_TARGET_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/include/nfc_target_impl.h
^
|
@@ -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
@@ -78,23 +78,6 @@
#define NFC_TARGET_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
NFC_TYPE_TARGET, NfcTargetClass)
-typedef
-void
-(*NfcTargetTransmitFunc)(
- NfcTarget* target,
- NFC_TRANSMIT_STATUS status,
- const void* data,
- guint len,
- void* user_data);
-
-NfcTarget*
-nfc_target_ref(
- NfcTarget* target);
-
-void
-nfc_target_unref(
- NfcTarget* target);
-
void
nfc_target_transmit_done(
NfcTarget* target,
@@ -110,26 +93,6 @@
nfc_target_gone(
NfcTarget* target);
-/*
- * These functions can be used for sending internal requests (e.g. presence
- * check) to take advantage of queueing provided by NfcTarget:
- */
-
-guint
-nfc_target_transmit(
- NfcTarget* target,
- const void* data,
- guint len,
- NfcTargetSequence* seq,
- NfcTargetTransmitFunc complete,
- GDestroyNotify destroy,
- void* user_data);
-
-gboolean
-nfc_target_cancel_transmit(
- NfcTarget* target,
- guint id);
-
G_END_DECLS
#endif /* NFC_TARGET_IMPL_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/include/nfc_types.h
^
|
@@ -1,6 +1,7 @@
/*
- * 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>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -53,11 +54,8 @@
typedef struct nfc_target NfcTarget;
typedef struct nfc_target_sequence NfcTargetSequence;
-typedef struct nfc_param_poll_a NfcParamPollA; /* Since 1.0.8 */
-typedef struct nfc_param_poll_b NfcParamPollB; /* Since 1.0.20 */
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 NfcParamPollA NfcTagParamT2; /* For backward compatibility */
/* Constants */
@@ -103,6 +101,31 @@
NFC_TRANSMIT_STATUS_TIMEOUT /* No response from NFCC */
} NFC_TRANSMIT_STATUS;
+/* RF technology specific parameters */
+
+typedef struct nfc_param_poll_a {
+ guint8 sel_res; /* (SAK)*/
+ GUtilData nfcid1;
+} NfcParamPollA, /* Since 1.0.8 */
+ NfcTagParamT2; /* This one for backward compatibility */
+
+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 union nfc_param_poll {
+ NfcParamPollA a;
+ NfcParamPollB b;
+} NfcParamPoll; /* Since 1.0.33 */
+
/* Logging */
#define NFC_CORE_LOG_MODULE nfc_core_log
extern GLogModule NFC_CORE_LOG_MODULE;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/include/nfc_version.h
^
|
@@ -35,7 +35,7 @@
#define NFC_VERSION_MAJOR 1
#define NFC_VERSION_MINOR 0
-#define NFC_VERSION_NANO 30
+#define NFC_VERSION_NANO 47
#define NFC_VERSION_WORD(v1,v2,v3) \
((((v1) & 0x7f) << 24) | \
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/nfcd-plugin.pc.in
^
|
@@ -3,6 +3,6 @@
Name: ${name}
Description: Header files for building ${name} plugins
-Version: [version]
+Version: @version@
Requires: glib-2.0
Cflags: -I${includedir} -I${includedir}/${name}
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/src/nfc_adapter.c
^
|
@@ -32,6 +32,7 @@
#define GLIB_DISABLE_DEPRECATION_WARNINGS
+#include "nfc_adapter_impl.h"
#include "nfc_adapter_p.h"
#include "nfc_tag_p.h"
#include "nfc_tag_t4_p.h"
@@ -445,8 +446,17 @@
NfcAdapter* self,
NfcTarget* target)
{
+ return nfc_adapter_add_other_tag2(self, target, NULL);
+}
+
+NfcTag*
+nfc_adapter_add_other_tag2(
+ NfcAdapter* self,
+ NfcTarget* target,
+ const NfcParamPoll* poll) /* Since 1.0.33 */
+{
if (G_LIKELY(self)) {
- NfcTag* tag = nfc_tag_new(target);
+ NfcTag* tag = nfc_tag_new(target, poll);
if (tag) {
return nfc_adapter_add_tag(self, tag);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/src/nfc_adapter_p.h
^
|
@@ -35,7 +35,7 @@
#include "nfc_types_p.h"
-#include <nfc_adapter_impl.h>
+#include <nfc_adapter.h>
void
nfc_adapter_set_name(
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/src/nfc_manager.c
^
|
@@ -49,6 +49,8 @@
NfcPlugins* plugins;
GHashTable* adapters;
guint next_adapter_index;
+ gboolean requested_power;
+ NFC_MODE requested_mode;
};
typedef GObjectClass NfcManagerClass;
@@ -211,6 +213,8 @@
nfc_adapter_set_name(adapter, name);
nfc_adapter_set_enabled(adapter, self->enabled);
+ nfc_adapter_request_mode(adapter, priv->requested_mode);
+ nfc_adapter_request_power(adapter, priv->requested_power);
g_hash_table_insert(priv->adapters, name, nfc_adapter_ref(adapter));
g_free(self->adapters);
self->adapters = nfc_manager_adapters(priv);
@@ -271,8 +275,10 @@
gboolean on)
{
if (G_LIKELY(self)) {
+ NfcManagerPriv* priv = self->priv;
NfcAdapter** adapters = nfc_manager_ref_adapters(self->priv);
+ priv->requested_power = on;
if (adapters) {
NfcAdapter** ptr = adapters;
@@ -290,8 +296,10 @@
NFC_MODE mode)
{
if (G_LIKELY(self)) {
+ NfcManagerPriv* priv = self->priv;
NfcAdapter** adapters = nfc_manager_ref_adapters(self->priv);
+ priv->requested_mode = mode;
if (adapters) {
NfcAdapter** ptr = adapters;
@@ -425,6 +433,7 @@
self->priv = priv;
self->adapters = g_new0(NfcAdapter*, 1);
self->enabled = TRUE;
+ priv->requested_mode = NFC_MODE_READER_WRITER;
priv->adapters = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, g_object_unref);
}
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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(
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/src/nfc_plugin.c
^
|
@@ -32,6 +32,7 @@
#define GLIB_DISABLE_DEPRECATION_WARNINGS
+#include "nfc_plugin_impl.h"
#include "nfc_plugin_p.h"
struct nfc_plugin_priv {
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/src/nfc_plugin_p.h
^
|
@@ -35,7 +35,7 @@
#include "nfc_types_p.h"
-#include <nfc_plugin_impl.h>
+#include <nfc_plugin.h>
gboolean
nfc_plugin_start(
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/src/nfc_plugins.c
^
|
@@ -32,6 +32,7 @@
#include "nfc_plugin_p.h"
#include "nfc_plugins.h"
+#include "nfc_version.h"
#include "nfc_log.h"
#include <gutil_strv.h>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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:
*
@@ -38,10 +39,12 @@
#include "nfc_log.h"
#include <gutil_misc.h>
+#include <gutil_macros.h>
struct nfc_tag_priv {
char* name;
gulong gone_id;
+ NfcParamPoll* param;
};
G_DEFINE_TYPE(NfcTag, nfc_tag, G_TYPE_OBJECT)
@@ -77,12 +80,13 @@
NfcTag*
nfc_tag_new(
- NfcTarget* target)
+ NfcTarget* target,
+ const NfcParamPoll* poll)
{
if (G_LIKELY(target)) {
NfcTag* self = g_object_new(NFC_TYPE_TAG, NULL);
- nfc_tag_init_base(self, target);
+ nfc_tag_init_base(self, target, poll);
return self;
}
return NULL;
@@ -107,6 +111,13 @@
}
}
+const NfcParamPoll*
+nfc_tag_param(
+ NfcTag* self) /* Since 1.0.33 */
+{
+ return G_LIKELY(self) ? self->priv->param : NULL;
+}
+
void
nfc_tag_deactivate(
NfcTag* self)
@@ -162,7 +173,8 @@
void
nfc_tag_init_base(
NfcTag* self,
- NfcTarget* target)
+ NfcTarget* target,
+ const NfcParamPoll* poll)
{
NfcTagPriv* priv = self->priv;
@@ -172,6 +184,56 @@
self->present = target->present;
self->target = nfc_target_ref(target);
priv->gone_id = nfc_target_add_gone_handler(target, nfc_tag_gone, self);
+ if (poll) {
+ const gsize aligned_size = G_ALIGN8(sizeof(*poll));
+ const GUtilData* src;
+ const NfcParamPollB* poll_b;
+ guint8* dest;
+ gsize size;
+
+ /*
+ * Allocate the whole thing (including additional data) from a
+ * single memory block and adjust the pointers.
+ */
+ switch (target->technology) {
+ case NFC_TECHNOLOGY_A:
+ src = &poll->a.nfcid1;
+ size = src->size ? (aligned_size + src->size) : sizeof(*poll);
+ *(priv->param = g_malloc0(size)) = *poll;
+ if (src->bytes) {
+ dest = (guint8*)priv->param + aligned_size;
+
+ memcpy(dest, src->bytes, src->size);
+ priv->param->a.nfcid1.bytes = dest;
+ }
+ break;
+ case NFC_TECHNOLOGY_B:
+ 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) {
+ 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:
+ case NFC_TECHNOLOGY_UNKNOWN:
+ break;
+ }
+ }
}
void
@@ -219,6 +281,7 @@
nfc_target_unref(self->target);
nfc_ndef_rec_unref(self->ndef);
g_free(priv->name);
+ g_free(priv->param);
G_OBJECT_CLASS(nfc_tag_parent_class)->finalize(object);
}
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/src/nfc_tag_p.h
^
|
@@ -43,19 +43,21 @@
NfcTag*
nfc_tag_new(
- NfcTarget* target)
+ NfcTarget* target,
+ const NfcParamPoll* poll)
NFCD_INTERNAL;
NfcTagType2*
nfc_tag_t2_new(
NfcTarget* target,
- const NfcParamPollA* param)
+ const NfcParamPollA* poll_a)
NFCD_INTERNAL;
void
nfc_tag_init_base(
NfcTag* tag,
- NfcTarget* target)
+ NfcTarget* target,
+ const NfcParamPoll* poll)
NFCD_INTERNAL;
void
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -114,8 +115,6 @@
GHashTable* reads;
GHashTable* writes;
GByteArray* cached_blocks;
- guint8 serial[4];
- void* nfcid1;
guint sector_count;
NfcTagType2Sector* sectors;
guint init_id;
@@ -875,7 +874,7 @@
nfc_hexdump_data(&data);
if ((block * block_size) < sector->size) {
/* Inficate that data wasn't fully read */
- gutil_log(&_nfc_dump_log, GLOG_LEVEL_DEBUG, " %04X: ...",
+ gutil_log(&nfc_dump_log, GLOG_LEVEL_DEBUG, " %04X: ...",
block * block_size);
}
@@ -903,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) {
@@ -957,18 +951,27 @@
nfc_tag_t2_init2(
NfcTagType2* self,
NfcTarget* target,
- const NfcParamPollA* param)
+ const NfcParamPollA* poll_a)
{
NfcTagType2Priv* priv = self->priv;
+ NfcTag* tag = &self->tag;
- nfc_tag_init_base(&self->tag, target);
- priv->init_seq = nfc_target_sequence_new(target);
- if (param) {
- priv->nfcid1 = g_memdup(param->nfcid1.bytes, param->nfcid1.size);
- self->sel_res = param->sel_res;
- self->nfcid1.size = param->nfcid1.size;
- self->nfcid1.bytes = priv->nfcid1;
+ if (poll_a) {
+ NfcParamPoll poll;
+
+ GASSERT(target->technology == NFC_TECHNOLOGY_A);
+ memset(&poll, 0, sizeof(poll));
+ poll.a = *poll_a;
+ 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);
}
+ priv->init_seq = nfc_target_sequence_new(target);
}
/*==========================================================================*
@@ -1387,7 +1390,6 @@
}
nfc_target_cancel_transmit(self->tag.target, priv->init_id);
nfc_target_sequence_unref(priv->init_seq);
- g_free(priv->nfcid1);
G_OBJECT_CLASS(nfc_tag_t2_parent_class)->finalize(object);
}
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -39,6 +40,8 @@
#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,30 @@
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* self)
{
- nfc_tag_t4_initialized(NFC_TAG_T4(user_data));
+ /*
+ * 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(NFC_TAG_T4(self));
+ }
}
static
@@ -399,10 +424,9 @@
* 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)) {
+ 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);
}
@@ -663,6 +687,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
+nfc_tag_t4_reset_data_resp(
+ NfcTarget* target,
+ NFC_REACTIVATE_STATUS status,
+ void* user_data)
+{
+ NfcIsoDepResetData* rst = user_data;
+
+ if (rst->resp) {
+ /* Result is FALSE in case of tag was gone or reactivation timed out */
+ rst->resp(rst->t4, status == NFC_REACTIVATE_STATUS_SUCCESS,
+ rst->user_data);
+ }
+}
+
/*==========================================================================*
* Internal interface
*==========================================================================*/
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -43,22 +44,37 @@
NfcTagType4a*
nfc_tag_t4a_new(
NfcTarget* target,
- const NfcParamPollA* tech_param,
- const NfcParamIsoDepPollA* interface_param)
+ const NfcParamPollA* poll_a,
+ const NfcParamIsoDepPollA* iso_dep_param)
NFCD_INTERNAL;
NfcTagType4b*
nfc_tag_t4b_new(
NfcTarget* target,
- const NfcParamPollB* tech_param,
- const NfcParamIsoDepPollB* interface_param)
+ const NfcParamPollB* poll_b,
+ const NfcParamIsoDepPollB* iso_dep_param)
NFCD_INTERNAL;
void
nfc_tag_t4_init_base(
NfcTagType4* tag,
NfcTarget* target,
- guint mtu)
+ guint mtu,
+ 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.0.47.tar.bz2/core/src/nfc_tag_t4a.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,6 +32,7 @@
*/
#include "nfc_tag_t4_p.h"
+#include "nfc_target.h"
#include "nfc_log.h"
typedef struct nfc_tag_t4a_class {
@@ -50,19 +52,33 @@
NfcTagType4a*
nfc_tag_t4a_new(
NfcTarget* target,
- const NfcParamPollA* tech_param,
- const NfcParamIsoDepPollA* iso_dep_param)
+ const NfcParamPollA* poll_a,
+ 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");
- nfc_tag_t4_init_base(&self->t4, target, iso_dep_param->fsc);
+ GASSERT(target->technology == NFC_TECHNOLOGY_A);
+ memset(&iso_dep, 0, sizeof(iso_dep));
+ iso_dep.a = *iso_dep_a;
+ if (poll_a) {
+ NfcParamPoll poll;
+
+ memset(&poll, 0, sizeof(poll));
+ poll.a = *poll_a;
+ nfc_tag_t4_init_base(t4, target, iso_dep_a->fsc, &poll, &iso_dep);
+ } else {
+ 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.0.47.tar.bz2/core/src/nfc_tag_t4b.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,6 +32,7 @@
*/
#include "nfc_tag_t4_p.h"
+#include "nfc_target.h"
#include "nfc_log.h"
typedef struct nfc_tag_t4b_class {
@@ -50,14 +52,27 @@
NfcTagType4b*
nfc_tag_t4b_new(
NfcTarget* target,
- const NfcParamPollB* tech_param,
- const NfcParamIsoDepPollB* iso_dep_param)
+ const NfcParamPollB* poll_b,
+ const NfcParamIsoDepPollB* iso_dep_b)
{
- if (G_LIKELY(tech_param)) {
+ 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");
- nfc_tag_t4_init_base(&self->t4, target, tech_param->fsc);
+ GASSERT(target->technology == NFC_TECHNOLOGY_B);
+ memset(&poll, 0, sizeof(poll));
+ poll.b = *poll_b;
+ 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.0.47.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) 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_tag.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)
+{
+ static const NfcTargetRequestType transmit_request_type = {
+ "Transmit",
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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:
*
@@ -35,7 +36,20 @@
#include "nfc_types_p.h"
-#include <nfc_target_impl.h>
+#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(
@@ -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.0.47.tar.bz2/core/src/nfc_types_p.h
^
|
@@ -35,10 +35,12 @@
#include <nfc_types.h>
-extern GLogModule _nfc_dump_log;
-
+/* Macros */
#define NFCD_INTERNAL G_GNUC_INTERNAL
+/* Internal log module */
+extern GLogModule nfc_dump_log NFCD_INTERNAL;
+
#endif /* NFC_TYPES_PRIVATE_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/core/src/nfc_util.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:
*
@@ -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
@@ -38,7 +38,7 @@
#include <gutil_macros.h>
/* sub-module, to turn prefix off */
-GLogModule _nfc_dump_log = {
+GLogModule nfc_dump_log = {
.name = "nfc.dump",
.parent = &GLOG_MODULE_NAME,
.max_level = GLOG_LEVEL_MAX,
@@ -52,7 +52,7 @@
int len)
{
const int level = GLOG_LEVEL_VERBOSE;
- GLogModule* log = &_nfc_dump_log;
+ GLogModule* log = &nfc_dump_log;
if (gutil_log_enabled(log, level)) {
const guint8* ptr = data;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/plugins/Makefile
^
|
@@ -44,6 +44,7 @@
dbus_service_name.c \
dbus_service_ndef.c \
dbus_service_plugin.c \
+ dbus_service_util.c \
dbus_service_tag.c \
dbus_service_tag_t2.c
@@ -146,8 +147,6 @@
# Setting plugin
#
-PKGS += libmce-glib
-
SETTINGS_DIR = settings
SETTINGS_PLUGIN_SRC = \
settings_plugin.c
@@ -233,40 +232,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.0.47.tar.bz2/plugins/dbus_neard/org.neard.conf
^
|
@@ -8,6 +8,7 @@
<allow own="org.neard"/>
</policy>
<policy context="default">
+ <allow send_destination="org.neard" send_interface="org.freedesktop.DBus.Introspectable"/>
<allow send_destination="org.neard" send_interface="org.freedesktop.DBus.Properties"/>
<allow send_destination="org.neard" send_interface="org.freedesktop.DBus.ObjectManager"/>
<allow send_destination="org.neard" send_interface="org.neard.Adapter"/>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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-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:
*
@@ -112,7 +112,7 @@
NfcTargetSequence*
dbus_service_tag_sequence(
DBusServiceTag* tag,
- const char* sender);
+ GDBusMethodInvocation* call);
void
dbus_service_tag_free(
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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-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:
*
@@ -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>
@@ -64,6 +66,9 @@
CALL_DEACTIVATE,
CALL_ACQUIRE,
CALL_RELEASE,
+ CALL_GET_ALL3,
+ CALL_GET_POLL_PARAMETERS,
+ CALL_TRANSCEIVE,
CALL_COUNT
};
@@ -98,6 +103,11 @@
GSList* pending_calls; /* GDBusMethodInvocation references */
} DBusServiceTagLockWaiter;
+typedef struct dbus_service_tag_async_call {
+ OrgSailfishosNfcTag* iface;
+ GDBusMethodInvocation* call;
+} DBusServiceTagAsyncCall;
+
struct dbus_service_tag {
char* path;
GDBusConnection* connection;
@@ -117,7 +127,7 @@
};
#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
@@ -144,9 +154,11 @@
NfcTargetSequence*
dbus_service_tag_sequence(
DBusServiceTag* self,
- const char* sender)
+ GDBusMethodInvocation* call)
{
- if (G_LIKELY(self) && G_LIKELY(sender)) {
+ const char* sender = g_dbus_method_invocation_get_sender(call);
+
+ if (G_LIKELY(sender)) {
if (self->lock && !g_strcmp0(self->lock->name, sender)) {
return self->lock->seq;
} else {
@@ -761,6 +773,176 @@
return TRUE;
}
+/* Interface Version 3 */
+
+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);
+}
+
+/* GetAll3 */
+
+static
+void
+dbus_service_tag_complete_get_all3(
+ GDBusMethodInvocation* call,
+ DBusServiceTag* self)
+{
+ NfcTag* tag = self->tag;
+ NfcTarget* target = tag->target;
+
+ org_sailfishos_nfc_tag_complete_get_all3(self->iface, call,
+ NFC_DBUS_TAG_INTERFACE_VERSION, tag->present, target->technology,
+ target->protocol, tag->type, self->interfaces ? self->interfaces :
+ dbus_service_tag_default_interfaces,
+ dbus_service_tag_get_ndef_rec_paths(self),
+ dbus_service_tag_get_poll_parameters(self->tag,
+ nfc_tag_param(self->tag)));
+}
+
+static
+gboolean
+dbus_service_tag_handle_get_all3(
+ OrgSailfishosNfcTag* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceTag* self)
+{
+ /* Queue the call if the tag is not initialized yet */
+ return dbus_service_tag_handle_call(self, call,
+ dbus_service_tag_complete_get_all3);
+}
+
+/* GetPollParameters */
+
+static
+gboolean
+dbus_service_tag_handle_get_poll_parameters(
+ OrgSailfishosNfcTag* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceTag* self)
+{
+ NfcTag* tag = self->tag;
+
+ org_sailfishos_nfc_tag_complete_get_poll_parameters(iface, call,
+ dbus_service_tag_get_poll_parameters(tag, nfc_tag_param(tag)));
+ return TRUE;
+}
+
+/* Interface Version 4 */
+
+static
+void
+dbus_service_tag_async_free(
+ DBusServiceTagAsyncCall* async)
+{
+ g_object_unref(async->iface);
+ g_object_unref(async->call);
+ g_slice_free1(sizeof(*async), async);
+}
+
+static
+void
+dbus_service_tag_async_destroy(
+ void* async)
+{
+ dbus_service_tag_async_free((DBusServiceTagAsyncCall*)async);
+}
+
+static
+void
+dbus_service_tag_handle_transmit_complete(
+ NfcTarget* target,
+ NFC_TRANSMIT_STATUS status,
+ const void* data,
+ guint len,
+ void* user_data)
+{
+ DBusServiceTagAsyncCall* async = user_data;
+
+ switch (status) {
+ case NFC_TRANSMIT_STATUS_OK:
+ org_sailfishos_nfc_tag_complete_transceive(async->iface, async->call,
+ dbus_service_dup_byte_array_as_variant(data, len));
+ break;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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);
}
/*==========================================================================*
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.0.47.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.0.47.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.0.47.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>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.Tag.xml
^
|
@@ -59,5 +59,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.0.47.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.daemon.conf
^
|
@@ -9,6 +9,8 @@
</policy>
<policy context="default">
<allow send_destination="org.sailfishos.nfc.daemon"
+ send_interface="org.freedesktop.DBus.Introspectable"/>
+ <allow send_destination="org.sailfishos.nfc.daemon"
send_interface="org.sailfishos.nfc.Daemon"/>
<allow send_destination="org.sailfishos.nfc.daemon"
send_interface="org.sailfishos.nfc.Adapter"/>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/plugins/settings/org.sailfishos.nfc.settings.conf
^
|
@@ -9,6 +9,8 @@
</policy>
<policy context="default">
<allow send_destination="org.sailfishos.nfc.settings"
+ send_interface="org.freedesktop.DBus.Introspectable"/>
+ <allow send_destination="org.sailfishos.nfc.settings"
send_interface="org.sailfishos.nfc.Settings"/>
</policy>
</busconfig>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/plugins/settings/settings_plugin.c
^
|
@@ -39,9 +39,6 @@
#include <gio/gio.h>
-#include <mce_display.h>
-#include <mce_log.h>
-
#include <dbusaccess_policy.h>
#include <dbusaccess_peer.h>
@@ -64,12 +61,6 @@
};
enum {
- DISPLAY_VALID,
- DISPLAY_STATE,
- MCE_EVENT_COUNT
-};
-
-enum {
NFC_ADAPTER_ADDED,
NFC_EVENT_COUNT
};
@@ -78,17 +69,13 @@
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;
@@ -142,9 +129,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 +210,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 +218,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 +263,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 +270,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 +400,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 +420,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)) {
+ nfc_manager_request_power(self->manager, TRUE);
+ }
settings_plugin_set_nfc_enabled(self, settings_plugin_nfc_enabled(config));
- settings_plugin_update_nfc_state(self);
+ nfc_manager_set_enabled(self->manager, self->nfc_enabled);
g_key_file_unref(config);
return TRUE;
}
@@ -537,7 +437,6 @@
SettingsPlugin* self = SETTINGS_PLUGIN(plugin);
GVERBOSE("Stopping");
- settings_plugin_drop_display(self);
if (self->own_name_id) {
g_bus_unown_name(self->own_name_id);
self->own_name_id = 0;
@@ -551,7 +450,6 @@
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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 $@
@@ -182,11 +187,14 @@
# Install
#
+UNITDIR ?= usr/lib/systemd/system
+ABS_UNITDIR := $(shell echo /$(UNITDIR) | sed -r 's|/+|/|g')
+
INSTALL = install
INSTALL_DIRS = $(INSTALL) -d
INSTALL_SBIN_DIR = $(DESTDIR)/usr/sbin
-INSTALL_SYSTEMD_DIR = $(DESTDIR)/lib/systemd/system
+INSTALL_SYSTEMD_DIR = $(DESTDIR)$(ABS_UNITDIR)
install: $(RELEASE_EXE) $(INSTALL_SBIN_DIR) $(INSTALL_SYSTEMD_DIR)
$(INSTALL) -m 644 nfcd.service "$(INSTALL_SYSTEMD_DIR)"
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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-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:
*
@@ -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)
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/src/nfcd.map
^
|
@@ -1,6 +1,7 @@
{
global:
nfc_adapter_*;
+ nfc_core_*;
nfc_crc_*;
nfc_manager_*;
nfc_ndef_rec_*;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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.0.47.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.0.47.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.0.47.tar.bz2/unit/Makefile
^
|
@@ -27,6 +27,7 @@
@$(MAKE) -C plugins_dbus_service_adapter $*
@$(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.0.47.tar.bz2/unit/common/test_common.h
^
|
@@ -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,6 +35,15 @@
#include <nfc_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;
@@ -69,6 +78,16 @@
#define TEST_TIMEOUT_SEC (20)
+/* Utilities */
+GUtilData*
+test_alloc_data(
+ const void* bytes,
+ guint len);
+
+GUtilData*
+test_clone_data(
+ const GUtilData* data);
+
/* Helper macros */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/common/test_dbus.c
^
|
@@ -1,6 +1,6 @@
/*
- * 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>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -43,10 +43,46 @@
GDBusServer* server;
GDBusAuthObserver* observer;
TestDBusStartFunc start;
+ TestDBusStartFunc start2;
void* user_data;
+ gboolean started;
+ guint start2_id;
};
static
+gboolean
+test_dbus_start2(
+ gpointer user_data)
+{
+ TestDBus* self = user_data;
+
+ GDEBUG("Starting test stage 2");
+ self->start2_id = 0;
+ self->start2(self->client_connection, self->server_connection,
+ self->user_data);
+ return G_SOURCE_REMOVE;
+}
+
+static
+void
+test_dbus_start(
+ TestDBus* self)
+{
+ if ((self->start || self->start2) && !self->started) {
+ self->started = TRUE;
+ if (self->start) {
+ GDEBUG("Starting the test");
+ self->start(self->client_connection, self->server_connection,
+ self->user_data);
+ }
+ if (self->start2) {
+ self->start2_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+ test_dbus_start2, self, NULL);
+ }
+ }
+}
+
+static
void
test_dbus_client_connection(
GObject* source,
@@ -59,10 +95,8 @@
g_assert(!self->client_connection);
self->client_connection = g_dbus_connection_new_finish(res, NULL);
g_assert(self->client_connection);
-
- if (self->client_connection && self->server_connection && self->start) {
- self->start(self->client_connection, self->server_connection,
- self->user_data);
+ if (self->client_connection && self->server_connection && !self->started) {
+ test_dbus_start(self);
}
}
@@ -78,10 +112,8 @@
GDEBUG("Got server connection");
g_assert(!self->server_connection);
g_object_ref(self->server_connection = connection);
-
- if (self->client_connection && self->server_connection && self->start) {
- self->start(self->client_connection, self->server_connection,
- self->user_data);
+ if (self->client_connection && self->server_connection && !self->started) {
+ test_dbus_start(self);
}
return TRUE;
}
@@ -103,12 +135,22 @@
TestDBusStartFunc start,
void* user_data)
{
+ return test_dbus_new2(start, NULL, user_data);
+}
+
+TestDBus*
+test_dbus_new2(
+ TestDBusStartFunc start,
+ TestDBusStartFunc start2,
+ void* user_data)
+{
TestDBus* self = g_new0(TestDBus, 1);
char* guid = g_dbus_generate_guid();
char* tmpaddr;
const char* client_addr;
self->start = start;
+ self->start2 = start2;
self->user_data = user_data;
self->tmpdir = g_dir_make_tmp("test_dbus_XXXXXX", NULL);
tmpaddr = g_strconcat("unix:tmpdir=", self->tmpdir, NULL);
@@ -141,6 +183,9 @@
TestDBus* self)
{
if (self) {
+ if (self->start2_id) {
+ g_source_remove(self->start2_id);
+ }
if (self->client_connection) {
g_object_unref(self->client_connection);
}
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/common/test_dbus.h
^
|
@@ -1,6 +1,6 @@
/*
- * 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>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -49,6 +49,12 @@
TestDBusStartFunc start,
void* user_data);
+TestDBus*
+test_dbus_new2(
+ TestDBusStartFunc start,
+ TestDBusStartFunc start2,
+ void* user_data);
+
void
test_dbus_free(
TestDBus* dbus);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/common/test_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-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,36 @@
#include <gutil_log.h>
+GUtilData*
+test_alloc_data(
+ const void* bytes,
+ guint len)
+{
+ if (bytes) {
+ const gsize total = len + sizeof(GUtilData);
+ GUtilData* data = g_malloc(total);
+
+ if (len) {
+ void* contents = (void*)(data + 1);
+
+ data->bytes = contents;
+ data->size = len;
+ memcpy(contents, bytes, len);
+ } else {
+ memset(data, 0, sizeof(*data));
+ }
+ return data;
+ }
+ return NULL;
+}
+
+GUtilData*
+test_clone_data(
+ const GUtilData* data)
+{
+ return data ? test_alloc_data(data->bytes, data->size) : NULL;
+}
+
gboolean
test_timeout_expired(
gpointer data)
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/common/test_target.c
^
|
@@ -1,6 +1,6 @@
/*
- * 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>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,20 +30,91 @@
* 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>
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;
+}
+
+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_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
@@ -59,6 +130,22 @@
test_target_init(
TestTarget* self)
{
+ self->fail_transmit = -1; /* Always fail everything by default */
+ 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
@@ -66,7 +153,59 @@
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(
+ void)
+{
+ return g_object_new(TEST_TYPE_TARGET, NULL);
+}
+
+NfcTarget*
+test_target_new_tech(
+ NFC_TECHNOLOGY tech)
+{
+ NfcTarget* target = test_target_new();
+
+ target->technology = tech;
+ 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 = 0;
+ 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 = 0;
+ 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));
}
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/common/test_target.h
^
|
@@ -1,6 +1,6 @@
/*
- * 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>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -33,12 +33,48 @@
#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))
NfcTarget*
test_target_new(
void);
+NfcTarget*
+test_target_new_tech(
+ NFC_TECHNOLOGY tech);
+
+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);
+
#endif /* TEST_TARGET_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/core_adapter/test_core_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 "test_target.h"
#include "nfc_adapter_p.h"
+#include "nfc_adapter_impl.h"
#include "nfc_target_impl.h"
#include "nfc_tag_t2.h"
@@ -223,7 +224,9 @@
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_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));
@@ -269,7 +272,10 @@
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_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);
@@ -575,14 +581,14 @@
void)
{
TestAdapter* test = test_adapter_new();
- NfcTarget* target0 = test_target_new();
+ NfcTarget* target0 = test_target_new_tech(NFC_TECHNOLOGY_A);
NfcTarget* target1 = test_target_new();
NfcAdapter* adapter = &test->adapter;
NfcTag* tag0;
NfcTag* tag1;
gulong id[3];
int tag_added = 0, tag_removed = 0, presence_changed_count = 0;
- NfcParamPollA poll_a;
+ NfcParamPoll poll;
id[0] = nfc_adapter_add_tag_added_handler(adapter,
test_adapter_tag_inc, &tag_added);
@@ -606,9 +612,9 @@
g_assert(adapter->target_present);
g_assert(presence_changed_count == 1);
- memset(&poll_a, 0, sizeof(poll_a));
- tag0 = nfc_adapter_add_tag_t2(adapter, target0, &poll_a);
- tag1 = nfc_adapter_add_other_tag(adapter, target1);
+ memset(&poll, 0, sizeof(poll));
+ tag0 = nfc_adapter_add_tag_t2(adapter, target0, &poll.a);
+ tag1 = nfc_adapter_add_other_tag2(adapter, target1, NULL);
g_assert(tag0);
g_assert(tag1);
g_assert(!g_strcmp0(tag0->name, "tag0"));
@@ -634,8 +640,8 @@
nfc_adapter_remove_tag(adapter, NULL);
nfc_adapter_remove_tag(adapter, "foo");
- /* This tag is no longer present: */
- g_assert(!nfc_adapter_add_other_tag(adapter, target0));
+ /* This target is no longer present: */
+ g_assert(!nfc_adapter_add_other_tag2(adapter, target0, &poll));
g_assert(tag_removed == 2);
nfc_adapter_remove_all_handlers(adapter, id);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/core_plugin/test_core_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-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:
*
@@ -32,6 +32,7 @@
#include "test_common.h"
+#include "nfc_plugin_impl.h"
#include "nfc_plugin_p.h"
#include <gutil_log.h>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/core_tag/test_core_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-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:
*
@@ -35,6 +36,7 @@
#include "nfc_tag_p.h"
#include "nfc_target_p.h"
+#include "nfc_target_impl.h"
#include <gutil_log.h>
@@ -60,6 +62,7 @@
{
/* Public interfaces are NULL tolerant */
g_assert(!nfc_tag_ref(NULL));
+ g_assert(!nfc_tag_param(NULL));
g_assert(!nfc_tag_add_initialized_handler(NULL, NULL, NULL));
g_assert(!nfc_tag_add_gone_handler(NULL, NULL, NULL));
nfc_tag_remove_handler(NULL, 0);
@@ -79,15 +82,18 @@
{
NfcTag* tag = g_object_new(NFC_TYPE_TAG, NULL);
NfcTarget* target = test_target_new();
+ NfcParamPoll poll;
const char* name = "test";
int init_count = 0;
int gone_count = 0;
gulong init_id;
gulong gone_id;
- nfc_tag_init_base(tag, target);
+ memset(&poll, 0, sizeof(poll));
+ nfc_tag_init_base(tag, target, &poll);
g_assert(tag->target == target);
g_assert(tag->present == TRUE);
+ g_assert(!nfc_tag_param(tag)); /* No params for NFC_TECHNOLOGY_UNKNOWN */
g_assert(!tag->name);
nfc_tag_set_name(tag, name);
@@ -128,6 +134,152 @@
}
/*==========================================================================*
+ * basic_a
+ *==========================================================================*/
+
+static
+void
+test_basic_a(
+ void)
+{
+ static const guint8 nfcid1[] = {0x04, 0xbd, 0xfa, 0x4a, 0xeb, 0x2b, 0x80};
+ 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);
+ NfcParamPoll poll;
+ const NfcParamPollA* poll_a;
+
+ memset(&poll, 0, sizeof(poll));
+ poll.a.nfcid1 = nfcid1_data;
+ nfc_tag_init_base(tag, target, &poll);
+ g_assert(tag->target == target);
+ g_assert(tag->present == TRUE);
+ poll_a = &nfc_tag_param(tag)->a;
+ g_assert(poll_a);
+ g_assert(poll_a->nfcid1.size == sizeof(nfcid1));
+ g_assert(!memcmp(poll_a->nfcid1.bytes, nfcid1, sizeof(nfcid1)));
+ nfc_tag_unref(tag);
+
+ /* Make sure NULL nfcid1 is handled */
+ tag = g_object_new(NFC_TYPE_TAG, NULL);
+ memset(&poll, 0, sizeof(poll));
+ nfc_tag_init_base(tag, target, &poll);
+ poll_a = &nfc_tag_param(tag)->a;
+ g_assert(poll_a);
+ g_assert_cmpuint(poll_a->nfcid1.size, == ,0);
+ g_assert(!poll_a->nfcid1.bytes);
+ nfc_tag_unref(tag);
+
+ nfc_target_unref(target);
+}
+
+/*==========================================================================*
+ * basic_b
+ *==========================================================================*/
+
+static
+void
+test_basic_b(
+ void)
+{
+ 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);
+ 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 */
+ tag = g_object_new(NFC_TYPE_TAG, NULL);
+ memset(&poll, 0, sizeof(poll));
+ nfc_tag_init_base(tag, target, &poll);
+ poll_b = &nfc_tag_param(tag)->b;
+ g_assert(poll_b);
+ g_assert_cmpuint(poll_b->nfcid0.size, == ,0);
+ 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);
+}
+
+/*==========================================================================*
* Common
*==========================================================================*/
@@ -141,6 +293,8 @@
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/core_tag_t2/test_core_tag_t2.c
^
|
@@ -1,6 +1,7 @@
/*
- * 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>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -35,7 +36,7 @@
#include "nfc_ndef.h"
#include "nfc_tag_p.h"
#include "nfc_tag_t2.h"
-#include "nfc_target_p.h"
+#include "nfc_target_impl.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" */
@@ -421,6 +422,7 @@
{
TestTarget* self = g_object_new(TEST_TYPE_TARGET, NULL);
+ self->target.technology = NFC_TECHNOLOGY_A;
self->data.bytes = self->storage = g_memdup(bytes, size);
self->data.size = size;
return self;
@@ -683,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);
}
@@ -746,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);
@@ -795,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);
@@ -837,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);
@@ -908,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.0.47.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.0.47.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) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -31,11 +32,12 @@
*/
#include "test_common.h"
+#include "test_target.h"
#include "nfc_ndef.h"
#include "nfc_tag_p.h"
#include "nfc_tag_t4_p.h"
-#include "nfc_target_p.h"
+#include "nfc_target_impl.h"
#include <gutil_log.h>
@@ -173,38 +175,8 @@
0x73, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, /* Data */
0x90, 0x00 /* SW1|SW2 */
};
-
-static
-GUtilData*
-test_alloc_data(
- const void* bytes,
- guint len)
-{
- if (bytes) {
- const gsize total = len + sizeof(GUtilData);
- GUtilData* data = g_malloc(total);
-
- if (len) {
- void* contents = (void*)(data + 1);
-
- data->bytes = contents;
- data->size = len;
- memcpy(contents, bytes, len);
- } else {
- memset(data, 0, sizeof(*data));
- }
- return data;
- }
- return NULL;
-}
-
-static
-GUtilData*
-test_clone_data(
- const GUtilData* data)
-{
- return data ? test_alloc_data(data->bytes, data->size) : NULL;
-}
+static gint reset_count = 0;
+static gint reset_free_count = 0;
static
void
@@ -215,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);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.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:
*
@@ -34,6 +35,7 @@
#include "nfc_tag_p.h"
#include "nfc_target_p.h"
+#include "nfc_target_impl.h"
#include <gutil_log.h>
@@ -61,27 +63,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,
@@ -396,9 +377,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));
@@ -438,7 +421,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 */
@@ -494,9 +477,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(
@@ -514,11 +501,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);
@@ -570,9 +553,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);
@@ -595,11 +582,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);
@@ -690,7 +673,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);
@@ -708,11 +691,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);
@@ -772,12 +751,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,
@@ -814,11 +794,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);
@@ -846,7 +822,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;
@@ -891,11 +867,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);
@@ -924,19 +896,14 @@
/* Reactivation is supported */
g_assert(nfc_target_can_reactivate(target));
- /* Immediate reactivation failure */
- test->mode = TEST_REACTIVATE_MODE_FAIL;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/coverage/run
^
|
@@ -28,7 +28,8 @@
plugins_dbus_handlers_type_uri \
plugins_dbus_service_adapter \
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.0.47.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-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -111,8 +111,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 +182,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.0.47.tar.bz2/unit/plugins_dbus_service_adapter/test_plugins_dbus_service_adapter.c
^
|
@@ -1,6 +1,6 @@
/*
- * 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>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -40,6 +40,7 @@
#include "internal/nfc_manager_i.h"
#include "nfc_plugins.h"
#include "nfc_adapter_p.h"
+#include "nfc_adapter_impl.h"
#include "nfc_target_impl.h"
#include "nfc_tag.h"
@@ -543,13 +544,15 @@
{
TestData* test = user_data;
NfcTarget* target;
+ NfcParamPoll poll;
test->service = dbus_service_adapter_new(test->adapter, server);
g_assert(test->service);
/* Add second tag after creating DBusServiceAdapter */
target = test_target_new();
- g_assert(nfc_adapter_add_other_tag(test->adapter, target));
+ memset(&poll, 0, sizeof(poll));
+ g_assert(nfc_adapter_add_other_tag2(test->adapter, target, &poll));
nfc_target_unref(target);
g_dbus_connection_call(client, NULL,
@@ -566,12 +569,14 @@
TestData test;
TestDBus* dbus;
NfcTarget* target;
+ NfcParamPoll poll;
test_data_init(&test);
/* Add one tag before creating DBusServiceAdapter */
target = test_target_new();
- g_assert(nfc_adapter_add_other_tag(test.adapter, target));
+ memset(&poll, 0, sizeof(poll));
+ g_assert(nfc_adapter_add_other_tag2(test.adapter, target, &poll));
nfc_target_unref(target);
dbus = test_dbus_new(test_get_tags_start, &test);
@@ -800,6 +805,7 @@
{
TestData* test = user_data;
NfcTarget* target;
+ NfcParamPoll poll;
test->service = dbus_service_adapter_new(test->adapter, server);
g_assert(test->service);
@@ -812,7 +818,8 @@
/* Add a tag */
target = test_target_new();
- g_assert(nfc_adapter_add_other_tag(test->adapter, target));
+ memset(&poll, 0, sizeof(poll));
+ g_assert(nfc_adapter_add_other_tag2(test->adapter, target, &poll));
nfc_target_unref(target);
}
@@ -891,11 +898,13 @@
TestData test;
TestDBus* dbus;
NfcTarget* target;
+ NfcParamPoll poll;
test_data_init(&test);
target = test_target_new();
- g_assert(nfc_adapter_add_other_tag(test.adapter, target));
+ memset(&poll, 0, sizeof(poll));
+ g_assert(nfc_adapter_add_other_tag2(test.adapter, target, &poll));
nfc_target_unref(target);
dbus = test_dbus_new(test_tag_removed_start, &test);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/plugins_dbus_service_plugin/test_plugins_dbus_service_plugin.c
^
|
@@ -1,6 +1,6 @@
/*
- * 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>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -85,15 +85,25 @@
static
void
+test_start(
+ GDBusConnection* client,
+ GDBusConnection* server,
+ void* user_data)
+{
+ TestData* test = user_data;
+
+ test_server = server;
+ g_assert(nfc_manager_start(test->manager));
+}
+
+static
+void
test_call(
TestData* test,
GDBusConnection* client,
- GDBusConnection* server,
const char* method,
GAsyncReadyCallback callback)
{
- test_server = server;
- g_assert(nfc_manager_start(test->manager));
g_dbus_connection_call(client, NULL, "/", NFC_DAEMON_INTERFACE,
method, NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, callback, test);
}
@@ -148,7 +158,7 @@
data->name = g_strdup(name);
data->bus_acquired = bus_acquired;
data->name_acquired = name_acquired;
- g_idle_add_full(G_PRIORITY_HIGH, test_bus_acquired, data,
+ g_idle_add_full(G_PRIORITY_HIGH_IDLE, test_bus_acquired, data,
test_bus_acquired_free);
return TEST_NAME_OWN_ID;
}
@@ -196,7 +206,7 @@
GDBusConnection* server,
void* test)
{
- test_call((TestData*)test, client, server, "GetAll", test_get_all_done);
+ test_call((TestData*)test, client, "GetAll", test_get_all_done);
}
static
@@ -208,7 +218,7 @@
TestDBus* dbus;
test_data_init(&test);
- dbus = test_dbus_new(test_get_all_start, &test);
+ dbus = test_dbus_new2(test_start, test_get_all_start, &test);
test_run(&test_opt, test.loop);
test_data_cleanup(&test);
test_dbus_free(dbus);
@@ -248,7 +258,7 @@
GDBusConnection* server,
void* test)
{
- test_call((TestData*)test, client, server, "GetInterfaceVersion",
+ test_call((TestData*)test, client, "GetInterfaceVersion",
test_get_interface_version_done);
}
@@ -261,7 +271,7 @@
TestDBus* dbus;
test_data_init(&test);
- dbus = test_dbus_new(test_get_interface_version_start, &test);
+ dbus = test_dbus_new2(test_start, test_get_interface_version_start, &test);
test_run(&test_opt, test.loop);
test_data_cleanup(&test);
test_dbus_free(dbus);
@@ -301,7 +311,7 @@
GDBusConnection* server,
void* test)
{
- test_call((TestData*)test, client, server, "GetAdapters",
+ test_call((TestData*)test, client, "GetAdapters",
test_get_adapters_done);
}
@@ -314,7 +324,7 @@
TestDBus* dbus;
test_data_init(&test);
- dbus = test_dbus_new(test_get_adapters_start, &test);
+ dbus = test_dbus_new2(test_start, test_get_adapters_start, &test);
test_run(&test_opt, test.loop);
test_data_cleanup(&test);
test_dbus_free(dbus);
@@ -359,7 +369,7 @@
GDBusConnection* server,
void* test)
{
- test_call((TestData*)test, client, server, "GetAll2", test_get_all2_done);
+ test_call((TestData*)test, client, "GetAll2", test_get_all2_done);
}
static
@@ -371,7 +381,7 @@
TestDBus* dbus;
test_data_init(&test);
- dbus = test_dbus_new(test_get_all2_start, &test);
+ dbus = test_dbus_new2(test_start, test_get_all2_start, &test);
test_run(&test_opt, test.loop);
test_data_cleanup(&test);
test_dbus_free(dbus);
@@ -411,7 +421,7 @@
GDBusConnection* server,
void* test)
{
- test_call((TestData*)test, client, server, "GetDaemonVersion",
+ test_call((TestData*)test, client, "GetDaemonVersion",
test_get_daemon_version_done);
}
@@ -424,7 +434,7 @@
TestDBus* dbus;
test_data_init(&test);
- dbus = test_dbus_new(test_get_daemon_version_start, &test);
+ dbus = test_dbus_new2(test_start, test_get_daemon_version_start, &test);
test_run(&test_opt, test.loop);
test_data_cleanup(&test);
test_dbus_free(dbus);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.0.47.tar.bz2/unit/plugins_dbus_service_tag/test_plugins_dbus_service_tag.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:
*
@@ -36,18 +37,20 @@
#include "test_dbus.h"
#include "dbus_service/dbus_service.h"
+#include "dbus_service/dbus_service_util.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 "nfc_ndef.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";
@@ -72,6 +75,7 @@
{
NfcPluginsInfo pi;
NfcTarget* target;
+ NfcParamPoll poll;
g_assert(!test_name_watches);
memset(test, 0, sizeof(*test));
@@ -80,7 +84,8 @@
g_assert((test->adapter = test_adapter_new()) != NULL);
target = test_target_new();
- g_assert(nfc_adapter_add_other_tag(test->adapter, target));
+ memset(&poll, 0, sizeof(poll));
+ g_assert(nfc_adapter_add_other_tag2(test->adapter, target, &poll));
nfc_target_unref(target);
g_assert(nfc_manager_add_adapter(test->manager, test->adapter));
@@ -165,11 +170,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);
@@ -177,17 +183,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);
}
@@ -329,7 +352,6 @@
void)
{
dbus_service_tag_free(NULL);
- g_assert(!dbus_service_tag_sequence(NULL, NULL));
}
/*==========================================================================*
@@ -450,20 +472,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);
}
@@ -748,12 +763,12 @@
}
/*==========================================================================*
- * get_records
+ * get_ndef_records0
*==========================================================================*/
static
void
-test_get_records_done(
+test_get_ndef_records0_done(
GObject* object,
GAsyncResult* result,
gpointer user_data)
@@ -775,7 +790,7 @@
static
void
-test_get_records_start(
+test_get_ndef_records0_start(
GDBusConnection* client,
GDBusConnection* server,
void* user_data)
@@ -784,19 +799,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)
+{
+ TestData* test = user_data;
+ gchar** records = NULL;
+ GVariant* var = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object),
+ result, NULL);
+
+ g_assert(var);
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.0.47.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.0.47.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:
+ */
|