[-]
[+]
|
Changed |
_service:tar_git:libncicore.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore.spec
^
|
|
[-]
[+]
|
Deleted |
_service:tar_git:libncicore-1.1.0.tar.bz2/debian/libncicore-dev.install
^
|
@@ -1,3 +0,0 @@
-debian/tmp/usr/lib/libncicore.so usr/lib
-include/*.h usr/include/ncicore
-build/libncicore.pc usr/lib/pkgconfig
|
[-]
[+]
|
Deleted |
_service:tar_git:libncicore-1.1.0.tar.bz2/debian/libncicore.install
^
|
@@ -1 +0,0 @@
-debian/tmp/usr/lib/libncicore.so.* usr/lib
|
[-]
[+]
|
Deleted |
_service:tar_git:libncicore-1.1.0.tar.bz2/src/nci_transition_poll_active_to_idle.c
^
|
@@ -1,169 +0,0 @@
-/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 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 "nci_transition.h"
-#include "nci_transition_impl.h"
-#include "nci_sm.h"
-#include "nci_log.h"
-
-/*==========================================================================*
- *
- * 5.2.5 State RFST_POLL_ACTIVE
- *
- * ...
- * If the DH sends RF_DEACTIVATE_CMD (Idle Mode), the NFCC SHALL send
- * RF_DEACTIVATE_RSP followed by RF_DEACTIVATE_NTF (Idle Mode, DH Request)
- * upon successful deactivation. The state will then change to RFST_IDLE.
- *
- *==========================================================================*/
-
-typedef NciTransition NciTransitionPollActiveToIdle;
-typedef NciTransitionClass NciTransitionPollActiveToIdleClass;
-
-G_DEFINE_TYPE(NciTransitionPollActiveToIdle,
- nci_transition_poll_active_to_idle, NCI_TYPE_TRANSITION)
-#define THIS_TYPE (nci_transition_poll_active_to_idle_get_type())
-#define PARENT_CLASS (nci_transition_poll_active_to_idle_parent_class)
-
-/*==========================================================================*
- * Implementation
- *==========================================================================*/
-
-static
-void
-nci_transition_poll_active_to_idle_rsp(
- NCI_REQUEST_STATUS status,
- const GUtilData* payload,
- NciTransition* self)
-{
- if (status == NCI_REQUEST_CANCELLED || !nci_transition_active(self)) {
- GDEBUG("RF_DEACTIVATE (Idle) cancelled");
- } else if (status == NCI_REQUEST_TIMEOUT) {
- GDEBUG("RF_DEACTIVATE (Idle) timed out");
- nci_transition_stall(self, NCI_STALL_ERROR);
- } else if (status == NCI_REQUEST_SUCCESS) {
- const guint8* rsp = payload->bytes;
- const guint len = payload->size;
-
- if (len == 1 && rsp[0] == NCI_STATUS_OK) {
- GDEBUG("%c RF_DEACTIVATE_RSP (Idle) ok", DIR_IN);
- /* Wait for RF_DEACTIVATE_NTF */
- } else {
- if (len > 0) {
- GWARN("%c RF_DEACTIVATE_RSP (Idle) error %u", DIR_IN, rsp[0]);
- } else {
- GWARN("%c Broken RF_DEACTIVATE_RSP (Idle)", DIR_IN);
- }
- nci_transition_stall(self, NCI_STALL_ERROR);
- }
- }
-}
-
-/*==========================================================================*
- * Interface
- *==========================================================================*/
-
-NciTransition*
-nci_transition_poll_active_to_idle_new(
- NciSm* sm)
-{
- NciState* dest = nci_sm_get_state(sm, NCI_RFST_IDLE);
-
- if (dest) {
- NciTransition* self = g_object_new(THIS_TYPE, NULL);
-
- nci_transition_init_base(self, sm, dest);
- return self;
- }
- return NULL;
-}
-
-/*==========================================================================*
- * Methods
- *==========================================================================*/
-
-static
-void
-nci_transition_poll_active_to_idle_handle_ntf(
- NciTransition* self,
- guint8 gid,
- guint8 oid,
- const GUtilData* payload)
-{
- switch (gid) {
- case NCI_GID_RF:
- switch (oid) {
- case NCI_OID_RF_DEACTIVATE:
- nci_sm_handle_rf_deactivate_ntf(nci_transition_sm(self), payload);
- return;
- }
- break;
- }
- NCI_TRANSITION_CLASS(PARENT_CLASS)->handle_ntf(self, gid, oid, payload);
-}
-
-static
-gboolean
-nci_transition_poll_active_to_idle_start(
- NciTransition* self)
-{
- return nci_transition_deactivate_to_idle(self,
- nci_transition_poll_active_to_idle_rsp);
-}
-
-/*==========================================================================*
- * Internals
- *==========================================================================*/
-
-static
-void
-nci_transition_poll_active_to_idle_init(
- NciTransitionPollActiveToIdle* self)
-{
-}
-
-static
-void
-nci_transition_poll_active_to_idle_class_init(
- NciTransitionPollActiveToIdleClass* klass)
-{
- klass->start = nci_transition_poll_active_to_idle_start;
- klass->handle_ntf = nci_transition_poll_active_to_idle_handle_ntf;
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
|
[-]
[+]
|
Deleted |
_service:tar_git:libncicore-1.1.0.tar.bz2/src/nci_util.h
^
|
@@ -1,87 +0,0 @@
-/*
- * 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:
- *
- * 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 NCI_UTIL_H
-#define NCI_UTIL_H
-
-#include "nci_types_p.h"
-
-gboolean
-nci_listen_mode(
- NCI_MODE mode)
- NCI_INTERNAL;
-
-const NciModeParam*
-nci_parse_mode_param(
- NciModeParam* param,
- NCI_MODE mode,
- const guint8* bytes,
- guint len)
- NCI_INTERNAL;
-
-gboolean
-nci_parse_discover_ntf(
- NciDiscoveryNtf* ntf,
- NciModeParam* param,
- const guint8* bytes,
- guint len)
- NCI_INTERNAL;
-
-gboolean
-nci_parse_intf_activated_ntf(
- NciIntfActivationNtf* ntf,
- NciModeParam* mode_param,
- NciActivationParam* activation_param,
- const guint8* pkt,
- guint len)
- NCI_INTERNAL;
-
-NciDiscoveryNtf*
-nci_discovery_ntf_copy_array(
- const NciDiscoveryNtf* const* ntfs,
- guint count)
- NCI_INTERNAL;
-
-NciDiscoveryNtf*
-nci_discovery_ntf_copy(
- const NciDiscoveryNtf* ntf)
- NCI_INTERNAL;
-
-#endif /* NCI_UTIL_H */
-
-/*
- * Local Variables:
- * mode: C
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/.gitignore
^
|
@@ -4,6 +4,7 @@
debian/libncicore-dev
debian/*.debhelper.log
debian/*.debhelper
+debian/*.install
debian/*.substvars
debian/tmp
documentation.list
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/LICENSE
^
|
@@ -1,6 +1,6 @@
Copyright (C) 2018-2020 Jolla Ltd.
Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
-Copyright (C) 2019 Open Mobile Platform LLC.
+Copyright (C) 2019-2020 Open Mobile Platform LLC.
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/Makefile
^
|
@@ -61,10 +61,10 @@
nci_state_w4_all_discoveries.c \
nci_state_w4_host_select.c \
nci_transition.c \
+ nci_transition_active_to_idle.c \
nci_transition_deactivate_to_discovery.c \
nci_transition_deactivate_to_idle.c \
nci_transition_idle_to_discovery.c \
- nci_transition_poll_active_to_idle.c \
nci_transition_reset.c \
nci_util.c
@@ -90,7 +90,8 @@
BASE_FLAGS = -fPIC
FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
-MMD -MP $(shell pkg-config --cflags $(PKGS))
-FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME)
+FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) \
+ -Wl,--version-script=$(LIB_NAME).map
LIBS = $(shell pkg-config --libs $(PKGS))
DEBUG_FLAGS = -g
RELEASE_FLAGS =
@@ -231,8 +232,19 @@
$(RELEASE_BUILD_DIR)/$(LIB_SYMLINK2): $(RELEASE_LIB)
ln -sf $(LIB) $@
+#
+# LIBDIR usually gets substituted with arch specific dir.
+# It's relative in deb build and can be whatever in rpm build.
+#
+
+LIBDIR ?= usr/lib
+ABS_LIBDIR := $(shell echo /$(LIBDIR) | sed -r 's|/+|/|g')
+
$(PKGCONFIG): $(LIB_NAME).pc.in $(VERSION_FILE)
- sed -e 's/\[version\]/'$(PCVERSION)/g $< > $@
+ sed -e 's|@version@|$(PCVERSION)|g' -e 's|@libdir@|$(ABS_LIBDIR)|g' $< > $@
+
+debian/%.install: debian/%.install.in
+ sed 's|@LIBDIR@|$(LIBDIR)|g' $< > $@
#
# Install
@@ -242,12 +254,12 @@
INSTALL_DIRS = $(INSTALL) -d
INSTALL_FILES = $(INSTALL) -m 644
-INSTALL_LIB_DIR = $(DESTDIR)/usr/lib
+INSTALL_LIB_DIR = $(DESTDIR)$(ABS_LIBDIR)
INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/$(NAME)
-INSTALL_PKGCONFIG_DIR = $(DESTDIR)/usr/lib/pkgconfig
+INSTALL_PKGCONFIG_DIR = $(DESTDIR)$(ABS_LIBDIR)/pkgconfig
install: $(INSTALL_LIB_DIR)
- $(INSTALL_FILES) $(RELEASE_LIB) $(INSTALL_LIB_DIR)
+ $(INSTALL) -m 755 $(RELEASE_LIB) $(INSTALL_LIB_DIR)
ln -sf $(LIB) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK2)
ln -sf $(LIB_SYMLINK2) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK1)
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/debian/changelog
^
|
@@ -1,3 +1,98 @@
+libncicore (1.1.14) unstable; urgency=low
+
+ * Fixed misleading "Invalid packet id" warning
+
+ -- Slava Monich <slava.monich@jolla.com> Mon, 28 Sep 2020 23:39:06 +0300
+
+libncicore (1.1.13) unstable; urgency=low
+
+ * Added nci_util_copy_mode_param() and nci_util_copy_activation_param()
+
+ -- Slava Monich <slava.monich@jolla.com> Mon, 21 Sep 2020 18:31:29 +0300
+
+libncicore (1.1.12) unstable; urgency=low
+
+ * Update libncicore.pc when version header changes
+
+ -- Slava Monich <slava.monich@jolla.com> Wed, 09 Sep 2020 19:41:13 +0300
+
+libncicore (1.1.11) unstable; urgency=low
+
+ * Added missing activation params for t4a tags
+ * Fixed TC presense bit in RATS response
+ * Avoid accessing data beyond the end of RATS response
+
+ -- Slava Monich <slava.monich@jolla.com> Thu, 20 Aug 2020 20:33:45 +0300
+
+libncicore (1.1.10) unstable; urgency=low
+
+ * Set TOTAL_DURATION to 500ms
+
+ -- Slava Monich <slava.monich@jolla.com> Mon, 10 Aug 2020 02:49:45 +0300
+
+libncicore (1.1.9) unstable; urgency=low
+
+ * Fixed credit management for fragmented data packets
+ * Fixed LISTEN_ACTIVE => IDLE transition
+
+ -- Slava Monich <slava.monich@jolla.com> Tue, 14 Jul 2020 14:24:42 +0300
+
+libncicore (1.1.8) unstable; urgency=low
+
+ * Issue INTF_ACTIVATED signal after state change
+
+ -- Slava Monich <slava.monich@jolla.com> Sat, 11 Jul 2020 19:18:05 +0300
+
+libncicore (1.1.7) unstable; urgency=low
+
+ * Request NFC-DEP RF interface for NFC-DEP protocol
+
+ -- Slava Monich <slava.monich@jolla.com> Fri, 10 Jul 2020 16:20:15 +0300
+
+libncicore (1.1.6) unstable; urgency=low
+
+ * Housekeeping release
+
+ -- Slava Monich <slava.monich@jolla.com> Thu, 11 Jun 2020 01:26:18 +0300
+
+libncicore (1.1.5) unstable; urgency=low
+
+ * Added NciActivationParamIsoDepPollB.
+ * Extended NciModeParamPollB to provide all SENSB_RES data
+
+ -- Slava Monich <slava.monich@jolla.com> Wed, 03 Jun 2020 19:06:39 +0300
+
+libncicore (1.1.4) unstable; urgency=low
+
+ * Reversed protocol selection order in RFST_W4_HOST_SELECT state
+ * Allow RF_INTF_ACTIVATED_NTF handler to request state transition
+
+ -- Slava Monich <slava.monich@jolla.com> Sun, 31 May 2020 01:46:20 +0300
+
+libncicore (1.1.3) unstable; urgency=low
+
+ * Fixed offsets of middle chunks in segmented packets
+
+ -- Slava Monich <slava.monich@jolla.com> Sat, 30 May 2020 13:38:04 +0300
+
+libncicore (1.1.2) unstable; urgency=low
+
+ * Respect arch specific lib dir
+ * Configure more RF discovery modes
+ * Added NfcParamListenF
+ * Hide internal symbols
+
+ -- Slava Monich <slava.monich@jolla.com> Tue, 26 May 2020 17:59:15 +0300
+
+libncicore (1.1.1) unstable; urgency=low
+
+ * Clear cmd_id on command completion
+ * Fixed handling of control packet payload size limit
+ * Apply max data packet size from RF_INTF_ACTIVATED_NTF
+ * Handle NCI_STATUS_SYNTAX_ERROR notifications
+
+ -- Slava Monich <slava.monich@jolla.com> Mon, 11 May 2020 01:37:06 +0300
+
libncicore (1.1.0) unstable; urgency=low
* Implement listen part of the state machine
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/debian/control
^
|
@@ -2,7 +2,7 @@
Section: libs
Priority: optional
Maintainer: Slava Monich <slava.monich@jolla.com>
-Build-Depends: debhelper (>= 7), libglib2.0-dev (>= 2.0), libglibutil-dev
+Build-Depends: debhelper (>= 8.1.3), libglib2.0-dev (>= 2.0), libglibutil-dev
Standards-Version: 3.8.4
Package: libncicore
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/debian/copyright
^
|
@@ -1,6 +1,6 @@
Copyright (C) 2018-2020 Jolla Ltd.
Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
-Copyright (C) 2019 Open Mobile Platform LLC.
+Copyright (C) 2019-2020 Open Mobile Platform LLC.
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.14.tar.bz2/debian/libncicore-dev.install.in
^
|
@@ -0,0 +1,3 @@
+debian/tmp/@LIBDIR@/libncicore.so @LIBDIR@
+debian/tmp/@LIBDIR@/pkgconfig/libncicore.pc @LIBDIR@/pkgconfig
+debian/tmp/usr/include/* usr/include
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.14.tar.bz2/debian/libncicore.install.in
^
|
@@ -0,0 +1 @@
+debian/tmp/@LIBDIR@/libncicore.so.* @LIBDIR@
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/debian/rules
^
|
@@ -4,8 +4,13 @@
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
+LIBDIR=usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
+
+override_dh_auto_build:
+ dh_auto_build -- LIBDIR=$(LIBDIR) release pkgconfig debian/libncicore.install debian/libncicore-dev.install
+
override_dh_auto_install:
- dh_auto_install -- install-dev
+ dh_auto_install -- LIBDIR=$(LIBDIR) install-dev
%:
dh $@
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/include/nci_types.h
^
|
@@ -130,6 +130,9 @@
typedef struct nci_mode_param_poll_b {
guint8 nfcid0[4];
guint fsc; /* FSCI converted to bytes */
+ /* Since 1.1.5 */
+ guint8 app_data[4];
+ GUtilData prot_info;
} NciModeParamPollB;
/* Table 58: Specific Parameters for NFC-F Poll Mode */
@@ -138,18 +141,42 @@
guint8 nfcid2[8]; /* Bytes 2-9 of SENSF_RES */
} NciModeParamPollF; /* Since 1.0.8 */
+/* Table 59: Specific Parameters for NFC-F Listen Mode */
+typedef struct nci_mode_param_listen_f {
+ GUtilData nfcid2; /* NFCID2 generated by the Local NFCC */
+} NciModeParamListenF; /* Since 1.1.2 */
+
typedef union nci_mode_param {
NciModeParamPollA poll_a;
NciModeParamPollB poll_b;
- NciModeParamPollF poll_f; /* Since 1.0.8 */
+ NciModeParamPollF poll_f; /* Since 1.0.8 */
+ NciModeParamListenF listen_f; /* Since 1.1.2 */
} NciModeParam;
/* Table 76: Activation Parameters for NFC-A/ISO-DEP Poll Mode */
typedef struct nci_activation_param_iso_dep_poll_a {
guint fsc; /* FSC (FSCI converted to bytes) */
GUtilData t1; /* T1 to Tk (otherwise called historical bytes) */
+ /* Since 1.1.11 */
+ guint8 t0; /* Format byte T0 */
+
+#define NFC_T4A_ATS_T0_A (0x10) /* TA is transmitted */
+#define NFC_T4A_ATS_T0_B (0x20) /* TB is transmitted */
+#define NFC_T4A_ATS_T0_C (0x40) /* TC is transmitted */
+#define NFC_T4A_ATS_T0_FSCI_MASK (0x0f) /* FSCI mask */
+
+ guint8 ta; /* Interface byte TA (optional) */
+ guint8 tb; /* Interface byte TB (optional) */
+ guint8 tc; /* Interface byte TC (optional) */
} NciActivationParamIsoDepPollA;
+/* Table 75: Activation Parameters for NFC-B/ISO-DEP Poll Mode */
+typedef struct nci_activation_param_iso_dep_poll_b {
+ guint mbli; /* Maximum Buffer Length Index */
+ guint did; /* Device ID */
+ GUtilData hlr; /* Higher Layer Response */
+} NciActivationParamIsoDepPollB; /* Since 1.1.5 */
+
/* Table 82: Activation Parameters for NFC-DEP Poll Mode */
typedef struct nci_activation_param_nfc_dep_poll {
/* ATR_RES starting from and including Byte 3 */
@@ -175,6 +202,7 @@
typedef union nci_activation_param {
NciActivationParamIsoDepPollA iso_dep_poll_a;
+ NciActivationParamIsoDepPollB iso_dep_poll_b; /* Since 1.1.5 */
NciActivationParamNfcDepPoll nfc_dep_poll; /* Since 1.0.8 */
NciActivationParamNfcDepListen nfc_dep_listen; /* Since 1.0.8 */
} NciActivationParam;
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.14.tar.bz2/include/nci_util.h
^
|
@@ -0,0 +1,64 @@
+/*
+ * 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:
+ *
+ * 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 NCI_UTIL_H
+#define NCI_UTIL_H
+
+#include <nci_types.h>
+
+G_BEGIN_DECLS
+
+/* Free the result with g_free() */
+NciModeParam*
+nci_util_copy_mode_param(
+ const NciModeParam* param,
+ NCI_MODE mode); /* Since 1.1.13 */
+
+/* Free the result with g_free() */
+NciActivationParam*
+nci_util_copy_activation_param(
+ const NciActivationParam* param,
+ NCI_RF_INTERFACE intf,
+ NCI_MODE mode); /* Since 1.1.13 */
+
+G_END_DECLS
+
+#endif /* NCI_UTIL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/include/nci_version.h
^
|
@@ -38,7 +38,7 @@
/* libncicore version */
#define NCI_CORE_VERSION_MAJOR 1
#define NCI_CORE_VERSION_MINOR 1
-#define NCI_CORE_VERSION_NANO 0
+#define NCI_CORE_VERSION_NANO 14
#define NCI_CORE_VERSION_WORD(v1,v2,v3) \
((((v1) & 0x7f) << 24) | \
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.14.tar.bz2/libncicore.map
^
|
@@ -0,0 +1,8 @@
+{
+ global:
+ nci_core_*;
+ nci_log;
+ nci_util_*;
+ local:
+ *;
+};
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/libncicore.pc.in
^
|
@@ -1,10 +1,10 @@
name=ncicore
-libdir=/usr/lib
+libdir=@libdir@
includedir=/usr/include
Name: libncicore
Description: NCI state machine development library
-Version: [version]
+Version: @version@
Requires.private: glib-2.0 gio-2.0 libglibutil
Libs: -L${libdir} -l${name}
Cflags: -I${includedir} -I${includedir}/${name}
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_core.c
^
|
@@ -90,6 +90,7 @@
} NciCoreObject;
typedef GObjectClass NciCoreObjectClass;
+GType nci_core_object_get_type() NCI_INTERNAL;
G_DEFINE_TYPE(NciCoreObject, nci_core_object, G_TYPE_OBJECT)
#define NCI_TYPE_CORE (nci_core_object_get_type())
#define NCI_CORE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
@@ -159,9 +160,10 @@
gboolean success,
gpointer user_data)
{
- if (!success) {
- NciCoreObject* self = NCI_CORE(user_data);
+ NciCoreObject* self = NCI_CORE(user_data);
+ self->cmd_id = 0;
+ if (!success) {
GWARN("Failed to send command %02x/%02x", self->rsp_gid, self->rsp_oid);
nci_sm_stall(self->sm, NCI_STALL_ERROR);
}
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_param_w4_all_discoveries.c
^
|
@@ -32,7 +32,7 @@
#include "nci_param_w4_all_discoveries.h"
#include "nci_param_impl.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
typedef NciParamClass NciParamW4AllDiscoveriesClass;
G_DEFINE_TYPE(NciParamW4AllDiscoveries, nci_param_w4_all_discoveries,
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_param_w4_host_select.c
^
|
@@ -32,7 +32,7 @@
#include "nci_param_w4_host_select.h"
#include "nci_param_impl.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
typedef NciParamClass NciParamW4HostSelectClass;
G_DEFINE_TYPE(NciParamW4HostSelect, nci_param_w4_host_select, NCI_TYPE_PARAM)
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_sar.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:
*
@@ -39,17 +39,18 @@
/* SAR (Segmentation and Reassembly) */
#define SAR_DEFAULT_MAX_LOGICAL_CONNECTIONS (1)
-#define SAR_DEFAULT_CONTROL_MTU (0x20)
-#define SAR_DEFAULT_DATA_MTU (0xff)
-#define SAR_MIN_MTU (0x04)
+#define SAR_MIN_CONTROL_PAYLOAD_LIMIT (0x20) /* Valid range is 32 to 255 */
+#define SAR_MIN_DATA_PAYLOAD_LIMIT (0x01) /* Valid range is 1 to 255 */
#define SAR_UNLIMITED_CREDITS (0xff)
#define NCI_HDR_SIZE (3)
typedef struct nci_sar_packet_out NciSarPacketOut;
+typedef struct nci_sar_logical_connection NciSarLogicalConnection;
struct nci_sar_packet_out {
NciSarPacketOut* next;
+ NciSarLogicalConnection* conn;
guint8 hdr[NCI_HDR_SIZE];
GBytes* payload;
guint payload_pos;
@@ -64,11 +65,11 @@
NciSarPacketOut* last;
} NciSarPacketOutQueue;
-typedef struct nci_sar_logical_connection {
+struct nci_sar_logical_connection {
guint8 credits;
GByteArray* in;
NciSarPacketOutQueue out;
-} NciSarLogicalConnection;
+};
struct nci_sar {
NciHalIo* io;
@@ -76,8 +77,8 @@
NciHalClient hal_client;
gboolean started;
guint8 max_logical_conns;
- guint8 control_mtu;
- guint8 data_mtu;
+ guint8 control_payload_limit;
+ guint8 data_payload_limit;
guint last_packet_id;
guint start_write_id;
gboolean write_pending;
@@ -184,8 +185,9 @@
NciSarLogicalConnection* conn = self->conn + i;
if (conn->out.first && conn->credits) {
- if (eat_credit) {
+ if (eat_credit && conn->credits != SAR_UNLIMITED_CREDITS) {
conn->credits--;
+ GVERBOSE("cid %u: %u credit(s)", i, conn->credits);
}
return &conn->out;
}
@@ -208,6 +210,22 @@
NciSar* self)
{
if (!self->write_pending) {
+ if (self->writing && self->writing->conn) {
+ NciSarLogicalConnection* conn = self->writing->conn;
+
+ if (conn->credits) {
+ if (conn->credits != SAR_UNLIMITED_CREDITS) {
+ conn->credits--;
+ GVERBOSE("cid %d: %u credit(s)", (int)(conn - self->conn),
+ conn->credits);
+ }
+ } else {
+ /* No more credits left, put it back to the queue */
+ self->writing->next = conn->out.first;
+ conn->out.first = self->writing;
+ self->writing = NULL;
+ }
+ }
if (!self->writing) {
NciSarPacketOutQueue* queue = nci_sar_write_queue(self, TRUE);
@@ -223,14 +241,14 @@
if (self->writing) {
NciHalIo* io = self->io;
NciSarPacketOut* out = self->writing;
- guint total_len = NCI_HDR_SIZE; /* +1 for payload length */
const guint8* payload = NULL;
gsize remaining_payload_len = 0;
GUtilData chunks[2];
int nchunks = 1;
gboolean write_submitted = FALSE;
- const guint mtu = ((out->hdr[0] & NCI_MT_MASK) ==
- NCI_MT_CMD_PKT) ? self->control_mtu : self->data_mtu;
+ const guint max_payload_size = ((out->hdr[0] & NCI_MT_MASK) ==
+ NCI_MT_CMD_PKT) ? self->control_payload_limit :
+ self->data_payload_limit;
if (out->payload) {
gsize payload_len = 0;
@@ -238,12 +256,11 @@
payload = g_bytes_get_data(out->payload, &payload_len);
GASSERT(payload_len >= out->payload_pos);
remaining_payload_len = payload_len - out->payload_pos;
- total_len += remaining_payload_len;
}
chunks[0].bytes = out->hdr;
chunks[0].size = NCI_HDR_SIZE;
- if (total_len <= mtu) {
+ if (remaining_payload_len <= max_payload_size) {
/* We can send the whole thing */
out->hdr[0] &= ~NCI_PBF;
out->hdr[2] = (guint8)remaining_payload_len;
@@ -256,9 +273,9 @@
} else {
/* Send a fragment */
out->hdr[0] |= NCI_PBF;
- out->hdr[2] = mtu;
- chunks[nchunks].bytes = payload;
- chunks[nchunks].size = mtu - chunks[0].size;
+ out->hdr[2] = max_payload_size;
+ chunks[nchunks].bytes = payload + out->payload_pos;
+ chunks[nchunks].size = max_payload_size;
out->payload_pos += chunks[nchunks].size;
nchunks++;
}
@@ -325,6 +342,7 @@
nci_sar_send(
NciSar* self,
NciSarPacketOutQueue* queue,
+ NciSarLogicalConnection* conn,
const guint8* hdr,
GBytes* payload,
NciSarCompletionFunc complete,
@@ -340,6 +358,7 @@
/* Fill in the packet structure */
out->id = id;
+ out->conn = conn;
out->complete = complete;
out->destroy = destroy;
out->user_data = user_data;
@@ -655,8 +674,8 @@
self->client = client;
self->io = io;
self->max_logical_conns = SAR_DEFAULT_MAX_LOGICAL_CONNECTIONS;
- self->control_mtu = SAR_DEFAULT_CONTROL_MTU;
- self->data_mtu = SAR_DEFAULT_DATA_MTU;
+ self->control_payload_limit = SAR_MIN_CONTROL_PAYLOAD_LIMIT;
+ self->data_payload_limit = SAR_MIN_DATA_PAYLOAD_LIMIT;
self->conn = g_new0(NciSarLogicalConnection, self->max_logical_conns);
return self;
}
@@ -778,15 +797,29 @@
}
void
-nci_sar_set_max_control_packet_size(
+nci_sar_set_max_control_payload_size(
+ NciSar* self,
+ guint8 max)
+{
+ if (G_LIKELY(self)) {
+ if (max < SAR_MIN_CONTROL_PAYLOAD_LIMIT) {
+ self->control_payload_limit = SAR_MIN_CONTROL_PAYLOAD_LIMIT;
+ } else {
+ self->control_payload_limit = max;
+ }
+ }
+}
+
+void
+nci_sar_set_max_data_payload_size(
NciSar* self,
guint8 max)
{
if (G_LIKELY(self)) {
- if (max < SAR_MIN_MTU) {
- self->control_mtu = max ? SAR_MIN_MTU : SAR_DEFAULT_CONTROL_MTU;
+ if (max < SAR_MIN_DATA_PAYLOAD_LIMIT) {
+ self->data_payload_limit = SAR_MIN_DATA_PAYLOAD_LIMIT;
} else {
- self->control_mtu = max;
+ self->data_payload_limit = max;
}
}
}
@@ -801,6 +834,7 @@
/* The queue should be empty at this point */
GASSERT(!self->conn[cid].out.first);
self->conn[cid].credits = credits;
+ GVERBOSE("cid %u: %u initial credit(s)", cid, credits);
}
}
@@ -818,6 +852,7 @@
conn->credits = SAR_UNLIMITED_CREDITS;
} else {
conn->credits += credits;
+ GVERBOSE("cid %u: %u credit(s)", cid, conn->credits);
}
if (conn->out.first) {
nci_sar_schedule_write(self);
@@ -842,7 +877,7 @@
hdr[0] = NCI_MT_CMD_PKT | (gid & NCI_CONTROL_GID_MASK);
hdr[1] = oid & NCI_CONTROL_OID_MASK;
- return nci_sar_send(self, &self->cmd, hdr, payload, complete,
+ return nci_sar_send(self, &self->cmd, NULL, hdr, payload, complete,
destroy, user_data);
}
return 0;
@@ -864,7 +899,7 @@
hdr[0] = cid & NCI_DATA_CID_MASK;
hdr[1] = 0;
- return nci_sar_send(self, &conn->out, hdr, payload, complete,
+ return nci_sar_send(self, &conn->out, conn, hdr, payload, complete,
destroy, user_data);
}
return 0;
@@ -880,7 +915,6 @@
/* We can't really cancel the packet once we started writing it.
* Just clear the completion callback. */
self->writing->complete = NULL;
- return;
} else if (!nci_sar_cancel_queue(self, &self->cmd, id)) {
guint i;
@@ -891,8 +925,8 @@
return;
}
}
+ GWARN("Invalid packet id %u", id);
}
- GWARN("Invalid packet id %u", id);
}
}
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_sar.h
^
|
@@ -88,7 +88,13 @@
NCI_INTERNAL;
void
-nci_sar_set_max_control_packet_size(
+nci_sar_set_max_control_payload_size(
+ NciSar* sar,
+ guint8 max)
+ NCI_INTERNAL;
+
+void
+nci_sar_set_max_data_payload_size(
NciSar* sar,
guint8 max)
NCI_INTERNAL;
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_sm.c
^
|
@@ -618,11 +618,15 @@
/* Set up the transitions */
/* Reusable deactivate_to_idle */
+ deactivate_to_idle = nci_transition_active_to_idle_new(sm);
+ nci_sm_add_transition(sm, NCI_RFST_LISTEN_ACTIVE, deactivate_to_idle);
+ nci_sm_add_transition(sm, NCI_RFST_POLL_ACTIVE, deactivate_to_idle);
+ nci_transition_unref(deactivate_to_idle);
+
deactivate_to_idle = nci_transition_deactivate_to_idle_new(sm);
nci_sm_add_transition(sm, NCI_RFST_DISCOVERY, deactivate_to_idle);
nci_sm_add_transition(sm, NCI_RFST_W4_ALL_DISCOVERIES, deactivate_to_idle);
nci_sm_add_transition(sm, NCI_RFST_W4_HOST_SELECT, deactivate_to_idle);
- nci_sm_add_transition(sm, NCI_RFST_LISTEN_ACTIVE, deactivate_to_idle);
nci_sm_add_transition(sm, NCI_RFST_LISTEN_SLEEP, deactivate_to_idle);
nci_transition_unref(deactivate_to_idle);
@@ -635,8 +639,6 @@
/* And these are not reusable */
nci_sm_add_new_transition(sm, NCI_RFST_IDLE,
nci_transition_idle_to_discovery_new);
- nci_sm_add_new_transition(sm, NCI_RFST_POLL_ACTIVE,
- nci_transition_poll_active_to_idle_new);
return sm;
}
@@ -926,7 +928,10 @@
NciSmObject* self = nci_sm_object(sm);
if (G_LIKELY(self)) {
- nci_sar_set_initial_credits(nci_sm_sar(sm), NCI_STATIC_RF_CONN_ID,
+ NciSar* sar = nci_sm_sar(sm);
+
+ nci_sar_set_max_data_payload_size(sar, ntf->max_data_packet_size);
+ nci_sar_set_initial_credits(sar, NCI_STATIC_RF_CONN_ID,
ntf->num_credits);
g_signal_emit(self, nci_sm_signals[SIGNAL_INTF_ACTIVATED], 0, ntf);
}
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_state_discovery.c
^
|
@@ -34,7 +34,7 @@
#include "nci_sar.h"
#include "nci_state_impl.h"
#include "nci_param_w4_all_discoveries.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
#include "nci_log.h"
typedef NciState NciStateDiscovery;
@@ -75,12 +75,17 @@
*/
if (nci_parse_intf_activated_ntf(&ntf, &mode_param, &activation_param,
payload->bytes, payload->size)) {
- nci_sm_intf_activated(sm, &ntf);
+ /*
+ * Switch the state first because RF_INTF_ACTIVATED_NTF handler
+ * may want to change the state again (e.g. if configuration is
+ * unsupported).
+ */
if (nci_listen_mode(ntf.mode)) {
nci_sm_enter_state(sm, NCI_RFST_LISTEN_ACTIVE, NULL);
} else {
nci_sm_enter_state(sm, NCI_RFST_POLL_ACTIVE, NULL);
}
+ nci_sm_intf_activated(sm, &ntf);
} else {
/* Deactivate this target */
nci_sm_enter_state(sm, NCI_RFST_POLL_ACTIVE, NULL);
@@ -163,6 +168,17 @@
return FALSE;
}
+static
+void
+nci_state_discovery_entered(
+ NciState* self)
+{
+ NciSm* sm = nci_state_sm(self);
+ NciSar* sar = nci_sm_sar(sm);
+
+ nci_sar_set_max_data_payload_size(sar, 0 /* Reset to default */);
+}
+
/*==========================================================================*
* Interface
*==========================================================================*/
@@ -183,6 +199,26 @@
static
void
+nci_state_discovery_enter(
+ NciState* self,
+ NciParam* param)
+{
+ nci_state_discovery_entered(self);
+ NCI_STATE_CLASS(PARENT_CLASS)->enter(self, param);
+}
+
+static
+void
+nci_state_discovery_reenter(
+ NciState* self,
+ NciParam* param)
+{
+ nci_state_discovery_entered(self);
+ NCI_STATE_CLASS(PARENT_CLASS)->reenter(self, param);
+}
+
+static
+void
nci_state_discovery_handle_ntf(
NciState* self,
guint8 gid,
@@ -228,7 +264,9 @@
nci_state_discovery_class_init(
NciStateDiscoveryClass* klass)
{
- NCI_STATE_CLASS(klass)->handle_ntf = nci_state_discovery_handle_ntf;
+ klass->enter = nci_state_discovery_enter;
+ klass->reenter = nci_state_discovery_reenter;
+ klass->handle_ntf = nci_state_discovery_handle_ntf;
}
/*
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_state_listen_active.c
^
|
@@ -80,22 +80,26 @@
* remain RFST_LISTEN_ACTIVE.
*/
if (len == 2) {
- NciSm* sm = nci_state_sm(self);
-
switch (pkt[0]) {
+ case NCI_STATUS_SYNTAX_ERROR:
+ GDEBUG("CORE_INTERFACE_ERROR_NTF (Syntax Error)");
+ break;
case NCI_RF_TRANSMISSION_ERROR:
GDEBUG("CORE_INTERFACE_ERROR_NTF (Transmission Error)");
- nci_sm_switch_to(sm, NCI_RFST_DISCOVERY);
- return TRUE;
+ break;
case NCI_RF_PROTOCOL_ERROR:
GDEBUG("CORE_INTERFACE_ERROR_NTF (Protocol Error)");
- nci_sm_switch_to(sm, NCI_RFST_DISCOVERY);
- return TRUE;
+ break;;
case NCI_RF_TIMEOUT_ERROR:
GDEBUG("CORE_INTERFACE_ERROR_NTF (Timeout)");
- nci_sm_switch_to(sm, NCI_RFST_DISCOVERY);
- return TRUE;
+ break;
+ default:
+ /* Unrecognized notification */
+ return FALSE;
}
+ /* Deactivate the link */
+ nci_sm_switch_to(nci_state_sm(self), NCI_RFST_DISCOVERY);
+ return TRUE;
}
/* Unrecognized notification */
return FALSE;
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_state_listen_sleep.c
^
|
@@ -32,7 +32,7 @@
#include "nci_sm.h"
#include "nci_state_impl.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
#include "nci_log.h"
typedef NciState NciStateListenSleep;
@@ -70,9 +70,14 @@
*/
if (nci_parse_intf_activated_ntf(&ntf, &mode_param, &activation_param,
payload->bytes, payload->size)) {
- nci_sm_intf_activated(sm, &ntf);
if (nci_listen_mode(ntf.mode)) {
+ /*
+ * Switch the state first because RF_INTF_ACTIVATED_NTF handler
+ * may want to change the state again (e.g. if configuration is
+ * unsupported).
+ */
nci_sm_enter_state(sm, NCI_RFST_LISTEN_ACTIVE, NULL);
+ nci_sm_intf_activated(sm, &ntf);
return;
} else {
GDEBUG("Unexpected activation mode 0x%02x", ntf.mode);
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_state_poll_active.c
^
|
@@ -77,19 +77,25 @@
*/
if (len == 2) {
switch (pkt[0]) {
+ case NCI_STATUS_SYNTAX_ERROR:
+ GDEBUG("CORE_INTERFACE_ERROR_NTF (Syntax Error)");
+ break;
case NCI_RF_TRANSMISSION_ERROR:
GDEBUG("CORE_INTERFACE_ERROR_NTF (Transmission Error)");
- nci_sm_switch_to(nci_state_sm(self), NCI_RFST_DISCOVERY);
- return TRUE;
+ break;
case NCI_RF_PROTOCOL_ERROR:
GDEBUG("CORE_INTERFACE_ERROR_NTF (Protocol Error)");
- nci_sm_switch_to(nci_state_sm(self), NCI_RFST_DISCOVERY);
- return TRUE;
+ break;;
case NCI_RF_TIMEOUT_ERROR:
GDEBUG("CORE_INTERFACE_ERROR_NTF (Timeout)");
- nci_sm_switch_to(nci_state_sm(self), NCI_RFST_DISCOVERY);
- return TRUE;
+ break;
+ default:
+ /* Unrecognized notification */
+ return FALSE;
}
+ /* Deactivate the link */
+ nci_sm_switch_to(nci_state_sm(self), NCI_RFST_DISCOVERY);
+ return TRUE;
}
/* Unrecognized notification */
return FALSE;
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_state_w4_all_discoveries.c
^
|
@@ -34,7 +34,7 @@
#include "nci_state_impl.h"
#include "nci_param_w4_all_discoveries.h"
#include "nci_param_w4_host_select.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
typedef NciStateClass NciStateW4AllDiscoveriesClass;
typedef struct nci_state_w4_all_discoveries {
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_state_w4_host_select.c
^
|
@@ -33,7 +33,7 @@
#include "nci_sm.h"
#include "nci_state_impl.h"
#include "nci_param_w4_host_select.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
#include "nci_log.h"
typedef NciStateClass NciStateW4HostSelectClass;
@@ -65,9 +65,9 @@
*/
if (ntf_a->protocol != ntf_b->protocol) {
static const NCI_PROTOCOL protocol_order[] = {
- NCI_PROTOCOL_T2T,
+ NCI_PROTOCOL_NFC_DEP,
NCI_PROTOCOL_ISO_DEP,
- NCI_PROTOCOL_NFC_DEP
+ NCI_PROTOCOL_T2T
};
guint i;
@@ -164,11 +164,27 @@
* +=========================================================+
*/
guint8 cmd[3];
+ NCI_RF_INTERFACE rf_intf = NCI_RF_INTERFACE_FRAME;
+
+ switch (ntf->protocol) {
+ case NCI_PROTOCOL_T1T:
+ case NCI_PROTOCOL_T2T:
+ case NCI_PROTOCOL_T3T:
+ case NCI_PROTOCOL_PROPRIETARY:
+ case NCI_PROTOCOL_UNDETERMINED:
+ /* Choose NCI_RF_INTERFACE_FRAME */
+ break;
+ case NCI_PROTOCOL_ISO_DEP:
+ rf_intf = NCI_RF_INTERFACE_ISO_DEP;
+ break;
+ case NCI_PROTOCOL_NFC_DEP:
+ rf_intf = NCI_RF_INTERFACE_NFC_DEP;
+ break;
+ }
+
cmd[0] = ntf->discovery_id;
cmd[1] = ntf->protocol;
- cmd[2] = (ntf->protocol == NCI_PROTOCOL_ISO_DEP) ?
- NCI_RF_INTERFACE_ISO_DEP :
- NCI_RF_INTERFACE_FRAME;
+ cmd[2] = rf_intf;
GDEBUG("%c RF_DISCOVER_SELECT_CMD (0x%02x)", DIR_OUT,
ntf->discovery_id);
@@ -211,8 +227,13 @@
*/
if (nci_parse_intf_activated_ntf(&ntf, &mode_param, &activation_param,
payload->bytes, payload->size)) {
- nci_sm_intf_activated(sm, &ntf);
+ /*
+ * Switch the state first because RF_INTF_ACTIVATED_NTF handler
+ * may want to change the state again (e.g. if configuration is
+ * unsupported).
+ */
nci_sm_enter_state(sm, NCI_RFST_POLL_ACTIVE, NULL);
+ nci_sm_intf_activated(sm, &ntf);
} else {
/* Deactivate this target */
nci_sm_enter_state(sm, NCI_RFST_POLL_ACTIVE, NULL);
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_transition.h
^
|
@@ -109,7 +109,7 @@
NCI_INTERNAL;
NciTransition*
-nci_transition_poll_active_to_idle_new(
+nci_transition_active_to_idle_new(
NciSm* sm)
NCI_INTERNAL;
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_transition_active_to_idle.c
^
|
@@ -0,0 +1,170 @@
+/*
+ * 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:
+ *
+ * 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 "nci_transition.h"
+#include "nci_transition_impl.h"
+#include "nci_sm.h"
+#include "nci_log.h"
+
+/*==========================================================================*
+ *
+ * 5.2.5 State RFST_POLL_ACTIVE
+ * 5.2.6 State RFST_LISTEN_ACTIVE
+ *
+ * ...
+ * If the DH sends RF_DEACTIVATE_CMD (Idle Mode), the NFCC SHALL send
+ * RF_DEACTIVATE_RSP followed by RF_DEACTIVATE_NTF (Idle Mode, DH Request)
+ * upon successful deactivation. The state will then change to RFST_IDLE.
+ *
+ *==========================================================================*/
+
+typedef NciTransition NciTransitionActiveToIdle;
+typedef NciTransitionClass NciTransitionActiveToIdleClass;
+
+G_DEFINE_TYPE(NciTransitionActiveToIdle, nci_transition_active_to_idle,
+ NCI_TYPE_TRANSITION)
+#define THIS_TYPE (nci_transition_active_to_idle_get_type())
+#define PARENT_CLASS (nci_transition_active_to_idle_parent_class)
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+nci_transition_active_to_idle_rsp(
+ NCI_REQUEST_STATUS status,
+ const GUtilData* payload,
+ NciTransition* self)
+{
+ if (status == NCI_REQUEST_CANCELLED || !nci_transition_active(self)) {
+ GDEBUG("RF_DEACTIVATE (Idle) cancelled");
+ } else if (status == NCI_REQUEST_TIMEOUT) {
+ GDEBUG("RF_DEACTIVATE (Idle) timed out");
+ nci_transition_stall(self, NCI_STALL_ERROR);
+ } else if (status == NCI_REQUEST_SUCCESS) {
+ const guint8* rsp = payload->bytes;
+ const guint len = payload->size;
+
+ if (len == 1 && rsp[0] == NCI_STATUS_OK) {
+ GDEBUG("%c RF_DEACTIVATE_RSP (Idle) ok", DIR_IN);
+ /* Wait for RF_DEACTIVATE_NTF */
+ } else {
+ if (len > 0) {
+ GWARN("%c RF_DEACTIVATE_RSP (Idle) error %u", DIR_IN, rsp[0]);
+ } else {
+ GWARN("%c Broken RF_DEACTIVATE_RSP (Idle)", DIR_IN);
+ }
+ nci_transition_stall(self, NCI_STALL_ERROR);
+ }
+ }
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NciTransition*
+nci_transition_active_to_idle_new(
+ NciSm* sm)
+{
+ NciState* dest = nci_sm_get_state(sm, NCI_RFST_IDLE);
+
+ if (dest) {
+ NciTransition* self = g_object_new(THIS_TYPE, NULL);
+
+ nci_transition_init_base(self, sm, dest);
+ return self;
+ }
+ return NULL;
+}
+
+/*==========================================================================*
+ * Methods
+ *==========================================================================*/
+
+static
+void
+nci_transition_active_to_idle_handle_ntf(
+ NciTransition* self,
+ guint8 gid,
+ guint8 oid,
+ const GUtilData* payload)
+{
+ switch (gid) {
+ case NCI_GID_RF:
+ switch (oid) {
+ case NCI_OID_RF_DEACTIVATE:
+ nci_sm_handle_rf_deactivate_ntf(nci_transition_sm(self), payload);
+ return;
+ }
+ break;
+ }
+ NCI_TRANSITION_CLASS(PARENT_CLASS)->handle_ntf(self, gid, oid, payload);
+}
+
+static
+gboolean
+nci_transition_active_to_idle_start(
+ NciTransition* self)
+{
+ return nci_transition_deactivate_to_idle(self,
+ nci_transition_active_to_idle_rsp);
+}
+
+/*==========================================================================*
+ * Internals
+ *==========================================================================*/
+
+static
+void
+nci_transition_active_to_idle_init(
+ NciTransitionActiveToIdle* self)
+{
+}
+
+static
+void
+nci_transition_active_to_idle_class_init(
+ NciTransitionActiveToIdleClass* klass)
+{
+ klass->start = nci_transition_active_to_idle_start;
+ klass->handle_ntf = nci_transition_active_to_idle_handle_ntf;
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_transition_idle_to_discovery.c
^
|
@@ -140,6 +140,22 @@
GDEBUG("%c RF_DISCOVER_CMD", DIR_OUT);
g_byte_array_append(cmd, cmd_header, sizeof(cmd_header));
+ /*
+ * RW Modes: Poll A/B/V
+ * Peer Modes: Poll/Listen A/F
+ * CE Modes: Listen A/B
+ */
+ if (sm->op_mode & NFC_OP_MODE_RW) {
+ static const guint8 entries[] = {
+ NCI_MODE_PASSIVE_POLL_B, 1,
+ NCI_MODE_PASSIVE_POLL_15693, 1
+ };
+
+ GDEBUG(" PassivePollB");
+ GDEBUG(" PassivePollV");
+ g_byte_array_append(cmd, entries, sizeof(entries));
+ cmd->data[0] += sizeof(entries)/2;
+ }
if ((sm->op_mode & NFC_OP_MODE_RW) ||
(sm->op_mode & (NFC_OP_MODE_PEER|NFC_OP_MODE_POLL)) ==
(NFC_OP_MODE_PEER|NFC_OP_MODE_POLL)) {
@@ -153,14 +169,27 @@
g_byte_array_append(cmd, entries, sizeof(entries));
cmd->data[0] += sizeof(entries)/2;
}
- if (sm->op_mode & NFC_OP_MODE_RW) {
+ if ((sm->op_mode & (NFC_OP_MODE_PEER|NFC_OP_MODE_POLL)) ==
+ (NFC_OP_MODE_PEER|NFC_OP_MODE_POLL)) {
static const guint8 entries[] = {
- NCI_MODE_PASSIVE_POLL_B, 1,
- NCI_MODE_PASSIVE_POLL_15693, 1
+ NCI_MODE_PASSIVE_POLL_F, 1,
+ NCI_MODE_ACTIVE_POLL_F, 1
};
- GDEBUG(" PassivePollB");
- GDEBUG(" PassivePollV");
+ GDEBUG(" PassivePollF");
+ GDEBUG(" ActivePollF");
+ g_byte_array_append(cmd, entries, sizeof(entries));
+ cmd->data[0] += sizeof(entries)/2;
+ }
+ if ((sm->op_mode & (NFC_OP_MODE_PEER|NFC_OP_MODE_LISTEN)) ==
+ (NFC_OP_MODE_PEER|NFC_OP_MODE_LISTEN)) {
+ static const guint8 entries[] = {
+ NCI_MODE_PASSIVE_LISTEN_F, 1,
+ NCI_MODE_ACTIVE_LISTEN_F, 1
+ };
+
+ GDEBUG(" PassiveListenF");
+ GDEBUG(" ActiveListenF");
g_byte_array_append(cmd, entries, sizeof(entries));
cmd->data[0] += sizeof(entries)/2;
}
@@ -177,6 +206,15 @@
g_byte_array_append(cmd, entries, sizeof(entries));
cmd->data[0] += sizeof(entries)/2;
}
+ if (sm->op_mode & NFC_OP_MODE_CE) {
+ static const guint8 entries[] = {
+ NCI_MODE_PASSIVE_LISTEN_B, 1
+ };
+
+ GDEBUG(" PassiveListenB");
+ g_byte_array_append(cmd, entries, sizeof(entries));
+ cmd->data[0] += sizeof(entries)/2;
+ }
nci_transition_idle_to_discovery_send_byte_array(self,
NCI_GID_RF, NCI_OID_RF_DISCOVER, cmd,
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_transition_reset.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,11 +43,44 @@
#define THIS_TYPE (nci_transition_reset_get_type())
#define PARENT_CLASS (nci_transition_reset_parent_class)
+#define DEFAULT_TOTAL_DURATION (500) /* ms */
+
/*==========================================================================*
* Implementation
*==========================================================================*/
static
+gboolean
+nci_transition_reset_find_config_param(
+ guint nparams,
+ const guint8* params,
+ const guint len,
+ guint8 id,
+ GUtilData* value)
+{
+ const guint8* ptr = params;
+ const guint8* end = params + len;
+
+ /*
+ * +-----------------------------------------+
+ * | ID | 1 | The identifier |
+ * | Len | 1 | The length of Val (m) |
+ * | Val | m | The value of the parameter |
+ * +-----------------------------------------+
+ */
+ while (nparams > 0 && (ptr + 2) <= end && (ptr + 2 + ptr[1]) <= end) {
+ if (ptr[0] == id) {
+ value->size = ptr[1];
+ value->bytes = ptr + 2;
+ return TRUE;
+ }
+ nparams--;
+ ptr += 2 + ptr[1];
+ }
+ return FALSE;
+}
+
+static
void
nci_transition_reset_set_config_rsp(
NCI_REQUEST_STATUS status,
@@ -110,7 +143,10 @@
* +=========================================================+
*/
static const guint8 cmd[] = {
- 2,
+ 3,
+ NCI_CONFIG_TOTAL_DURATION, 0x02,
+ (guint8)(DEFAULT_TOTAL_DURATION & 0xff),
+ (guint8)((DEFAULT_TOTAL_DURATION >> 8) & 0xff),
NCI_CONFIG_PA_BAIL_OUT, 0x01, 0x00,
NCI_CONFIG_PB_BAIL_OUT, 0x01, 0x00
};
@@ -159,7 +195,33 @@
const guint n = pkt[1];
if (pkt[0] == NCI_STATUS_OK) {
+ GUtilData data;
+
GDEBUG("%c CORE_GET_CONFIG_RSP ok", DIR_IN);
+
+ /* Check if we need to tweak TOTAL_DURATION */
+ if (nci_transition_reset_find_config_param(n, pkt + 2, len - 2,
+ NCI_CONFIG_TOTAL_DURATION, &data) && data.size == 2) {
+ /*
+ * 1.11 Coding Conventions
+ *
+ * All values greater than 1 octet are sent and
+ * received in Little Endian format.
+ */
+ const guint ms = data.bytes[0] +
+ (((guint)data.bytes[1]) << 8);
+
+ if (ms == DEFAULT_TOTAL_DURATION) {
+ GDEBUG("TOTAL_DURATION is %u ms", ms);
+ /* Done with transition */
+ nci_transition_finish(self, NULL);
+ return;
+ } else {
+ GDEBUG("TOTAL_DURATION is %u ms, fixing that", ms);
+ }
+ } else {
+ GDEBUG("Could not determine TOTAL_DURATION");
+ }
} else if (pkt[0] == NCI_STATUS_INVALID_PARAM && len >= 2 + n*2) {
#if GUTIL_LOG_DEBUG
/*
@@ -217,15 +279,10 @@
* +=========================================================+
*/
static const guint8 cmd[] = {
- 2,
- NCI_CONFIG_PA_BAIL_OUT,
- NCI_CONFIG_PB_BAIL_OUT
+ 1,
+ NCI_CONFIG_TOTAL_DURATION
};
- /*
- * We may want to set some parameters some day but for now let's just
- * query something and see how it works...
- */
GDEBUG("%c CORE_GET_CONFIG_CMD", DIR_OUT);
nci_transition_send_command_static(self,
NCI_GID_CORE, NCI_OID_CORE_GET_CONFIG, cmd, sizeof(cmd),
@@ -276,7 +333,7 @@
len == ((n = pkt[5]) + 17)) {
const guint8* rf_interfaces = pkt + 6;
guint8 max_logical_conns = pkt[6 + n];
- guint8 max_control_packet = pkt[9 + n];
+ guint8 max_control_payload = pkt[9 + n];
if (sm->rf_interfaces) {
g_bytes_unref(sm->rf_interfaces);
@@ -308,13 +365,14 @@
#endif
GDEBUG(" Max Logical Connections = %u", max_logical_conns);
GDEBUG(" Max Routing Table Size = %u", sm->max_routing_table_size);
- GDEBUG(" Max Control Packet Size = %u", max_control_packet);
+ GDEBUG(" Max Control Packet Size = %u", max_control_payload);
GDEBUG(" Manufacturer = 0x%02x", pkt[12 + n]);
GDEBUG(" Manufacturer Info = %02x %02x %02x %02x",
pkt[13 + n], pkt[14 + n], pkt[15 + n], pkt[16 + n]);
nci_sar_set_max_logical_connections(sar, max_logical_conns);
- nci_sar_set_max_control_packet_size(sar, max_control_packet);
+ nci_sar_set_max_control_payload_size(sar, max_control_payload);
+ nci_sar_set_max_data_payload_size(sar, 0 /* Reset to default */);
nci_transition_reset_get_config(self);
return;
}
@@ -367,7 +425,7 @@
len == (2 * (n = pkt[13]) + 14)) {
const guint8* rf_interfaces = pkt + 14;
guint8 max_logical_conns = pkt[5];
- guint8 max_control_packet = pkt[8];
+ guint8 max_control_payload = pkt[8];
if (sm->rf_interfaces) {
g_bytes_unref(sm->rf_interfaces);
@@ -399,10 +457,11 @@
#endif
GDEBUG(" Max Logical Connections = %u", max_logical_conns);
GDEBUG(" Max Routing Table Size = %u", sm->max_routing_table_size);
- GDEBUG(" Max Control Packet Size = %u", max_control_packet);
+ GDEBUG(" Max Control Packet Size = %u", max_control_payload);
nci_sar_set_max_logical_connections(sar, max_logical_conns);
- nci_sar_set_max_control_packet_size(sar, max_control_packet);
+ nci_sar_set_max_control_payload_size(sar, max_control_payload);
+ nci_sar_set_max_data_payload_size(sar, 0 /* Reset to default */);
nci_transition_reset_get_config(self);
return;
}
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_util.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:
*
@@ -30,7 +31,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "nci_util.h"
+#include "nci_util_p.h"
#include "nci_log.h"
#include <gutil_macros.h>
@@ -178,11 +179,30 @@
ppb->fsc = (fsci < G_N_ELEMENTS(fsc_table)) ?
fsc_table[fsci] :
fsc_table[G_N_ELEMENTS(fsc_table) - 1];
+ memcpy(ppb->app_data, bytes + 5, 4);
+ ppb->prot_info.size = bytes[0] - 8;
+ ppb->prot_info.bytes = bytes + 9;
- GDEBUG("NFC-B");
- GDEBUG(" PollB.fsc = %u", ppb->fsc);
- GDEBUG(" PollB.nfcid0 = %02x %02x %02x %02x", ppb->nfcid0[0],
- ppb->nfcid0[1], ppb->nfcid0[2], ppb->nfcid0[3]);
+#if GUTIL_LOG_DEBUG
+ if (GLOG_ENABLED(GLOG_LEVEL_DEBUG)) {
+ GString *buf = g_string_new(NULL);
+ guint i;
+
+ for (i = 0; i < ppb->prot_info.size; i++) {
+ g_string_append_printf(buf, " %02x",
+ ppb->prot_info.bytes[i]);
+ }
+ GDEBUG("NFC-B");
+ GDEBUG(" PollB.fsc = %u", ppb->fsc);
+ GDEBUG(" PollB.nfcid0 = %02x %02x %02x %02x", ppb->nfcid0[0],
+ ppb->nfcid0[1], ppb->nfcid0[2], ppb->nfcid0[3]);
+ GDEBUG(" PollB.AppData = %02x %02x %02x %02x",
+ ppb->app_data[0], ppb->app_data[1], ppb->app_data[2],
+ ppb->app_data[3]);
+ GDEBUG(" PollB.ProtInfo =%s", buf->str);
+ g_string_free(buf, TRUE);
+ }
+#endif
return param;
}
GDEBUG("Failed to parse parameters for NFC-B poll mode");
@@ -215,20 +235,47 @@
pf->nfcid2[4], pf->nfcid2[5], pf->nfcid2[6], pf->nfcid2[7]);
return param;
}
- GDEBUG("Failed to parse parameters for NFC-F poll mode");
+ /* This does happen */
+ GDEBUG("No parameters for NFC-F poll mode");
+ return NULL;
+ case NCI_MODE_ACTIVE_LISTEN_F:
+ case NCI_MODE_PASSIVE_LISTEN_F:
+ /*
+ * NFCForum-TS-NCI-1.0
+ * Table 59: Specific Parameters for NFC-F Listen Mode
+ *
+ * +=========================================================+
+ * | Offset | Size | Description |
+ * +=========================================================+
+ * | 0 | 1 | Length of Local NFCID2 n (0 or 8) |
+ * | 1 | n | NFCID2 generated by the Local NFCC |
+ * +=========================================================+
+ */
+ if (len > 0 && (bytes[0] + 1) <= len) {
+ NciModeParamListenF* lf = ¶m->listen_f;
+
+ if (bytes[0] == 0) {
+ memset(lf, 0, sizeof(*lf));
+ return param;
+ } else if (bytes[0] == 8) {
+ lf->nfcid2.size = bytes[0];
+ lf->nfcid2.bytes = bytes + 1;
+ return param;
+ }
+ }
+ /* This does happen */
+ GDEBUG("No parameters for NFC-F listen mode");
return NULL;
case NCI_MODE_PASSIVE_POLL_15693:
case NCI_MODE_PASSIVE_LISTEN_15693:
break;
case NCI_MODE_PASSIVE_LISTEN_A:
case NCI_MODE_PASSIVE_LISTEN_B:
- case NCI_MODE_PASSIVE_LISTEN_F:
case NCI_MODE_ACTIVE_LISTEN_A:
- case NCI_MODE_ACTIVE_LISTEN_F:
- /* NCI 1.0 defines no parameters for A/B/F Listen modes */
+ /* NCI 1.0 defines no parameters for A/B Listen modes */
return NULL;
}
- GDEBUG("Unhandled activation mode 0x%x02", mode);
+ GDEBUG("Unhandled activation mode 0x%02x", mode);
return NULL;
}
@@ -327,17 +374,14 @@
const guint8* ats = bytes + 1;
const guint8* ats_end = ats + ats_len;
const guint8* ats_ptr = ats;
+ const guint8* ta = NULL;
+ const guint8* tb = NULL;
+ const guint8* tc = NULL;
const guint8 t0 = *ats_ptr++;
-#define NFC_T4A_ATS_T0_A (0x10) /* TA is transmitted */
-#define NFC_T4A_ATS_T0_B (0x20) /* TB is transmitted */
-#define NFC_T4A_ATS_T0_C (0x30) /* TC is transmitted */
-#define NFC_T4A_ATS_T0_FSCI_MASK (0x0f) /* FSCI mask */
-
- /* Skip TA, TB and TC if they are present */
- if (t0 & NFC_T4A_ATS_T0_A) ats_ptr++;
- if (t0 & NFC_T4A_ATS_T0_B) ats_ptr++;
- if (t0 & NFC_T4A_ATS_T0_C) ats_ptr++;
+ if (t0 & NFC_T4A_ATS_T0_A) ta = ats_ptr++;
+ if (t0 & NFC_T4A_ATS_T0_B) tb = ats_ptr++;
+ if (t0 & NFC_T4A_ATS_T0_C) tc = ats_ptr++;
if (ats_ptr <= ats_end) {
/* NFCForum-TS-DigitalProtocol-1.01
* Table 66: FSCI to FSC Conversion */
@@ -346,6 +390,11 @@
16, 24, 32, 40, 48, 64, 96, 128, 256
};
+ /* Save TA, TB and TC if they are present */
+ param->t0 = t0;
+ if (ta) param->ta = *ta;
+ if (tb) param->tb = *tb;
+ if (tc) param->tc = *tc;
param->fsc = (fsci < G_N_ELEMENTS(fsc_table)) ?
fsc_table[fsci] :
fsc_table[G_N_ELEMENTS(fsc_table) - 1];
@@ -367,6 +416,16 @@
GDEBUG(" T1 =%s", buf->str);
g_string_free(buf, TRUE);
}
+ GDEBUG(" T0 = 0x%02x", param->t0);
+ if (param->t0 & NFC_T4A_ATS_T0_A) {
+ GDEBUG(" TA = 0x%02x", param->ta);
+ }
+ if (param->t0 & NFC_T4A_ATS_T0_B) {
+ GDEBUG(" TB = 0x%02x", param->tb);
+ }
+ if (param->t0 & NFC_T4A_ATS_T0_C) {
+ GDEBUG(" TC = 0x%02x", param->tc);
+ }
}
#endif
return TRUE;
@@ -377,6 +436,66 @@
static
gboolean
+nci_parse_iso_dep_poll_b_param(
+ NciActivationParamIsoDepPollB* param,
+ const guint8* bytes,
+ guint len)
+{
+ /* NFCFrum-TS-NCI-1.0
+ * Table 75: Activation parameters for NFC-B/ISO-DEP Poll Mode
+ *
+ * +============================================================+
+ * | Offset | Size | Description |
+ * +============================================================+
+ * | 0 | 1 | Length of ATTRIB Response Parameter (n) |
+ * | 1 | n | ATTRIB Response |
+ * +============================================================+
+ */
+
+ /* ATTRIB Response */
+ const guint attrib_length = bytes[0];
+
+ if (attrib_length >= 1) {
+ /* NFCForum-TS-DigitalProtocol-1.01
+ * Table 79: ATTRIB Response Format */
+
+#define NFC_T4B_MBLI_MASK (0xF0) /* MBLI Mask */
+#define NFC_T4B_DID_MASK (0x0F) /* DID Mask */
+
+ /* First two octets of the first byte of ATTRIB Response */
+ param->mbli = (bytes[1] & NFC_T4B_MBLI_MASK) >> 4;
+ param->did = (bytes[1] & NFC_T4B_DID_MASK);
+
+ /* Higher Layer Response */
+ if (attrib_length >= 2) {
+ param->hlr.bytes = bytes + 2;
+ param->hlr.size = attrib_length - 1;
+ }
+
+#if GUTIL_LOG_DEBUG
+ if (GLOG_ENABLED(GLOG_LEVEL_DEBUG)) {
+ GDEBUG("ISO-DEP");
+ GDEBUG(" MBLI = %u", param->mbli);
+ GDEBUG(" DID = %u", param->did);
+ if (param->hlr.size > 0) {
+ GString *buf = g_string_new(NULL);
+ guint i;
+
+ for (i = 0; i < param->hlr.size; i++) {
+ g_string_append_printf(buf, " %02x", bytes[i]);
+ }
+ GDEBUG(" HigherLayer Response =%s", buf->str);
+ g_string_free(buf, TRUE);
+ }
+ }
+#endif
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static
+gboolean
nci_parse_nfc_dep_poll_param(
NciActivationParamNfcDepPoll* param,
const guint8* bytes,
@@ -530,6 +649,12 @@
GDEBUG("Failed to parse parameters for NFC-A/ISO-DEP poll mode");
break;
case NCI_MODE_PASSIVE_POLL_B:
+ if (nci_parse_iso_dep_poll_b_param(¶m->iso_dep_poll_b,
+ bytes, len)) {
+ return param;
+ }
+ GDEBUG("Failed to parse parameters for NFC-B/ISO-DEP poll mode");
+ break;
case NCI_MODE_PASSIVE_POLL_F:
case NCI_MODE_ACTIVE_POLL_F:
case NCI_MODE_PASSIVE_POLL_15693:
@@ -725,6 +850,112 @@
return FALSE;
}
+static
+gsize
+nci_mode_param_copy_impl(
+ NciModeParam* dest,
+ const NciModeParam* src,
+ NCI_MODE mode)
+{
+ if (G_LIKELY(src) && G_LIKELY(dest)) {
+ gsize size = sizeof(NciModeParam);
+ const NciModeParamPollB* poll_b = NULL;
+ const NciModeParamListenF* listen_f = NULL;
+
+ switch (mode) {
+ case NCI_MODE_ACTIVE_POLL_A: /* fallthrough */
+ case NCI_MODE_PASSIVE_POLL_A:
+ case NCI_MODE_ACTIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_F:
+ memcpy(dest, src, size);
+ return size;
+ case NCI_MODE_PASSIVE_POLL_B:
+ poll_b = &src->poll_b;
+ memcpy(dest, src, size);
+ if (poll_b->prot_info.bytes) {
+ size = G_ALIGN8(size);
+ guint8* ptr = (guint8*)dest + size;
+
+ memcpy(ptr, poll_b->prot_info.bytes, poll_b->prot_info.size);
+ dest->poll_b.prot_info.bytes = ptr;
+ size += G_ALIGN8(poll_b->prot_info.size);
+ }
+ return size;
+ case NCI_MODE_ACTIVE_LISTEN_F:
+ case NCI_MODE_PASSIVE_LISTEN_F:
+ listen_f = &src->listen_f;
+ memcpy(dest, src, size);
+ if (listen_f->nfcid2.bytes) {
+ size = G_ALIGN8(size);
+ guint8* ptr = (guint8*)dest + size;
+
+ memcpy(ptr, listen_f->nfcid2.bytes, listen_f->nfcid2.size);
+ dest->listen_f.nfcid2.bytes = ptr;
+ size += G_ALIGN8(listen_f->nfcid2.size);
+ }
+ return size;
+ case NCI_MODE_PASSIVE_POLL_15693: /* fallthrough */
+ case NCI_MODE_PASSIVE_LISTEN_15693:
+ break;
+ case NCI_MODE_PASSIVE_LISTEN_A: /* fallthrough */
+ case NCI_MODE_PASSIVE_LISTEN_B:
+ case NCI_MODE_ACTIVE_LISTEN_A:
+ /* NCI 1.0 defines no parameters for A/B Listen modes */
+ return 0;
+ }
+ GDEBUG("Unhandled activation mode 0x%02x", mode);
+ }
+ return 0;
+}
+
+static
+gsize
+nci_mode_param_size(
+ const NciModeParam* param,
+ NCI_MODE mode)
+{
+ gsize size = 0;
+
+ if (G_LIKELY(param)) {
+ const NciModeParamPollB* poll_b = NULL;
+ const NciModeParamListenF* listen_f = NULL;
+
+ switch (mode) {
+ case NCI_MODE_ACTIVE_POLL_A: /* fallthrough */
+ case NCI_MODE_PASSIVE_POLL_A:
+ case NCI_MODE_ACTIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_F:
+ size = sizeof(NciModeParam);
+ break;
+ case NCI_MODE_PASSIVE_POLL_B:
+ size = sizeof(NciModeParam);
+ poll_b = ¶m->poll_b;
+ if (poll_b->prot_info.size) {
+ size = G_ALIGN8(size);
+ size += G_ALIGN8(poll_b->prot_info.size);
+ }
+ break;
+ case NCI_MODE_ACTIVE_LISTEN_F: /* fallthrough */
+ case NCI_MODE_PASSIVE_LISTEN_F:
+ size = sizeof(NciModeParam);
+ listen_f = ¶m->listen_f;
+ if (listen_f->nfcid2.size) {
+ size = G_ALIGN8(size);
+ size += G_ALIGN8(listen_f->nfcid2.size);
+ }
+ break;
+ case NCI_MODE_PASSIVE_POLL_15693: /* fallthrough */
+ case NCI_MODE_PASSIVE_LISTEN_15693:
+ case NCI_MODE_PASSIVE_LISTEN_A:
+ case NCI_MODE_PASSIVE_LISTEN_B:
+ case NCI_MODE_ACTIVE_LISTEN_A:
+ /* NCI 1.0 defines no parameters for A/B Listen modes */
+ break;
+ }
+ }
+ return size;
+}
+
NciDiscoveryNtf*
nci_discovery_ntf_copy_array(
const NciDiscoveryNtf* const* ntfs,
@@ -743,7 +974,8 @@
if (src->param_len) {
size += G_ALIGN8(src->param_len);
if (src->param) {
- size += G_ALIGN8(sizeof(*src->param));
+ size += G_ALIGN8(nci_mode_param_size(src->param,
+ src->mode));
}
}
}
@@ -763,10 +995,16 @@
ptr += G_ALIGN8(src->param_len);
if (src->param) {
NciModeParam* dest_param = (NciModeParam*)ptr;
+ const gsize copied = nci_mode_param_copy_impl(dest_param,
+ src->param, src->mode);
- *dest_param = *src->param;
- dest->param = dest_param;
- ptr += G_ALIGN8(sizeof(*src->param));
+ if (copied) {
+ dest->param = dest_param;
+ ptr += G_ALIGN8(copied);
+ } else {
+ GWARN("ModeParam is not NULL but non copyable");
+ dest->param = NULL;
+ }
}
}
}
@@ -788,6 +1026,159 @@
}
}
+/* Free the result with g_free() */
+NciModeParam*
+nci_util_copy_mode_param(
+ const NciModeParam* param,
+ NCI_MODE mode) /* Since 1.1.13 */
+{
+ if (G_LIKELY(param)) {
+ NciModeParam* copy = NULL;
+ gsize size = nci_mode_param_size(param, mode);
+
+ switch (mode) {
+ case NCI_MODE_ACTIVE_POLL_A: /* fallthrough */
+ case NCI_MODE_PASSIVE_POLL_A:
+ case NCI_MODE_ACTIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_B:
+ case NCI_MODE_ACTIVE_LISTEN_F:
+ case NCI_MODE_PASSIVE_LISTEN_F:
+ if (size) {
+ copy = g_malloc0(size);
+ nci_mode_param_copy_impl(copy, param, mode);
+ }
+ return copy;
+ case NCI_MODE_PASSIVE_POLL_15693: /* fallthrough */
+ case NCI_MODE_PASSIVE_LISTEN_15693:
+ break;
+ case NCI_MODE_PASSIVE_LISTEN_A: /* fallthrough */
+ case NCI_MODE_PASSIVE_LISTEN_B:
+ case NCI_MODE_ACTIVE_LISTEN_A:
+ /* NCI 1.0 defines no parameters for A/B Listen modes */
+ return NULL;
+ }
+ GDEBUG("Unhandled activation mode 0x%02x", mode);
+ }
+ return NULL;
+}
+
+/* Free the result with g_free() */
+NciActivationParam*
+nci_util_copy_activation_param(
+ const NciActivationParam* param,
+ NCI_RF_INTERFACE intf,
+ NCI_MODE mode) /* Since 1.1.13 */
+{
+ if (G_LIKELY(param)) {
+ NciActivationParam* copy = NULL;
+ gsize size = sizeof(NciActivationParam);
+ const NciActivationParamIsoDepPollA* iso_dep_poll_a = NULL;
+ const NciActivationParamIsoDepPollB* iso_dep_poll_b = NULL;
+ const NciActivationParamNfcDepPoll* nfc_dep_poll = NULL;
+ const NciActivationParamNfcDepListen* nfc_dep_listen = NULL;
+
+ switch (intf) {
+ case NCI_RF_INTERFACE_ISO_DEP:
+ switch (mode) {
+ case NCI_MODE_PASSIVE_POLL_A:
+ case NCI_MODE_ACTIVE_POLL_A:
+ iso_dep_poll_a = ¶m->iso_dep_poll_a;
+ if (iso_dep_poll_a->t1.size) {
+ size = G_ALIGN8(size);
+ size += G_ALIGN8(iso_dep_poll_a->t1.size);
+ }
+ copy = g_malloc0(size);
+ memcpy(copy, param, sizeof(NciActivationParam));
+ if (iso_dep_poll_a->t1.bytes) {
+ guint8* dest = (guint8*)copy +
+ G_ALIGN8(sizeof(NciActivationParam));
+ memcpy(dest, iso_dep_poll_a->t1.bytes,
+ iso_dep_poll_a->t1.size);
+ copy->iso_dep_poll_a.t1.bytes = dest;
+ }
+ return copy;
+ case NCI_MODE_PASSIVE_POLL_B:
+ iso_dep_poll_b = ¶m->iso_dep_poll_b;
+ if (iso_dep_poll_b->hlr.size) {
+ size = G_ALIGN8(size);
+ size += G_ALIGN8(iso_dep_poll_b->hlr.size);
+ }
+ copy = g_malloc0(size);
+ memcpy(copy, param, sizeof(NciActivationParam));
+ if (iso_dep_poll_b->hlr.bytes) {
+ guint8* dest = (guint8*)copy +
+ G_ALIGN8(sizeof(NciActivationParam));
+ memcpy(dest, iso_dep_poll_b->hlr.bytes,
+ iso_dep_poll_b->hlr.size);
+ copy->iso_dep_poll_b.hlr.bytes = dest;
+ }
+ return copy;
+ case NCI_MODE_PASSIVE_POLL_F:
+ case NCI_MODE_ACTIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_15693:
+ case NCI_MODE_PASSIVE_LISTEN_A:
+ case NCI_MODE_PASSIVE_LISTEN_B:
+ case NCI_MODE_PASSIVE_LISTEN_F:
+ case NCI_MODE_ACTIVE_LISTEN_A:
+ case NCI_MODE_ACTIVE_LISTEN_F:
+ case NCI_MODE_PASSIVE_LISTEN_15693:
+ break;
+ }
+ break;
+ case NCI_RF_INTERFACE_FRAME:
+ /* There are no Activation Parameters for Frame RF interface */
+ break;
+ case NCI_RF_INTERFACE_NFC_DEP:
+ switch (mode) {
+ case NCI_MODE_ACTIVE_POLL_A:
+ case NCI_MODE_ACTIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_A:
+ case NCI_MODE_PASSIVE_POLL_F:
+ nfc_dep_poll = ¶m->nfc_dep_poll;
+ size += G_ALIGN8(nfc_dep_poll->g.size);
+ copy = g_malloc0(size);
+ memcpy(copy, param, sizeof(NciActivationParam));
+ if (nfc_dep_poll->g.bytes) {
+ guint8* dest = (guint8*)copy +
+ G_ALIGN8(sizeof(NciActivationParam));
+ memcpy(dest, nfc_dep_poll->g.bytes,
+ nfc_dep_poll->g.size);
+ copy->nfc_dep_poll.g.bytes = dest;
+ }
+ return copy;
+ case NCI_MODE_ACTIVE_LISTEN_A:
+ case NCI_MODE_ACTIVE_LISTEN_F:
+ case NCI_MODE_PASSIVE_LISTEN_A:
+ case NCI_MODE_PASSIVE_LISTEN_F:
+ nfc_dep_listen = ¶m->nfc_dep_listen;
+ size += G_ALIGN8(nfc_dep_listen->g.size);
+ copy = g_malloc0(size);
+ memcpy(copy, param, sizeof(NciActivationParam));
+ if (nfc_dep_listen->g.bytes) {
+ guint8* dest = (guint8*)copy +
+ G_ALIGN8(sizeof(NciActivationParam));
+ memcpy(dest, nfc_dep_listen->g.bytes,
+ nfc_dep_listen->g.size);
+ copy->nfc_dep_listen.g.bytes = dest;
+ }
+ return copy;
+ case NCI_MODE_PASSIVE_POLL_B:
+ case NCI_MODE_PASSIVE_POLL_15693:
+ case NCI_MODE_PASSIVE_LISTEN_B:
+ case NCI_MODE_PASSIVE_LISTEN_15693:
+ break;
+ }
+ break;
+ case NCI_RF_INTERFACE_NFCEE_DIRECT:
+ case NCI_RF_INTERFACE_PROPRIETARY:
+ GDEBUG("Unhandled interface type");
+ break;
+ }
+ }
+ return NULL;
+}
+
/*
* Local Variables:
* mode: C
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.14.tar.bz2/src/nci_util_p.h
^
|
@@ -0,0 +1,89 @@
+/*
+ * 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:
+ *
+ * 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 NCI_UTIL_PRIVATE_H
+#define NCI_UTIL_PRIVATE_H
+
+#include <nci_util.h>
+#include "nci_types_p.h"
+
+gboolean
+nci_listen_mode(
+ NCI_MODE mode)
+ NCI_INTERNAL;
+
+const NciModeParam*
+nci_parse_mode_param(
+ NciModeParam* param,
+ NCI_MODE mode,
+ const guint8* bytes,
+ guint len)
+ NCI_INTERNAL;
+
+gboolean
+nci_parse_discover_ntf(
+ NciDiscoveryNtf* ntf,
+ NciModeParam* param,
+ const guint8* bytes,
+ guint len)
+ NCI_INTERNAL;
+
+gboolean
+nci_parse_intf_activated_ntf(
+ NciIntfActivationNtf* ntf,
+ NciModeParam* mode_param,
+ NciActivationParam* activation_param,
+ const guint8* pkt,
+ guint len)
+ NCI_INTERNAL;
+
+NciDiscoveryNtf*
+nci_discovery_ntf_copy_array(
+ const NciDiscoveryNtf* const* ntfs,
+ guint count)
+ NCI_INTERNAL;
+
+NciDiscoveryNtf*
+nci_discovery_ntf_copy(
+ const NciDiscoveryNtf* ntf)
+ NCI_INTERNAL;
+
+#endif /* NCI_UTIL_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.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:
*
@@ -48,11 +48,19 @@
char* argv[]);
/* Run loop with a timeout */
+guint
+test_setup_timeout(
+ const TestOpt* opt);
+
void
-test_run(
+test_run_loop(
const TestOpt* opt,
GMainLoop* loop);
+void
+test_run(
+ const TestOpt* opt);
+
/* Quits the event loop on the next iteration (or after n iterations) */
void
test_quit_later(
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.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:
*
@@ -39,7 +39,7 @@
test_timeout_expired(
gpointer data)
{
- g_assert(!"TIMEOUT");
+ g_assert_not_reached();
return G_SOURCE_REMOVE;
}
@@ -95,22 +95,39 @@
test_quit_later_n(loop, 0);
}
+guint
+test_setup_timeout(
+ const TestOpt* opt)
+{
+ return g_timeout_add_seconds(TEST_TIMEOUT_SEC, test_timeout_expired, NULL);
+}
+
void
-test_run(
+test_run_loop(
const TestOpt* opt,
GMainLoop* loop)
{
if (opt->flags & TEST_FLAG_DEBUG) {
g_main_loop_run(loop);
} else {
- const guint timeout_id = g_timeout_add_seconds(TEST_TIMEOUT_SEC,
- test_timeout_expired, NULL);
+ const guint timeout_id = test_setup_timeout(opt);
+
g_main_loop_run(loop);
g_source_remove(timeout_id);
}
}
void
+test_run(
+ const TestOpt* opt)
+{
+ GMainLoop* loop = g_main_loop_new(NULL, TRUE);
+
+ test_run_loop(opt, loop);
+ g_main_loop_unref(loop);
+}
+
+void
test_init(
TestOpt* opt,
int argc,
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/unit/nci_core/test_nci_core.c
^
|
@@ -43,7 +43,6 @@
static TestOpt test_opt;
-#define TEST_TIMEOUT (20) /* seconds */
#define TEST_DEFAULT_CMD_TIMEOUT (10000) /* milliseconds */
static const guint8 CORE_RESET_RSP[] = {
@@ -118,8 +117,23 @@
0x40, 0x01, 0x00
};
static const guint8 CORE_GET_CONFIG_RSP[] = {
- 0x40, 0x03, 0x0b, 0x00, 0x03, 0x08, 0x01, 0x00,
- 0x11, 0x01, 0x00, 0x22, 0x01, 0x00
+ 0x40, 0x03, 0x08, 0x00, 0x02, 0x08, 0x01, 0x00,
+ 0x11, 0x01, 0x00
+};
+static const guint8 CORE_GET_CONFIG_RSP_DEFAULT_DURATION[] = {
+ 0x40, 0x03, 0x06, 0x00, 0x01, 0x00, 0x02, 0xf4, 0x01
+};
+static const guint8 CORE_GET_CONFIG_RSP_WRONG_DURATION[] = {
+ 0x40, 0x03, 0x06, 0x00, 0x01, 0x00, 0x02, 0xe8, 0x03
+};
+static const guint8 CORE_GET_CONFIG_RSP_BROKEN_DURATION_1[] = {
+ 0x40, 0x03, 0x05, 0x00, 0x01, 0x00, 0x02, 0xf4
+};
+static const guint8 CORE_GET_CONFIG_RSP_BROKEN_DURATION_2[] = {
+ 0x40, 0x03, 0x05, 0x00, 0x01, 0x00, 0x01, 0xf4
+};
+static const guint8 CORE_GET_CONFIG_RSP_BROKEN_DURATION_3[] = {
+ 0x40, 0x03, 0x03, 0x00, 0x01, 0x00
};
static const guint8 CORE_GET_CONFIG_RSP_ERROR[] = {
0x40, 0x03, 0x02, 0x03, 0x00
@@ -281,6 +295,9 @@
static const guint8 CORE_INTERFACE_GENERIC_ERROR_NTF[] = {
0x60, 0x08, 0x02, NCI_STATUS_FAILED, 0x00
};
+static const guint8 CORE_INTERFACE_SYNTAX_ERROR_NTF[] = {
+ 0x60, 0x08, 0x02, NCI_STATUS_SYNTAX_ERROR, 0x00
+};
static const guint8 CORE_INTERFACE_TRANSMISSION_ERROR_NTF[] = {
0x60, 0x08, 0x02, NCI_RF_TRANSMISSION_ERROR, 0x00
};
@@ -332,27 +349,6 @@
};
static
-gboolean
-test_timeout(
- gpointer loop)
-{
- g_assert(!"TIMEOUT");
- 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_bytes_unref(
gpointer bytes)
@@ -777,7 +773,6 @@
TestHalIo* hal = test_hal_io_new();
NciCore* nci = nci_core_new(&hal->io);
GMainLoop* loop = g_main_loop_new(NULL, TRUE);
- guint timeout_id = test_setup_timeout(loop);
gulong id;
nci->cmd_timeout = (test_opt.flags & TEST_FLAG_DEBUG) ? 0 :
@@ -794,10 +789,7 @@
test_restart_done, loop);
nci_core_restart(nci);
- g_main_loop_run(loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run_loop(&test_opt, loop);
g_assert(nci->current_state == NCI_RFST_IDLE);
g_assert(nci->next_state == NCI_RFST_IDLE);
@@ -830,7 +822,6 @@
TestHalIo* hal = test_hal_io_new();
NciCore* nci = nci_core_new(&hal->io);
GMainLoop* loop = g_main_loop_new(NULL, TRUE);
- guint timeout_id;
gulong id[2];
/* Second time does nothing */
@@ -866,11 +857,7 @@
g_assert(id[0]);
g_assert(id[1]);
- timeout_id = test_setup_timeout(loop);
- g_main_loop_run(loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run_loop(&test_opt, loop);
g_assert(nci->current_state == NCI_RFST_IDLE);
g_assert(nci->next_state == NCI_RFST_IDLE);
@@ -903,18 +890,13 @@
{
NciCore* nci = nci_core_new(&test_dummy_hal_io);
GMainLoop* loop = g_main_loop_new(NULL, TRUE);
- guint timeout_id;
gulong id;
nci_core_set_state(nci, NCI_RFST_IDLE);
id = nci_core_add_current_state_changed_handler(nci,
test_init_failed1_done, loop);
- timeout_id = test_setup_timeout(loop);
- g_main_loop_run(loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run_loop(&test_opt, loop);
g_assert(nci->current_state == NCI_STATE_ERROR);
g_assert(nci->next_state == NCI_STATE_ERROR);
@@ -945,7 +927,6 @@
TestHalIo* hal = test_hal_io_new();
NciCore* nci;
GMainLoop* loop;
- guint timeout_id;
gulong id;
hal->fail_write++;
@@ -955,11 +936,7 @@
id = nci_core_add_current_state_changed_handler(nci,
test_init_failed2_done, loop);
- timeout_id = test_setup_timeout(loop);
- g_main_loop_run(loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run_loop(&test_opt, loop);
g_assert(nci->current_state == NCI_STATE_ERROR);
g_assert(nci->next_state == NCI_STATE_ERROR);
@@ -1229,7 +1206,7 @@
test.nci->cmd_timeout = (test_opt.flags & TEST_FLAG_DEBUG) ? 0 :
TEST_DEFAULT_CMD_TIMEOUT;
- timeout_id = test_setup_timeout(test.loop);
+ timeout_id = test_setup_timeout(&test_opt);
while (test.entry->func) {
test.entry->func(&test);
test.entry++;
@@ -1245,7 +1222,16 @@
/* State machine tests */
-static const TestSmEntry test_nci_sm_init_ok[] = {
+static const TestSmEntry test_nci_sm_init_ok_default_duration[] = {
+ TEST_NCI_SM_SET_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_QUEUE_RSP(CORE_RESET_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_INIT_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_GET_CONFIG_RSP_DEFAULT_DURATION),
+ TEST_NCI_SM_WAIT_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_END()
+};
+
+static const TestSmEntry test_nci_sm_init_ok_no_duration[] = {
TEST_NCI_SM_SET_STATE(NCI_RFST_IDLE),
TEST_NCI_SM_QUEUE_RSP(CORE_RESET_RSP),
TEST_NCI_SM_QUEUE_RSP(CORE_INIT_RSP),
@@ -1255,6 +1241,46 @@
TEST_NCI_SM_END()
};
+static const TestSmEntry test_nci_sm_init_ok_wrong_duration[] = {
+ TEST_NCI_SM_SET_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_QUEUE_RSP(CORE_RESET_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_INIT_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_GET_CONFIG_RSP_WRONG_DURATION),
+ TEST_NCI_SM_QUEUE_RSP(CORE_SET_CONFIG_RSP),
+ TEST_NCI_SM_WAIT_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_END()
+};
+
+static const TestSmEntry test_nci_sm_init_ok_broken_duration1[] = {
+ TEST_NCI_SM_SET_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_QUEUE_RSP(CORE_RESET_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_INIT_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_GET_CONFIG_RSP_BROKEN_DURATION_1),
+ TEST_NCI_SM_QUEUE_RSP(CORE_SET_CONFIG_RSP),
+ TEST_NCI_SM_WAIT_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_END()
+};
+
+static const TestSmEntry test_nci_sm_init_ok_broken_duration2[] = {
+ TEST_NCI_SM_SET_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_QUEUE_RSP(CORE_RESET_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_INIT_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_GET_CONFIG_RSP_BROKEN_DURATION_2),
+ TEST_NCI_SM_QUEUE_RSP(CORE_SET_CONFIG_RSP),
+ TEST_NCI_SM_WAIT_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_END()
+};
+
+static const TestSmEntry test_nci_sm_init_ok_broken_duration3[] = {
+ TEST_NCI_SM_SET_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_QUEUE_RSP(CORE_RESET_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_INIT_RSP),
+ TEST_NCI_SM_QUEUE_RSP(CORE_GET_CONFIG_RSP_BROKEN_DURATION_3),
+ TEST_NCI_SM_QUEUE_RSP(CORE_SET_CONFIG_RSP),
+ TEST_NCI_SM_WAIT_STATE(NCI_RFST_IDLE),
+ TEST_NCI_SM_END()
+};
+
static const TestSmEntry test_nci_sm_init_timeout[] = {
TEST_NCI_SM_SET_TIMEOUT(500),
TEST_NCI_SM_SET_STATE(NCI_RFST_IDLE),
@@ -2060,6 +2086,18 @@
NCI_PROTOCOL_ISO_DEP, NCI_MODE_PASSIVE_POLL_A),
TEST_NCI_SM_WAIT_STATE(NCI_RFST_POLL_ACTIVE),
+ /* Back to DISCOVERY */
+ TEST_NCI_SM_QUEUE_NTF(CORE_INTERFACE_SYNTAX_ERROR_NTF),
+ TEST_NCI_SM_QUEUE_RSP(RF_DEACTIVATE_RSP),
+ TEST_NCI_SM_QUEUE_NTF(RF_DEACTIVATE_NTF_DISCOVERY),
+ TEST_NCI_SM_WAIT_STATE(NCI_RFST_DISCOVERY),
+
+ /* Activation 5 */
+ TEST_NCI_SM_QUEUE_NTF(RF_INTF_ACTIVATED_NTF_T4A),
+ TEST_NCI_SM_WAIT_ACTIVATION(NCI_RF_INTERFACE_ISO_DEP,
+ NCI_PROTOCOL_ISO_DEP, NCI_MODE_PASSIVE_POLL_A),
+ TEST_NCI_SM_WAIT_STATE(NCI_RFST_POLL_ACTIVE),
+
/* Deactivate to IDLE */
TEST_NCI_SM_SET_STATE(NCI_RFST_IDLE),
TEST_NCI_SM_ASSERT_STATES(NCI_RFST_POLL_ACTIVE, NCI_RFST_IDLE),
@@ -2408,6 +2446,15 @@
TEST_NCI_SM_QUEUE_NTF(RF_DEACTIVATE_NTF_DISCOVERY),
TEST_NCI_SM_WAIT_STATE(NCI_RFST_DISCOVERY),
+ TEST_NCI_SM_QUEUE_NTF(RF_INTF_ACTIVATED_NTF_NFC_DEP_LISTEN_A),
+ TEST_NCI_SM_WAIT_ACTIVATION(NCI_RF_INTERFACE_NFC_DEP,
+ NCI_PROTOCOL_NFC_DEP, NCI_MODE_ACTIVE_LISTEN_A),
+ TEST_NCI_SM_WAIT_STATE(NCI_RFST_LISTEN_ACTIVE),
+ TEST_NCI_SM_QUEUE_NTF(CORE_INTERFACE_SYNTAX_ERROR_NTF),
+ TEST_NCI_SM_QUEUE_RSP(RF_DEACTIVATE_RSP),
+ TEST_NCI_SM_QUEUE_NTF(RF_DEACTIVATE_NTF_DISCOVERY),
+ TEST_NCI_SM_WAIT_STATE(NCI_RFST_DISCOVERY),
+
TEST_NCI_SM_END()
};
@@ -2484,7 +2531,12 @@
};
static const TestNciSmData nci_sm_tests[] = {
- { "init-ok", test_nci_sm_init_ok },
+ { "init-ok-no-duration", test_nci_sm_init_ok_no_duration },
+ { "init-ok-default-duration", test_nci_sm_init_ok_default_duration },
+ { "init-ok-wrong-duration", test_nci_sm_init_ok_wrong_duration },
+ { "init-ok-broken-duration1", test_nci_sm_init_ok_broken_duration1 },
+ { "init-ok-broken-duration2", test_nci_sm_init_ok_broken_duration2 },
+ { "init-ok-broken-duration3", test_nci_sm_init_ok_broken_duration3 },
{ "init-timeout", test_nci_sm_init_timeout },
{ "get-config-timeout", test_nci_sm_get_config_timeout },
{ "set-config-timeout", test_nci_sm_set_config_timeout },
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/unit/nci_sar/test_nci_sar.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:
*
@@ -41,33 +41,10 @@
static TestOpt test_opt;
-#define TEST_TIMEOUT (10) /* seconds */
-
#define TEST_GID (0x01)
#define TEST_OID (0x02)
static
-gboolean
-test_timeout(
- gpointer loop)
-{
- g_assert(!"TIMEOUT");
- 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_bytes_unref(
gpointer bytes)
@@ -398,7 +375,8 @@
void)
{
nci_sar_set_max_logical_connections(NULL, 0);
- nci_sar_set_max_control_packet_size(NULL, 0);
+ nci_sar_set_max_control_payload_size(NULL, 0);
+ nci_sar_set_max_data_payload_size(NULL, 0);
g_assert(!nci_sar_send_command(NULL, 0, 0, NULL, NULL, NULL, NULL));
g_assert(!nci_sar_send_data_packet(NULL, 0, NULL, NULL, NULL, NULL));
g_assert(!nci_sar_start(NULL));
@@ -438,7 +416,6 @@
{
NciSar* sar;
TestFailClient test;
- guint timeout_id;
memset(&test, 0, sizeof(test));
test.client.fn = &test_dummy_sar_client_fn;
@@ -454,11 +431,7 @@
nci_sar_cancel(sar, 112345); /* Invalid ID */
test.loop = g_main_loop_new(NULL, TRUE);
- timeout_id = test_setup_timeout(test.loop);
- g_main_loop_run(test.loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
+ test_run_loop(&test_opt, test.loop);
nci_sar_free(sar);
g_main_loop_unref(test.loop);
@@ -510,7 +483,6 @@
NciSar* sar;
TestHalIo* test_io = test_hal_io_new();
TestBasicClient test;
- guint timeout_id;
memset(&test, 0, sizeof(test));
test.client.fn = &test_basic_sar_client_fn;
@@ -520,8 +492,8 @@
nci_sar_set_max_logical_connections(sar, 1);
nci_sar_set_max_logical_connections(sar, 3);
nci_sar_set_max_logical_connections(sar, 2);
- nci_sar_set_max_control_packet_size(sar, 0);
- nci_sar_set_max_control_packet_size(sar, 0xff);
+ nci_sar_set_max_control_payload_size(sar, 0);
+ nci_sar_set_max_control_payload_size(sar, 0xff);
nci_sar_set_initial_credits(sar, 42, 1); /* Invalid cid */
nci_sar_set_initial_credits(sar, 0, 0xfe);
nci_sar_add_credits(sar, 0, 1);
@@ -536,8 +508,7 @@
nci_sar_add_credits(sar, 42, 1); /* Invalid cid */
test.loop = g_main_loop_new(NULL, TRUE);
- timeout_id = test_setup_timeout(test.loop);
- g_main_loop_run(test.loop);
+ test_run_loop(&test_opt, test.loop);
/* Signal error */
g_assert(test_io->sar);
@@ -546,9 +517,6 @@
nci_sar_reset(sar);
g_assert(test_io->written->len == 3);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
nci_sar_free(sar);
test_hal_io_free(test_io);
@@ -613,19 +581,28 @@
.cancel_write = test_hal_io_cancel_write
};
- /* Set MTU to minimum and send one byte of payload per packet */
- static const guint8 payload[] = { 0x01, 0x02 };
+ /* Set MTU to minimum and send 32 bytes of payload per packet */
+ static const guint8 payload[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
+ };
GBytes* payload_bytes = g_bytes_new_static(payload, sizeof(payload));
TestHalIo* test_io = test_hal_io_new_with_functions(&hal_io_fn);
TestSendSegData test;
- guint timeout_id, i;
+ guint i;
memset(&test, 0, sizeof(test));
test.client.fn = &test_dummy_sar_client_fn;
test_io->test_data = &test;
test.sar = nci_sar_new(&test_io->io, &test.client);
- nci_sar_set_max_control_packet_size(test.sar, 3); /* Actually sets 4 */
+ nci_sar_set_max_control_payload_size(test.sar, 1); /* Actually 32 */
test.send_id = nci_sar_send_command(test.sar, TEST_GID, TEST_OID,
payload_bytes, test_client_unexpected_completion, NULL, NULL);
g_assert(test.send_id);
@@ -633,23 +610,19 @@
payload_bytes, test_send_seg_expect_success_and_quit, NULL, NULL));
test.loop = g_main_loop_new(NULL, TRUE);
- timeout_id = test_setup_timeout(test.loop);
- g_main_loop_run(test.loop);
+ test_run_loop(&test_opt, test.loop);
/* The same data have been sent twice */
- g_assert(test_io->written->len == 2*sizeof(payload));
+ g_assert_cmpuint(test_io->written->len, == ,4);
for (i = 0; i < test_io->written->len; i++) {
GBytes* packet = test_io->written->pdata[i];
gsize packet_size;
const guint8* packet_data = g_bytes_get_data(packet, &packet_size);
- g_assert(packet_size == 4);
- g_assert(packet_data[3] == payload[i % sizeof(payload)]);
+ g_assert_cmpuint(packet_size, == , 35 /* Minimum size + header */);
+ g_assert(!memcmp(packet_data + 3, payload + (i % 2) * 32, 32));
}
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
nci_sar_free(test.sar);
test_hal_io_free(test_io);
@@ -658,6 +631,210 @@
}
/*==========================================================================*
+ * send_data_seg
+ *==========================================================================*/
+
+static
+void
+test_send_data_seg_expect_success_and_quit(
+ NciSarClient* client,
+ gboolean success,
+ gpointer user_data)
+{
+ g_assert(success);
+ g_main_loop_quit(user_data);
+}
+
+static
+void
+test_send_data_seg(
+ void)
+{
+ /* Set MTU to minimum and send one byte of payload per data packet */
+ static const guint8 payload[] = { 0x01, 0x02, 0x03 };
+ GBytes* payload_bytes = g_bytes_new_static(payload, sizeof(payload));
+ NciSarClient client;
+ TestHalIo* test_io = test_hal_io_new();
+ NciSar* sar = nci_sar_new(&test_io->io, &client);
+ GMainLoop* loop = g_main_loop_new(NULL, TRUE);
+ guint i;
+ gsize packet_size;
+ const guint8* packet_data;
+
+ client.fn = &test_dummy_sar_client_fn;
+ nci_sar_set_max_data_payload_size(sar, 0 /* Default is 1 byte */);
+ g_assert(nci_sar_send_data_packet(sar, NCI_STATIC_RF_CONN_ID,
+ payload_bytes, test_send_data_seg_expect_success_and_quit,
+ NULL, loop));
+ nci_sar_add_credits(sar, NCI_STATIC_RF_CONN_ID, 3);
+
+ test_run_loop(&test_opt, loop);
+
+ /* One byte per packet with minimum MTU */
+ g_assert_cmpuint(test_io->written->len, == ,sizeof(payload));
+ for (i = 0; i < test_io->written->len; i++) {
+ packet_data = g_bytes_get_data(test_io->written->pdata[i],
+ &packet_size);
+ g_assert_cmpuint(packet_size, == ,4);
+ g_assert_cmpuint(packet_data[3], == ,payload[i % sizeof(payload)]);
+ }
+
+ /* Set the max packet size */
+ nci_sar_set_max_data_payload_size(sar, 0xff);
+ g_ptr_array_set_size(test_io->written, 0);
+
+ /* This time packet gets delivered in one piece */
+ nci_sar_add_credits(sar, NCI_STATIC_RF_CONN_ID, 1);
+ g_assert(nci_sar_send_data_packet(sar, NCI_STATIC_RF_CONN_ID,
+ payload_bytes, test_send_data_seg_expect_success_and_quit,
+ NULL, loop));
+ test_run_loop(&test_opt, loop);
+ g_assert_cmpuint(test_io->written->len, == ,1);
+ packet_data = g_bytes_get_data(test_io->written->pdata[0], &packet_size);
+ g_assert_cmpuint(packet_size, == ,3 + sizeof(payload));
+ g_assert(!memcmp(packet_data + 3, payload, sizeof(payload)));
+
+ nci_sar_free(sar);
+ test_hal_io_free(test_io);
+ g_main_loop_unref(loop);
+ g_bytes_unref(payload_bytes);
+}
+
+/*==========================================================================*
+ * send_data_seg2
+ *==========================================================================*/
+
+static
+void
+test_send_data_seg2(
+ void)
+{
+ /* Set MTU to minimum and send one byte of payload per data packet */
+ static const guint8 payload[] = { 0x01, 0x02, 0x03 };
+ GBytes* payload_bytes = g_bytes_new_static(payload, sizeof(payload));
+ NciSarClient client;
+ TestHalIo* test_io = test_hal_io_new();
+ NciSar* sar = nci_sar_new(&test_io->io, &client);
+ GMainLoop* loop = g_main_loop_new(NULL, TRUE);
+ guint i;
+ gsize packet_size;
+ const guint8* packet_data;
+
+ client.fn = &test_dummy_sar_client_fn;
+ nci_sar_set_max_data_payload_size(sar, 0 /* Default is 1 byte */);
+ g_assert(nci_sar_send_data_packet(sar, NCI_STATIC_RF_CONN_ID,
+ payload_bytes, test_send_data_seg_expect_success_and_quit,
+ NULL, loop));
+ nci_sar_add_credits(sar, NCI_STATIC_RF_CONN_ID, 2);
+
+ /* Send first 2 segments */
+ test_quit_later_n(loop, 10);
+ test_run_loop(&test_opt, loop);
+
+ /* One byte per packet with minimum MTU */
+ g_assert_cmpuint(test_io->written->len, == ,2);
+ for (i = 0; i < test_io->written->len; i++) {
+ packet_data = g_bytes_get_data(test_io->written->pdata[i],
+ &packet_size);
+ g_assert_cmpuint(packet_size, == ,4);
+ g_assert_cmpuint(packet_data[3], == ,payload[i % sizeof(payload)]);
+ }
+
+ /* And the last segment */
+ nci_sar_add_credits(sar, NCI_STATIC_RF_CONN_ID, 1);
+ test_run_loop(&test_opt, loop);
+
+ /* Now the last bytes is sent too */
+ g_assert_cmpuint(test_io->written->len, == ,i+1);
+ packet_data = g_bytes_get_data(test_io->written->pdata[i], &packet_size);
+ g_assert_cmpuint(packet_size, == ,4);
+ g_assert_cmpuint(packet_data[3], == ,payload[i % sizeof(payload)]);
+
+ nci_sar_free(sar);
+ test_hal_io_free(test_io);
+ g_main_loop_unref(loop);
+ g_bytes_unref(payload_bytes);
+}
+
+/*==========================================================================*
+ * send_data_seg3
+ *==========================================================================*/
+
+static
+void
+test_send_data_seg3(
+ void)
+{
+ /* Set MTU to minimum and send one byte of payload per data packet */
+ static const guint8 payload[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x03, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x13, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x23, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x33, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43, 0x43, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+ 0x50, 0x51, 0x52, 0x53, 0x53, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+ 0x60, 0x61, 0x62, 0x63, 0x63, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x73, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x83, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x93, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa3, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb3, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc3, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd3, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe3, 0xe5, 0xe6, 0xe7,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf3, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+ 0x00, 0x01, 0x02, 0x03, 0x03, 0x05, 0x06, 0x07
+ };
+ GBytes* payload_bytes = g_bytes_new_static(payload, sizeof(payload));
+ NciSarClient client;
+ TestHalIo* test_io = test_hal_io_new();
+ NciSar* sar = nci_sar_new(&test_io->io, &client);
+ GMainLoop* loop = g_main_loop_new(NULL, TRUE);
+ guint i;
+ gsize packet_size;
+ const guint8* packet_data;
+
+ client.fn = &test_dummy_sar_client_fn;
+ nci_sar_set_initial_credits(sar, 0, 0xff); /* Unlimited credits */
+ nci_sar_set_max_data_payload_size(sar, 0 /* Default is 1 byte */);
+ g_assert(nci_sar_send_data_packet(sar, NCI_STATIC_RF_CONN_ID,
+ payload_bytes, test_send_data_seg_expect_success_and_quit,
+ NULL, loop));
+
+ test_run_loop(&test_opt, loop);
+
+ /* One byte per packet with minimum MTU */
+ g_assert_cmpuint(test_io->written->len, == ,sizeof(payload));
+ for (i = 0; i < test_io->written->len; i++) {
+ packet_data = g_bytes_get_data(test_io->written->pdata[i],
+ &packet_size);
+ g_assert_cmpuint(packet_size, == ,4);
+ g_assert_cmpuint(packet_data[3], == ,payload[i % sizeof(payload)]);
+ }
+
+ nci_sar_free(sar);
+ test_hal_io_free(test_io);
+ g_main_loop_unref(loop);
+ g_bytes_unref(payload_bytes);
+}
+
+/*==========================================================================*
* send_err
*==========================================================================*/
@@ -783,12 +960,10 @@
TestSendErrHalIo* test_io = test_send_err_hal_io_new();
TestSendErrSarClient test;
NciSar* sar;
- guint timeout_id;
memset(&test, 0, sizeof(test));
test.client.fn = &test_send_err_sar_client_fn;
test.loop = g_main_loop_new(NULL, TRUE);
- timeout_id = test_setup_timeout(test.loop);
sar = nci_sar_new(&test_io->io, &test.client);
g_assert(nci_sar_start(sar));
@@ -798,17 +973,13 @@
g_assert(nci_sar_send_command(sar, TEST_GID, TEST_OID, NULL,
NULL, NULL, NULL));
- g_main_loop_run(test.loop);
+ test_run_loop(&test_opt, test.loop);
/* Same thing but with a completion callback */
g_assert(nci_sar_send_command(sar, TEST_GID, TEST_OID, NULL,
test_send_err_sar_send_complete, NULL, &test));
- g_main_loop_run(test.loop);
- if (timeout_id) {
- g_source_remove(timeout_id);
- }
-
+ test_run_loop(&test_opt, test.loop);
nci_sar_free(sar);
test_send_err_hal_io(test_io);
g_main_loop_unref(test.loop);
@@ -1462,6 +1633,9 @@
g_test_add_func(TEST_("fail"), test_fail);
g_test_add_func(TEST_("basic"), test_basic);
g_test_add_func(TEST_("send_seg"), test_send_seg);
+ g_test_add_func(TEST_("send_data_seg"), test_send_data_seg);
+ g_test_add_func(TEST_("send_data_seg2"), test_send_data_seg2);
+ g_test_add_func(TEST_("send_data_seg3"), test_send_data_seg3);
g_test_add_func(TEST_("send_err"), test_send_err);
g_test_add_func(TEST_("recv_ntf"), test_recv_ntf);
g_test_add_func(TEST_("recv_ntf_data"), test_recv_ntf_data);
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/unit/nci_sm/test_nci_sm.c
^
|
@@ -316,8 +316,7 @@
nci_transition_deactivate_to_discovery_new(sm);
NciTransition* deactivate_to_idle =
nci_transition_deactivate_to_idle_new(sm);
- NciTransition* poll_active_to_idle =
- nci_transition_poll_active_to_idle_new(sm);
+ NciTransition* active_to_idle = nci_transition_active_to_idle_new(sm);
g_assert(!nci_param_w4_all_discoveries_new(NULL));
@@ -325,7 +324,7 @@
g_assert(!nci_transition_idle_to_discovery_new(NULL));
g_assert(!nci_transition_deactivate_to_discovery_new(NULL));
g_assert(!nci_transition_deactivate_to_idle_new(NULL));
- g_assert(!nci_transition_poll_active_to_idle_new(NULL));
+ g_assert(!nci_transition_active_to_idle_new(NULL));
g_assert(!nci_transition_sm(null));
g_assert(!nci_transition_ref(null));
nci_transition_unref(null);
@@ -349,13 +348,13 @@
g_assert(!nci_transition_start(idle_to_discovery));
g_assert(!nci_transition_start(deactivate_to_discovery));
g_assert(!nci_transition_start(deactivate_to_idle));
- g_assert(!nci_transition_start(poll_active_to_idle));
+ g_assert(!nci_transition_start(active_to_idle));
nci_transition_unref(reset);
nci_transition_unref(idle_to_discovery);
nci_transition_unref(deactivate_to_discovery);
nci_transition_unref(deactivate_to_idle);
- nci_transition_unref(poll_active_to_idle);
+ nci_transition_unref(active_to_idle);
}
/*==========================================================================*
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.14.tar.bz2/unit/nci_util/test_nci_util.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:
*
@@ -32,7 +33,9 @@
#include "test_common.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
+
+#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
static TestOpt test_opt;
@@ -47,6 +50,8 @@
{
g_assert(!nci_discovery_ntf_copy_array(NULL, 0));
g_assert(!nci_discovery_ntf_copy(NULL));
+ g_assert(!nci_util_copy_mode_param(NULL, 0));
+ g_assert(!nci_util_copy_activation_param(NULL, 0, 0));
}
/*==========================================================================*
@@ -123,6 +128,12 @@
static const guint8 mode_param_success_data_poll_f_3[] =
{ 0x03, 0x12, 0x01, 0xfe, 0xc0, 0xf1, 0xc4, 0x41, 0x38, 0x21, 0xc0, 0xc1,
0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0x0f, 0xab };
+static const guint8 mode_param_success_data_listen_f_0[] =
+ { 0x00 };
+static const guint8 mode_param_success_data_listen_f_1[] =
+ { 0x08, 0x01, 0xfe, 0xc0, 0xf1, 0xc4, 0x41, 0x38, 0x21 };
+static const guint8 mode_param_success_data_listen_f_2[] =
+ { 0x00, /* rest is ignored */ 0x01, 0xfe, 0xc0, 0xf1 };
static const TestModeParamSuccessData mode_param_success_tests[] = {
{
.name = "minimal",
@@ -145,12 +156,16 @@
.name = "poll_b",
.mode = NCI_MODE_PASSIVE_POLL_B,
.data = { TEST_ARRAY_AND_SIZE(mode_param_success_data_poll_b) },
- .expected = { .poll_b = { {0x65, 0xe6, 0x70, 0x15}, 256 } }
+ .expected = { .poll_b = { {0x65, 0xe6, 0x70, 0x15}, 256,
+ {0xe1, 0xf3, 0x5e, 0x11},
+ {mode_param_success_data_poll_b + 9, 3}}}
},{
.name = "poll_b_rfu", /* RFU part of FSCI to FSC conversion table */
.mode = NCI_MODE_PASSIVE_POLL_B,
.data = { TEST_ARRAY_AND_SIZE(mode_param_success_data_poll_b_rfu) },
- .expected = { .poll_b = { {0x65, 0xe6, 0x70, 0x15}, 256 } }
+ .expected = { .poll_b = { {0x65, 0xe6, 0x70, 0x15}, 256,
+ {0xe1, 0xf3, 0x5e, 0x11},
+ {mode_param_success_data_poll_b_rfu + 9, 3}}}
},{
.name = "active_poll_f",
.mode = NCI_MODE_ACTIVE_POLL_F,
@@ -169,6 +184,19 @@
.data = { TEST_ARRAY_AND_SIZE(mode_param_success_data_poll_f_3) },
.expected = { .poll_f = { 3, {0x01, 0xfe, 0xc0, 0xf1,
0xc4, 0x41, 0x38, 0x21} } }
+ },{
+ .name = "active_listen_f",
+ .mode = NCI_MODE_ACTIVE_LISTEN_F,
+ .data = { TEST_ARRAY_AND_SIZE(mode_param_success_data_listen_f_0) },
+ },{
+ .name = "passive_listen_f",
+ .mode = NCI_MODE_PASSIVE_LISTEN_F,
+ .data = { TEST_ARRAY_AND_SIZE(mode_param_success_data_listen_f_1) },
+ .expected = { .listen_f = {{mode_param_success_data_listen_f_1+1, 8}}}
+ },{
+ .name = "passive_listen_f_2",
+ .mode = NCI_MODE_PASSIVE_LISTEN_F,
+ .data = { TEST_ARRAY_AND_SIZE(mode_param_success_data_listen_f_2) }
}
};
@@ -210,6 +238,10 @@
0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0x0f };
static const guint8 mode_param_fail_pollf_data_too_short_2[] =
{ 0x01, 0x07, 0x01, 0xfe, 0xc0, 0xf1, 0xc4, 0x41, 0x38 };
+static const guint8 mode_param_fail_listenf_data_too_short[] =
+ { 0x08, 0x01, 0xfe, 0xc0, 0xf1, 0xc4, 0x41, 0x38 };
+static const guint8 mode_param_fail_listenf_data_bad_len[] =
+ { 0x09, 0x01, 0xfe, 0xc0, 0xf1, 0xc4, 0x41, 0x38, 0x21, 0x00 };
static const TestModeParamFailData mode_param_fail_tests[] = {
{
.name = "invalid_mode",
@@ -268,6 +300,17 @@
.name = "poll_f_too_short_2",
.mode = NCI_MODE_PASSIVE_POLL_F,
.data = { TEST_ARRAY_AND_SIZE(mode_param_fail_pollf_data_too_short_2) }
+ },{
+ .name = "listen_f_empty",
+ .mode = NCI_MODE_ACTIVE_LISTEN_F,
+ },{
+ .name = "listen_f_too_short",
+ .mode = NCI_MODE_ACTIVE_LISTEN_F,
+ .data = { TEST_ARRAY_AND_SIZE(mode_param_fail_listenf_data_too_short) }
+ },{
+ .name = "listen_f_bad_len",
+ .mode = NCI_MODE_PASSIVE_LISTEN_F,
+ .data = { TEST_ARRAY_AND_SIZE(mode_param_fail_listenf_data_bad_len) }
}
};
@@ -299,11 +342,20 @@
g_assert(!ntf.mode_param == !test->mode_param);
g_assert(!ntf.mode_param || !memcmp(ntf.mode_param,
test->mode_param, sizeof(mode_param)));
- g_assert(ntf.activation_param);
- g_assert(!memcmp(ntf.activation_param, test->activation_param,
+ if (test->activation_param) {
+ g_assert(ntf.activation_param);
+ g_assert(!memcmp(ntf.activation_param, test->activation_param,
sizeof(activation_param)));
+ } else {
+ g_assert(!ntf.activation_param);
+ }
}
+static const guint8 test_intf_activated_ntf_mifare[] = {
+ 0x01, 0x80, 0x80, 0x00, 0xff, 0x01, 0x0c, 0x44,
+ 0x00, 0x07, 0x04, 0x47, 0x8a, 0x92, 0x7f, 0x51,
+ 0x80, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00
+};
static const guint8 test_intf_activated_ntf_nfc_dep_poll_1[] = {
0x01, 0x03, 0x05, 0x00, 0xfb, 0x01, 0x09, 0x08,
0x00, 0x04, 0x08, 0x50, 0xad, 0x0e, 0x01, 0x40,
@@ -336,14 +388,62 @@
0x02, 0x02, 0x07, 0xff, 0x03, 0x02, 0x00, 0x13,
0x04, 0x01, 0xff
};
-
static const guint8 test_intf_activated_ntf_nfc_dep_listen_2[] = {
0x01, 0x03, 0x05, 0x83, 0xfb, 0x01, 0x00, 0x83,
0x00, 0x00, 0x0f, 0x0e, 0xc5, 0x47, 0xe4, 0x98,
0x4d, 0x88, 0x04, 0xb4, 0x92, 0xe5, 0x00, 0x00,
0x00, 0x32
};
+static const guint8 test_intf_activated_ntf_isodep_poll_1[] = {
+ 0x01, 0x02, 0x04, 0x01, 0xff, 0x01, 0x0c, 0x0b,
+ 0xdb, 0xa2, 0xa2, 0x2b, 0x52, 0x74, 0x4d, 0x43,
+ 0x00, 0x81, 0xc1, 0x01, 0x00, 0x00, 0x02, 0x01,
+ 0x00
+};
+static const guint8 test_intf_activated_ntf_isodep_poll_2[] = {
+ 0x01, 0x02, 0x04, 0x01, 0xff, 0x01, 0x0c, 0x0b,
+ 0xdb, 0xa2, 0xa2, 0x2b, 0x52, 0x74, 0x4d, 0x43,
+ 0x00, 0x81, 0xc1, 0x01, 0x00, 0x00, 0x05, 0x04,
+ 0x00, 0x01, 0x02, 0x03
+};
+static const guint8 test_intf_activated_ntf_isodep_polla_1[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x05, 0x04, 0x78, 0x77, 0x95,
+ 0x02
+};
+static const guint8 test_intf_activated_ntf_isodep_polla_2[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x04, 0x03, 0x38, 0x77, 0x95
+};
+static const guint8 test_intf_activated_ntf_isodep_polla_3[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x03, 0x02, 0x18, 0x77
+};
+static const guint8 test_intf_activated_ntf_isodep_polla_4[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x02, 0x01, 0x08
+};
+static const guint8 test_intf_activated_ntf_isodep_polla_5[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x14, 0x13, 0x78, 0x77, 0x95,
+ 0x02, 0x80, 0x31, 0xb8, 0x65, 0xb0, 0x85, 0x03,
+ 0x00, 0xef, 0x12, 0x00, 0xf6, 0x82, 0x90, 0x00
+};
+static const NciModeParam test_intf_activated_ntf_mifare_mp = {
+ .poll_a = {
+ .sens_res = { 0x44, 0x00 },
+ .nfcid1_len = 7,
+ .nfcid1 = { 0x04, 0x47, 0x8a, 0x92, 0x7f, 0x51, 0x80 },
+ .sel_res_len = 1,
+ .sel_res = 0x08
+ }
+};
static const NciModeParam test_intf_activated_ntf_poll_a_mp = {
.poll_a = {
.sens_res = { 0x08, 0x00 },
@@ -353,6 +453,31 @@
.sel_res = 0x40
}
};
+static const NciModeParam test_intf_activated_ntf_polla_mp_1 = {
+ .poll_a = {
+ .sens_res = { 0x04, 0x00 },
+ .nfcid1_len = 4,
+ .nfcid1 = { 0x08, 0x46, 0x91, 0xde },
+ .sel_res_len = 1,
+ .sel_res = 0x20
+ }
+};
+static const NciModeParam test_intf_activated_ntf_poll_b_mp_1 = {
+ .poll_b = {
+ .nfcid0 = {0xdb, 0xa2, 0xa2, 0x2b},
+ .fsc = 256,
+ .app_data = {0x52, 0x74, 0x4d, 0x43},
+ .prot_info = { test_intf_activated_ntf_isodep_poll_1 + 0x10, 3 }
+ }
+};
+static const NciModeParam test_intf_activated_ntf_poll_b_mp_2 = {
+ .poll_b = {
+ .nfcid0 = {0xdb, 0xa2, 0xa2, 0x2b},
+ .fsc = 256,
+ .app_data = {0x52, 0x74, 0x4d, 0x43},
+ .prot_info = { test_intf_activated_ntf_isodep_poll_2 + 0x10, 3 }
+ }
+};
static const NciActivationParam test_intf_activated_ntf_nfc_dep_poll_ap_1 = {
.nfc_dep_poll = {
.nfcid3 = { 0xc2, 0x40, 0x83, 0x1b, 0xe1,
@@ -409,30 +534,124 @@
.pp = 0x32
}
};
+static const NciActivationParam test_intf_activated_ntf_isodep_poll_ap_1 = {
+ .iso_dep_poll_b = {
+ .mbli = 0x00,
+ .did = 0x00,
+ .hlr = { NULL, 0 },
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_poll_ap_2 = {
+ .iso_dep_poll_b = {
+ .mbli = 0x00,
+ .did = 0x00,
+ .hlr = { test_intf_activated_ntf_isodep_poll_2 + 0x19, 3 },
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_1 = {
+ .iso_dep_poll_a = {
+ .fsc = 256,
+ .t0 = 0x78,
+ .ta = 0x77,
+ .tb = 0x95,
+ .tc = 0x02
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_2 = {
+ .iso_dep_poll_a = {
+ .fsc = 256,
+ .t0 = 0x38,
+ .ta = 0x77,
+ .tb = 0x95
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_3 = {
+ .iso_dep_poll_a = {
+ .fsc = 256,
+ .t0 = 0x18,
+ .ta = 0x77
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_4 = {
+ .iso_dep_poll_a = {
+ .fsc = 256,
+ .t0 = 0x08
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_5 = {
+ .iso_dep_poll_a = {
+ .fsc = 256,
+ .t1 = { test_intf_activated_ntf_isodep_polla_5 + 0x19, 15 },
+ .t0 = 0x78,
+ .ta = 0x77,
+ .tb = 0x95,
+ .tc = 0x02
+ }
+};
static const TestIntfActivatedSuccessData intf_activated_success_tests[] = {
{
- .name = "nfc_dep_poll/ok/1",
+ .name = "mifare/ok",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_mifare)},
+ .mode_param = &test_intf_activated_ntf_mifare_mp,
+ .activation_param = NULL
+ },{
+ .name = "nfcdep/poll/ok/1",
.data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_nfc_dep_poll_1)},
.mode_param = &test_intf_activated_ntf_poll_a_mp,
.activation_param = &test_intf_activated_ntf_nfc_dep_poll_ap_1
},{
- .name = "nfc_dep_poll/ok/2",
+ .name = "nfcdep/poll/ok/2",
.data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_nfc_dep_poll_2)},
.activation_param = &test_intf_activated_ntf_nfc_dep_poll_ap_2
},{
- .name = "nfc_dep_poll/ok/3",
+ .name = "nfcdep/poll/ok/3",
.data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_nfc_dep_poll_3)},
.mode_param = &test_intf_activated_ntf_poll_a_mp,
.activation_param = &test_intf_activated_ntf_nfc_dep_poll_ap_3
},{
- .name = "nfc_dep_listen/ok/1",
+ .name = "nfcdep/listen/ok/1",
.data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_nfc_dep_listen_1)},
.activation_param = &test_intf_activated_ntf_nfc_dep_listen_ap_1
},{
- .name = "nfc_dep_listen/ok/2",
+ .name = "nfcdep/listen/ok/2",
.data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_nfc_dep_listen_2)},
.activation_param = &test_intf_activated_ntf_nfc_dep_listen_ap_2
+ },{
+ .name = "isodep/poll/ok/1",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_isodep_poll_1)},
+ .mode_param = &test_intf_activated_ntf_poll_b_mp_1,
+ .activation_param = &test_intf_activated_ntf_isodep_poll_ap_1
+ },{
+ .name = "isodep/poll/ok/2",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_isodep_poll_2)},
+ .mode_param = &test_intf_activated_ntf_poll_b_mp_2,
+ .activation_param = &test_intf_activated_ntf_isodep_poll_ap_2
+ },{
+ .name = "isodep/nfca/poll/1",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_isodep_polla_1)},
+ .mode_param = &test_intf_activated_ntf_polla_mp_1,
+ .activation_param = &test_intf_activated_ntf_isodep_polla_ap_1
+ },{
+ .name = "isodep/nfca/poll/2",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_isodep_polla_2)},
+ .mode_param = &test_intf_activated_ntf_polla_mp_1,
+ .activation_param = &test_intf_activated_ntf_isodep_polla_ap_2
+ },{
+ .name = "isodep/nfca/poll/3",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_isodep_polla_3)},
+ .mode_param = &test_intf_activated_ntf_polla_mp_1,
+ .activation_param = &test_intf_activated_ntf_isodep_polla_ap_3
+ },{
+ .name = "isodep/nfca/poll/4",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_isodep_polla_4)},
+ .mode_param = &test_intf_activated_ntf_polla_mp_1,
+ .activation_param = &test_intf_activated_ntf_isodep_polla_ap_4
+ },{
+ .name = "isodep/nfca/poll/5",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_isodep_polla_5)},
+ .mode_param = &test_intf_activated_ntf_polla_mp_1,
+ .activation_param = &test_intf_activated_ntf_isodep_polla_ap_5
}
};
@@ -497,23 +716,45 @@
/* ^^ ^^ ATR_REQ too short */
};
+static const guint8 test_intf_activated_ntf_iso_dep_fail_1[] = {
+ 0x01, 0x02, 0x04, 0x01, 0xff, 0x01, 0x0c, 0x0b,
+ 0xdb, 0xa2, 0xa2, 0x2b, 0x52, 0x74, 0x4d, 0x43,
+ 0x00, 0x81, 0xc1, 0x01, 0x00, 0x00, 0x01, 0x00,
+ /* ATTRIB Response is too short ^^ ^^ */
+};
+
+static const guint8 test_intf_activated_ntf_iso_dep_fail_2[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x02, 0x01, 0x18
+ /* TA marked as present ^ but is missing */
+};
+
static const TestIntfActivatedFailData intf_activated_fail_tests[] = {
{
- .name = "nfc_dep_1",
+ .name = "nfc_dep/1",
.data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_nfc_dep_fail_1)},
.parse_ok = TRUE, .mode_param_ok = TRUE, .activation_param_ok = FALSE
},{
- .name = "nfc_dep_2",
+ .name = "nfc_dep/2",
.data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_nfc_dep_fail_2)},
.parse_ok = TRUE, .mode_param_ok = TRUE, .activation_param_ok = FALSE
},{
- .name = "nfc_dep_3",
+ .name = "nfc_dep/3",
.data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_nfc_dep_fail_3)},
.parse_ok = TRUE, .mode_param_ok = FALSE, .activation_param_ok = FALSE
},{
- .name = "nfc_dep_4",
+ .name = "nfc_dep/4",
.data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_nfc_dep_fail_4)},
.parse_ok = TRUE, .mode_param_ok = FALSE, .activation_param_ok = FALSE
+ },{
+ .name = "iso_dep/1",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_iso_dep_fail_1)},
+ .parse_ok = TRUE, .mode_param_ok = TRUE, .activation_param_ok = FALSE
+ },{
+ .name = "iso_dep/2",
+ .data = {TEST_ARRAY_AND_SIZE(test_intf_activated_ntf_iso_dep_fail_2)},
+ .parse_ok = TRUE, .mode_param_ok = TRUE, .activation_param_ok = FALSE
}
};
@@ -525,7 +766,6 @@
const char* name;
GUtilData data;
NciDiscoveryNtf ntf;
-
} TestDiscoverSuccessData;
static
@@ -557,6 +797,17 @@
{ 0x02, 0x80, 0x00, 0x09, 0x04, 0x00, 0x04, 0x4f,
0x01, 0x74, 0x01, 0x01, 0x08, 0x00 };
+static const guint8 discover_success_data_full_3_param_app_data[] =
+{0x00, 0x81, 0xc1};
+
+static const NciModeParam discover_success_data_full_3_param = {
+ .poll_b = { {0x8e, 0x9c, 0x6d, 0xca}, 0x0b, { 0x52, 0x74, 0x4d, 0x43 },
+ { TEST_ARRAY_AND_SIZE(discover_success_data_full_3_param_app_data) } }
+};
+static const guint8 discover_success_data_full_3[] =
+ { 0x01, 0x04, 0x01, 0x0c, 0x0b, 0x8e, 0x9c, 0x6d, 0xca,
+ 0x52, 0x74, 0x4d, 0x43, 0x00, 0x81, 0xc1, 0x00 };
+
static const TestDiscoverSuccessData discover_success_tests[] = {
{
.name = "no_param",
@@ -580,6 +831,14 @@
.param_bytes = discover_success_data_full_2 + 4,
.param = &discover_success_data_full_2_param,
.last = TRUE }
+ },{
+ .name = "full/3",
+ .data = { TEST_ARRAY_AND_SIZE(discover_success_data_full_3) },
+ .ntf = { .discovery_id = 0x01, .protocol = 0x04,
+ .mode = NCI_MODE_PASSIVE_POLL_B, .param_len = 0x0c,
+ .param_bytes = discover_success_data_full_3 + 4,
+ .param = &discover_success_data_full_3_param,
+ .last = TRUE }
}
};
@@ -606,7 +865,7 @@
} else {
g_assert(!n1->param_bytes);
}
-
+
if (n2->param) {
g_assert(n1->param);
g_assert(!memcmp(n1->param_bytes, n2->param_bytes, n2->param_len));
@@ -625,6 +884,30 @@
g_assert(!memcmp(p1->nfcid1, p2->nfcid1, p2->nfcid1_len));
}
break;
+ case NCI_MODE_PASSIVE_POLL_B:
+ {
+ const NciModeParamPollB* p1 = &n1->param->poll_b;
+ const NciModeParamPollB* p2 = &n2->param->poll_b;
+
+ g_assert(p1->fsc == p2->fsc);
+ g_assert(!memcmp(p1->nfcid0, p2->nfcid0,
+ FIELD_SIZEOF(NciModeParamPollB, nfcid0)));
+ g_assert(!memcmp(p1->app_data, p2->app_data,
+ FIELD_SIZEOF(NciModeParamPollB, app_data)));
+ g_assert(!p1->prot_info.bytes || p1->prot_info.size);
+ g_assert(!p1->prot_info.size || p1->prot_info.bytes);
+ g_assert(!p2->prot_info.bytes || p2->prot_info.size);
+ g_assert(!p2->prot_info.size || p2->prot_info.bytes);
+ if (p1->prot_info.bytes) {
+ g_assert(p1->prot_info.bytes != p2->prot_info.bytes);
+ g_assert(p1->prot_info.size == p2->prot_info.size);
+ g_assert(!memcmp(p1->prot_info.bytes, p2->prot_info.bytes,
+ p1->prot_info.size));
+ } else {
+ g_assert(p1->prot_info.bytes == p2->prot_info.bytes);
+ }
+ }
+ break;
default:
break;
}
@@ -694,6 +977,387 @@
};
/*==========================================================================*
+ * copy_check helpers
+ *==========================================================================*/
+
+static
+void
+test_poll_a_copy_check(
+ const NciModeParamPollA* orig,
+ const NciModeParamPollA* copy)
+{
+ g_assert(orig);
+ g_assert(copy);
+ g_assert(orig != copy);
+ g_assert(orig->sel_res == copy->sel_res);
+ g_assert(orig->sel_res_len == copy->sel_res_len);
+ g_assert(orig->nfcid1_len == copy->nfcid1_len);
+ g_assert(orig->nfcid1_len == copy->nfcid1_len);
+ g_assert(!memcmp(orig->sens_res, copy->sens_res,
+ FIELD_SIZEOF(NciModeParamPollA, sens_res)));
+ g_assert(!memcmp(orig->nfcid1, copy->nfcid1,
+ FIELD_SIZEOF(NciModeParamPollA, nfcid1)));
+}
+
+static
+void
+test_poll_b_copy_check(
+ const NciModeParamPollB* orig,
+ const NciModeParamPollB* copy)
+{
+ g_assert(orig);
+ g_assert(copy);
+ g_assert(orig != copy);
+ g_assert(orig->fsc == copy->fsc);
+ g_assert(!memcmp(orig->nfcid0, copy->nfcid0,
+ FIELD_SIZEOF(NciModeParamPollB, nfcid0)));
+ g_assert(!memcmp(orig->app_data, copy->app_data,
+ FIELD_SIZEOF(NciModeParamPollB, app_data)));
+ g_assert(!orig->prot_info.bytes || orig->prot_info.size);
+ g_assert(!orig->prot_info.size || orig->prot_info.bytes);
+ g_assert(!copy->prot_info.bytes || copy->prot_info.size);
+ g_assert(!copy->prot_info.size || copy->prot_info.bytes);
+ if (orig->prot_info.bytes) {
+ g_assert(orig->prot_info.bytes != copy->prot_info.bytes);
+ g_assert(orig->prot_info.size == copy->prot_info.size);
+ g_assert(!memcmp(orig->prot_info.bytes, copy->prot_info.bytes,
+ orig->prot_info.size));
+ } else {
+ g_assert(orig->prot_info.bytes == copy->prot_info.bytes);
+ }
+}
+
+static
+void
+test_poll_f_copy_check(
+ const NciModeParamPollF* orig,
+ const NciModeParamPollF* copy)
+{
+ g_assert(orig);
+ g_assert(copy);
+ g_assert(orig != copy);
+ g_assert(orig->bitrate == copy->bitrate);
+ g_assert(!memcmp(orig->nfcid2, copy->nfcid2,
+ FIELD_SIZEOF(NciModeParamPollF, nfcid2)));
+}
+
+static
+void
+test_listen_f_copy_check(
+ const NciModeParamListenF* orig,
+ const NciModeParamListenF* copy)
+{
+ g_assert(orig);
+ g_assert(copy);
+ g_assert(orig != copy);
+ g_assert(!orig->nfcid2.bytes || orig->nfcid2.size);
+ g_assert(!orig->nfcid2.size || orig->nfcid2.bytes);
+ g_assert(!copy->nfcid2.bytes || copy->nfcid2.size);
+ g_assert(!copy->nfcid2.size || copy->nfcid2.bytes);
+ if (orig->nfcid2.bytes) {
+ g_assert(orig->nfcid2.bytes != copy->nfcid2.bytes);
+ g_assert(orig->nfcid2.size == copy->nfcid2.size);
+ g_assert(!memcmp(orig->nfcid2.bytes, copy->nfcid2.bytes,
+ orig->nfcid2.size));
+ } else {
+ g_assert(orig->nfcid2.bytes == copy->nfcid2.bytes);
+ }
+}
+
+static
+void
+test_mode_param_copy_check(
+ const NciModeParam* orig,
+ const NciModeParam* copy,
+ NCI_MODE mode)
+{
+ if (orig) {
+ g_assert(copy);
+ g_assert(orig != copy);
+ switch (mode) {
+ case NCI_MODE_ACTIVE_POLL_A: /* fallthrough */
+ case NCI_MODE_PASSIVE_POLL_A:
+ test_poll_a_copy_check(&orig->poll_a, ©->poll_a);
+ break;
+ case NCI_MODE_ACTIVE_POLL_F: /* fallthrough */
+ case NCI_MODE_PASSIVE_POLL_F:
+ test_poll_f_copy_check(&orig->poll_f, ©->poll_f);
+ break;
+ case NCI_MODE_PASSIVE_POLL_B:
+ test_poll_b_copy_check(&orig->poll_b, ©->poll_b);
+ break;
+ case NCI_MODE_ACTIVE_LISTEN_F:
+ case NCI_MODE_PASSIVE_LISTEN_F:
+ test_listen_f_copy_check(&orig->listen_f, ©->listen_f);
+ break;
+ case NCI_MODE_PASSIVE_POLL_15693:
+ case NCI_MODE_PASSIVE_LISTEN_15693:
+ break;
+ case NCI_MODE_PASSIVE_LISTEN_A: /* fallthrough */
+ case NCI_MODE_PASSIVE_LISTEN_B: /* fallthrough */
+ case NCI_MODE_ACTIVE_LISTEN_A:
+ break;
+ }
+ } else {
+ g_assert(orig == copy);
+ }
+}
+
+static
+void
+test_act_param_iso_dep_poll_a_copy_check(
+ const NciActivationParamIsoDepPollA* orig,
+ const NciActivationParamIsoDepPollA* copy)
+{
+ g_assert(orig);
+ g_assert(copy);
+ g_assert(orig != copy);
+ g_assert(orig->fsc == copy->fsc);
+ g_assert(orig->t0 == copy->t0);
+ g_assert(orig->ta == copy->ta);
+ g_assert(orig->tb == copy->tb);
+ g_assert(orig->tc == copy->tc);
+ g_assert(!orig->t1.bytes || orig->t1.size);
+ g_assert(!orig->t1.size || orig->t1.bytes);
+ g_assert(!copy->t1.bytes || copy->t1.size);
+ g_assert(!copy->t1.size || copy->t1.bytes);
+ if (orig->t1.bytes) {
+ g_assert(orig->t1.bytes != copy->t1.bytes);
+ g_assert(orig->t1.size == copy->t1.size);
+ g_assert(!memcmp(orig->t1.bytes, copy->t1.bytes, orig->t1.size));
+ } else {
+ g_assert(orig->t1.bytes == copy->t1.bytes);
+ }
+}
+
+static
+void
+test_act_param_iso_dep_poll_b_copy_check(
+ const NciActivationParamIsoDepPollB* orig,
+ const NciActivationParamIsoDepPollB* copy)
+{
+ g_assert(orig);
+ g_assert(copy);
+ g_assert(orig != copy);
+ g_assert(orig->mbli == copy->mbli);
+ g_assert(orig->did == copy->did);
+ g_assert(!orig->hlr.bytes || orig->hlr.size);
+ g_assert(!orig->hlr.size || orig->hlr.bytes);
+ g_assert(!copy->hlr.bytes || copy->hlr.size);
+ g_assert(!copy->hlr.size || copy->hlr.bytes);
+ if (orig->hlr.bytes) {
+ g_assert(orig->hlr.bytes != copy->hlr.bytes);
+ g_assert(orig->hlr.size == copy->hlr.size);
+ g_assert(!memcmp(orig->hlr.bytes, copy->hlr.bytes, orig->hlr.size));
+ } else {
+ g_assert(orig->hlr.bytes == copy->hlr.bytes);
+ }
+}
+
+static
+void
+test_act_param_nfc_dep_poll_copy_check(
+ const NciActivationParamNfcDepPoll* orig,
+ const NciActivationParamNfcDepPoll* copy)
+{
+ g_assert(orig);
+ g_assert(copy);
+ g_assert(orig != copy);
+ g_assert(orig->did == copy->did);
+ g_assert(orig->bs == copy->bs);
+ g_assert(orig->br == copy->br);
+ g_assert(orig->to == copy->to);
+ g_assert(orig->pp == copy->pp);
+ g_assert(!memcmp(orig->nfcid3, copy->nfcid3,
+ FIELD_SIZEOF(NciActivationParamNfcDepPoll, nfcid3)));
+ g_assert(!orig->g.bytes || orig->g.size);
+ g_assert(!orig->g.size || orig->g.bytes);
+ g_assert(!copy->g.bytes || copy->g.size);
+ g_assert(!copy->g.size || copy->g.bytes);
+ if (orig->g.bytes) {
+ g_assert(orig->g.bytes != copy->g.bytes);
+ g_assert(orig->g.size == copy->g.size);
+ g_assert(!memcmp(orig->g.bytes, copy->g.bytes, orig->g.size));
+ } else {
+ g_assert(orig->g.bytes == copy->g.bytes);
+ }
+}
+
+static
+void
+test_act_param_nfc_dep_listen_copy_check(
+ const NciActivationParamNfcDepListen* orig,
+ const NciActivationParamNfcDepListen* copy)
+{
+ g_assert(orig);
+ g_assert(copy);
+ g_assert(orig != copy);
+ g_assert(orig->did == copy->did);
+ g_assert(orig->bs == copy->bs);
+ g_assert(orig->br == copy->br);
+ g_assert(orig->pp == copy->pp);
+ g_assert(!memcmp(orig->nfcid3, copy->nfcid3,
+ FIELD_SIZEOF(NciActivationParamNfcDepPoll, nfcid3)));
+ g_assert(!orig->g.bytes || orig->g.size);
+ g_assert(!orig->g.size || orig->g.bytes);
+ g_assert(!copy->g.bytes || copy->g.size);
+ g_assert(!copy->g.size || copy->g.bytes);
+ if (orig->g.bytes) {
+ g_assert(orig->g.bytes != copy->g.bytes);
+ g_assert(orig->g.size == copy->g.size);
+ g_assert(!memcmp(orig->g.bytes, copy->g.bytes, orig->g.size));
+ } else {
+ g_assert(orig->g.bytes == copy->g.bytes);
+ }
+}
+
+static
+void
+test_activation_param_copy_check(
+ const NciActivationParam* orig,
+ const NciActivationParam* copy,
+ NCI_RF_INTERFACE intf,
+ NCI_MODE mode)
+{
+ if (orig) {
+ g_assert(copy);
+ g_assert(orig != copy);
+ switch (intf) {
+ case NCI_RF_INTERFACE_ISO_DEP:
+ switch (mode) {
+ case NCI_MODE_PASSIVE_POLL_A:
+ case NCI_MODE_ACTIVE_POLL_A:
+ test_act_param_iso_dep_poll_a_copy_check(&orig->iso_dep_poll_a,
+ ©->iso_dep_poll_a);
+ break;
+ case NCI_MODE_PASSIVE_POLL_B:
+ test_act_param_iso_dep_poll_b_copy_check(&orig->iso_dep_poll_b,
+ ©->iso_dep_poll_b);
+ case NCI_MODE_PASSIVE_POLL_F:
+ case NCI_MODE_ACTIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_15693:
+ case NCI_MODE_PASSIVE_LISTEN_A:
+ case NCI_MODE_PASSIVE_LISTEN_B:
+ case NCI_MODE_PASSIVE_LISTEN_F:
+ case NCI_MODE_ACTIVE_LISTEN_A:
+ case NCI_MODE_ACTIVE_LISTEN_F:
+ case NCI_MODE_PASSIVE_LISTEN_15693:
+ break;
+ }
+ break;
+ case NCI_RF_INTERFACE_FRAME:
+ /* There are no Activation Parameters for Frame RF interface */
+ break;
+ case NCI_RF_INTERFACE_NFC_DEP:
+ switch (mode) {
+ case NCI_MODE_ACTIVE_POLL_A:
+ case NCI_MODE_ACTIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_A:
+ case NCI_MODE_PASSIVE_POLL_F:
+ test_act_param_nfc_dep_poll_copy_check(&orig->nfc_dep_poll,
+ ©->nfc_dep_poll);
+ case NCI_MODE_ACTIVE_LISTEN_A:
+ case NCI_MODE_ACTIVE_LISTEN_F:
+ case NCI_MODE_PASSIVE_LISTEN_A:
+ case NCI_MODE_PASSIVE_LISTEN_F:
+ test_act_param_nfc_dep_listen_copy_check(&orig->nfc_dep_listen,
+ ©->nfc_dep_listen);
+ case NCI_MODE_PASSIVE_POLL_B:
+ case NCI_MODE_PASSIVE_POLL_15693:
+ case NCI_MODE_PASSIVE_LISTEN_B:
+ case NCI_MODE_PASSIVE_LISTEN_15693:
+ break;
+ }
+ break;
+ case NCI_RF_INTERFACE_NFCEE_DIRECT:
+ case NCI_RF_INTERFACE_PROPRIETARY:
+ break;
+ }
+ } else {
+ g_assert(orig == copy);
+ }
+}
+
+/*==========================================================================*
+ * mode_param_copy
+ *==========================================================================*/
+
+static
+void
+test_mode_param_copy(
+ gconstpointer test_data)
+{
+ const TestModeParamSuccessData* test = test_data;
+ const NCI_MODE mode = test->mode;
+ NciModeParam param;
+ memset(¶m, 0, sizeof(param));
+ g_assert(nci_parse_mode_param(¶m, mode, test->data.bytes,
+ test->data.size));
+
+ NciModeParam* copy = nci_util_copy_mode_param(¶m, mode);
+ test_mode_param_copy_check(¶m, copy, mode);
+ g_free(copy);
+}
+
+/*==========================================================================*
+ * discover_mode_param_copy
+ *==========================================================================*/
+
+static
+void
+test_discover_mode_param_copy(
+ gconstpointer test_data)
+{
+ const TestDiscoverSuccessData* test = test_data;
+ const NciModeParam* orig = test->ntf.param;
+ const NCI_MODE mode = test->ntf.mode;
+ NciModeParam* copy = nci_util_copy_mode_param(orig, mode);
+
+ test_mode_param_copy_check(orig, copy, mode);
+ g_free(copy);
+
+ orig = NULL;
+ copy = nci_util_copy_mode_param(orig, mode);
+ test_mode_param_copy_check(orig, copy, mode);
+ g_free(copy);
+}
+
+/*==========================================================================*
+ * intf_activated_copy_params
+ *==========================================================================*/
+
+
+static
+void
+test_intf_activated_copy_params(
+ gconstpointer test_data)
+{
+ const TestIntfActivatedSuccessData* test = test_data;
+ NciIntfActivationNtf ntf;
+ NciModeParam mode_param;
+ NciActivationParam activation_param;
+
+ memset(&mode_param, 0, sizeof(mode_param));
+ memset(&activation_param, 0, sizeof(activation_param));
+ g_assert(nci_parse_intf_activated_ntf(&ntf, &mode_param, &activation_param,
+ test->data.bytes, test->data.size));
+
+ const NciModeParam* orig_mode = test->mode_param;
+ const NCI_MODE mode = ntf.mode;
+ const NCI_RF_INTERFACE intf = ntf.rf_intf;
+ const NciActivationParam* orig_act = test->activation_param;
+ NciModeParam* copy_mode = nci_util_copy_mode_param(orig_mode, mode);
+ NciActivationParam* copy_act = nci_util_copy_activation_param(orig_act, intf,
+ mode);
+
+ test_mode_param_copy_check(orig_mode, copy_mode, mode);
+ test_activation_param_copy_check(orig_act, copy_act, intf, mode);
+ g_free(copy_mode);
+ g_free(copy_act);
+}
+
+
+/*==========================================================================*
* Common
*==========================================================================*/
@@ -709,10 +1373,14 @@
g_test_add_func(TEST_("listen_mode"), test_listen_mode);
for (i = 0; i < G_N_ELEMENTS(mode_param_success_tests); i++) {
const TestModeParamSuccessData* test = mode_param_success_tests + i;
- char* path = g_strconcat(TEST_("mode_param/ok/"), test->name, NULL);
+ char* path1 = g_strconcat(TEST_("mode_param/ok/"), test->name, NULL);
+ char* path2 = g_strconcat(TEST_("mode_param/ok_copy/"), test->name,
+ NULL);
- g_test_add_data_func(path, test, test_mode_param_success);
- g_free(path);
+ g_test_add_data_func(path1, test, test_mode_param_success);
+ g_test_add_data_func(path2, test, test_mode_param_copy);
+ g_free(path1);
+ g_free(path2);
}
for (i = 0; i < G_N_ELEMENTS(mode_param_fail_tests); i++) {
const TestModeParamFailData* test = mode_param_fail_tests + i;
@@ -725,20 +1393,28 @@
const TestDiscoverSuccessData* test = discover_success_tests + i;
char* path1 = g_strconcat(TEST_("discover/success/"), test->name, NULL);
char* path2 = g_strconcat(TEST_("discover/copy/"), test->name, NULL);
+ char* path3 = g_strconcat(TEST_("discover/copy_mode_param/"),
+ test->name, NULL);
g_test_add_data_func(path1, test, test_discover_success);
g_test_add_data_func(path2, test, test_discover_copy);
+ g_test_add_data_func(path3, test, test_discover_mode_param_copy);
g_free(path1);
g_free(path2);
+ g_free(path3);
}
for (i = 0; i < G_N_ELEMENTS(intf_activated_success_tests); i++) {
const TestIntfActivatedSuccessData* test =
intf_activated_success_tests + i;
- char* path = g_strconcat(TEST_("intf_activated/success/"),
+ char* path1 = g_strconcat(TEST_("intf_activated/success/"),
+ test->name, NULL);
+ char* path2 = g_strconcat(TEST_("intf_activated/copy_params/"),
test->name, NULL);
- g_test_add_data_func(path, test, test_intf_activated_success);
- g_free(path);
+ g_test_add_data_func(path1, test, test_intf_activated_success);
+ g_test_add_data_func(path2, test, test_intf_activated_copy_params);
+ g_free(path1);
+ g_free(path2);
}
for (i = 0; i < G_N_ELEMENTS(intf_activated_fail_tests); i++) {
const TestIntfActivatedFailData* test = intf_activated_fail_tests + i;
|