[-]
[+]
|
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;
|
[-]
[+]
|
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)) {
|
[-]
[+]
|
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),
|
[-]
[+]
|
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));
|
[-]
[+]
|
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
}
};
|