[-]
[+]
|
Changed |
_service:tar_git:libncicore.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,7 +2,7 @@
<service name="tar_git">
<param name="url">https://github.com/mer-hybris/libncicore.git</param>
<param name="branch">master</param>
- <param name="revision">1.0.5</param>
+ <param name="revision">1.1.10</param>
<param name="token"/>
<param name="debian">N</param>
<param name="dumb">N</param>
|
[-]
[+]
|
Deleted |
_service:tar_git:libncicore-1.0.5.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.0.5.tar.bz2/debian/libncicore.install
^
|
@@ -1 +0,0 @@
-debian/tmp/usr/lib/libncicore.so.* usr/lib
|
[-]
[+]
|
Deleted |
_service:tar_git:libncicore-1.0.5.tar.bz2/src/nci_transition_poll_active_to_discovery.c
^
|
@@ -1,200 +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 (Discovery), the NFCC SHALL send
- * RF_DEACTIVATE_RSP followed by RF_DEACTIVATE_NTF (Discovery, DH Request)
- * upon successful deactivation. The state will then change to RFST_DISCOVERY
- * where the NFCC SHALL either restart or continue the Polling discovery
- * activity.
- *
- *==========================================================================*/
-
-typedef NciTransition NciTransitionPollActiveToDiscovery;
-typedef NciTransitionClass NciTransitionPollActiveToDiscoveryClass;
-
-G_DEFINE_TYPE(NciTransitionPollActiveToDiscovery,
- nci_transition_poll_active_to_discovery, NCI_TYPE_TRANSITION)
-#define THIS_TYPE (nci_transition_poll_active_to_discovery_get_type())
-#define PARENT_CLASS (nci_transition_poll_active_to_discovery_parent_class)
-
-/*==========================================================================*
- * Implementation
- *==========================================================================*/
-
-static
-void
-nci_transition_poll_active_to_discovery_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");
- return;
- } else if (status == NCI_REQUEST_TIMEOUT) {
- GDEBUG("RF_DEACTIVATE (Idle) timed out");
- } 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);
- nci_sm_enter_state(nci_transition_sm(self), NCI_RFST_IDLE, NULL);
- return;
- } 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);
-}
-
-static
-void
-nci_transition_poll_active_to_discovery_rsp(
- NCI_REQUEST_STATUS status,
- const GUtilData* payload,
- NciTransition* self)
-{
- if (status == NCI_REQUEST_CANCELLED || !nci_transition_active(self)) {
- GDEBUG("RF_DEACTIVATE (Discovery) cancelled");
- } else if (status == NCI_REQUEST_TIMEOUT) {
- GDEBUG("RF_DEACTIVATE (Discovery) 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 (Discovery) ok", DIR_IN);
- /* Wait for RF_DEACTIVATE_NTF */
- } else {
- /* Try to deactivate to IDLE */
- GWARN("RF_DEACTIVATE_CMD (Discovery) failed");
- nci_transition_deactivate_to_idle(self,
- nci_transition_poll_active_to_discovery_idle_rsp);
- }
- } else {
- nci_transition_stall(self, NCI_STALL_ERROR);
- }
-}
-
-/*==========================================================================*
- * Interface
- *==========================================================================*/
-
-NciTransition*
-nci_transition_poll_active_to_discovery_new(
- NciSm* sm)
-{
- NciState* dest = nci_sm_get_state(sm, NCI_RFST_DISCOVERY);
-
- if (dest) {
- NciTransition* self = g_object_new(THIS_TYPE, NULL);
-
- nci_transition_init_base(self, sm, dest);
- return self;
- }
- return NULL;
-}
-
-/*==========================================================================*
- * Methods
- *==========================================================================*/
-
-static
-gboolean
-nci_transition_poll_active_to_discovery_start(
- NciTransition* self)
-{
- return nci_transition_deactivate_to_discovery(self,
- nci_transition_poll_active_to_discovery_rsp);
-}
-
-static
-void
-nci_transition_poll_active_to_discovery_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);
-}
-
-/*==========================================================================*
- * Internals
- *==========================================================================*/
-
-static
-void
-nci_transition_poll_active_to_discovery_init(
- NciTransitionPollActiveToDiscovery* self)
-{
-}
-
-static
-void
-nci_transition_poll_active_to_discovery_class_init(
- NciTransitionPollActiveToDiscoveryClass* klass)
-{
- klass->start = nci_transition_poll_active_to_discovery_start;
- klass->handle_ntf = nci_transition_poll_active_to_discovery_handle_ntf;
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
|
[-]
[+]
|
Deleted |
_service:tar_git:libncicore-1.0.5.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:
- */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.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.10.tar.bz2/LICENSE
^
|
@@ -1,5 +1,5 @@
-Copyright (C) 2018-2019 Jolla Ltd.
-Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+Copyright (C) 2018-2020 Jolla Ltd.
+Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
Copyright (C) 2019 Open Mobile Platform LLC.
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/Makefile
^
|
@@ -29,12 +29,15 @@
STATIC_LIB = $(LIB_NAME).a
#
-# Library version
+# Pull library version from nci_version.h
#
-VERSION_MAJOR = 1
-VERSION_MINOR = 0
-VERSION_RELEASE = 5
+VERSION_FILE = $(INCLUDE_DIR)/nci_version.h
+get_version = $(shell grep -E "^ *\\\#define +NCI_CORE_VERSION_$1 +[0-9]+$$" $(VERSION_FILE) | sed "s/ */ /g" | cut -d " " -f 3)
+
+VERSION_MAJOR = $(call get_version,MAJOR)
+VERSION_MINOR = $(call get_version,MINOR)
+VERSION_RELEASE = $(call get_version,NANO)
# Version for pkg-config
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
@@ -52,14 +55,16 @@
nci_sm.c \
nci_state.c \
nci_state_discovery.c \
+ nci_state_listen_active.c \
+ nci_state_listen_sleep.c \
nci_state_poll_active.c \
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_discovery.c \
- nci_transition_poll_active_to_idle.c \
nci_transition_reset.c \
nci_util.c
@@ -85,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 =
@@ -147,9 +153,9 @@
DEBUG_LINK = $(DEBUG_BUILD_DIR)/$(LIB_SONAME)
RELEASE_LINK = $(RELEASE_BUILD_DIR)/$(LIB_SONAME)
-debug: $(DEBUG_STATIC_LIB) $(DEBUG_LIB) $(DEBUG_LINK)
+debug: $(DEBUG_STATIC_LIB) $(DEBUG_LIB) $(DEBUG_LINK) $(PKGCONFIG)
-release: $(RELEASE_STATIC_LIB) $(RELEASE_LIB) $(RELEASE_LINK)
+release: $(RELEASE_STATIC_LIB) $(RELEASE_LIB) $(RELEASE_LINK) $(PKGCONFIG)
coverage: $(COVERAGE_STATIC_LIB)
@@ -226,8 +232,19 @@
$(RELEASE_BUILD_DIR)/$(LIB_SYMLINK2): $(RELEASE_LIB)
ln -sf $(LIB) $@
-$(PKGCONFIG): $(LIB_NAME).pc.in
- sed -e 's/\[version\]/'$(PCVERSION)/g $< > $@
+#
+# 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 Makefile
+ sed -e 's|@version@|$(PCVERSION)|g' -e 's|@libdir@|$(ABS_LIBDIR)|g' $< > $@
+
+debian/%.install: debian/%.install.in
+ sed 's|@LIBDIR@|$(LIBDIR)|g' $< > $@
#
# Install
@@ -237,9 +254,9 @@
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)
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/README
^
|
@@ -1,13 +1,15 @@
-NFC NCI state machine implementatiton
-=====================================
+NFC NCI state machine implementation
+====================================
-The following states are implemented according to NCI 1.0 spec:
+Implements all the states defined in NCI 1.0 spec:
RFST_IDLE
RFST_DISCOVERY
RFST_W4_ALL_DISCOVERIES
RFST_W4_HOST_SELECT
RFST_POLL_ACTIVE
+ RFST_LISTEN_ACTIVE
+ RFST_LISTEN_SLEEP
as well as a limited subset of NCI 2.0 features.
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/debian/changelog
^
|
@@ -1,3 +1,111 @@
+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
+ * Stop exporting internal functions
+
+ -- Slava Monich <slava.monich@jolla.com> Tue, 28 Apr 2020 18:25:52 +0300
+
+libncicore (1.0.9) unstable; urgency=low
+
+ * Prevent state machine from getting stuck in RFST_W4_HOST_SELECT state
+ * Consider NFC-DEP a supported protocol
+
+ -- Slava Monich <slava.monich@jolla.com> Tue, 21 Apr 2020 00:14:56 +0300
+
+libncicore (1.0.8) unstable; urgency=low
+
+ * Parse NFC-DEP activation parameters
+ * Parse NFC-F Poll Mode parameters
+
+ -- Slava Monich <slava.monich@jolla.com> Thu, 09 Apr 2020 13:26:53 +0300
+
+libncicore (1.0.7) unstable; urgency=low
+
+ * Removed unnecessary makefile dependency
+ * Switch from HOST_SELECT to DISCOVERY on activation failure
+ * Optimized two-step transitions through IDLE state
+
+ -- Slava Monich <slava.monich@jolla.com> Mon, 24 Feb 2020 18:46:09 +0200
+
+libncicore (1.0.6) unstable; urgency=low
+
+ * Switch from POLL_ACTIVE to DISCOVERY on ERROR_NTF
+ * Added nci_version.h and NCI_CORE_VERSION macro
+ * Added NCI_RF_INTERFACE_PROPRIETARY contant
+ * Added NCI_PROTOCOL_PROPRIETARY constant
+ * Ignore known Glib deprecation warnings
+
+ -- Slava Monich <slava.monich@jolla.com> Sun, 23 Feb 2020 14:10:06 +0200
+
libncicore (1.0.5) unstable; urgency=low
* Housekeeping release
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.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.10.tar.bz2/debian/copyright
^
|
@@ -1,6 +1,6 @@
-Copyright (C) 2018-2019 Jolla Ltd.
-Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
-Copyright (C) 2019 Open Mobile Platform LL C.
+Copyright (C) 2018-2020 Jolla Ltd.
+Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+Copyright (C) 2019 Open Mobile Platform LLC.
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.10.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.10.tar.bz2/debian/libncicore.install.in
^
|
@@ -0,0 +1 @@
+debian/tmp/@LIBDIR@/libncicore.so.* @LIBDIR@
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.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.10.tar.bz2/include/nci_core.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:
*
@@ -94,6 +94,11 @@
NciCore* nci,
NCI_STATE state);
+void
+nci_core_set_op_mode(
+ NciCore* nci,
+ NCI_OP_MODE op_mode); /* Since 1.1.0 */
+
guint
nci_core_send_data_msg(
NciCore* nci,
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/include/nci_types.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:
*
@@ -105,6 +105,7 @@
NCI_PROTOCOL_T3T = 0x03,
NCI_PROTOCOL_ISO_DEP = 0x04,
NCI_PROTOCOL_NFC_DEP = 0x05,
+ NCI_PROTOCOL_PROPRIETARY = 0x80 /* Since 1.0.6 */
} NCI_PROTOCOL;
/* Table 99: RF Interfaces */
@@ -112,7 +113,8 @@
NCI_RF_INTERFACE_NFCEE_DIRECT = 0x00,
NCI_RF_INTERFACE_FRAME = 0x01,
NCI_RF_INTERFACE_ISO_DEP = 0x02,
- NCI_RF_INTERFACE_NFC_DEP = 0x03
+ NCI_RF_INTERFACE_NFC_DEP = 0x03,
+ NCI_RF_INTERFACE_PROPRIETARY = 0x80 /* Since 1.0.6 */
} NCI_RF_INTERFACE;
/* See Table 54: Specific Parameters for NFC-A Poll Mode */
@@ -128,11 +130,27 @@
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 */
+typedef struct nci_mode_param_poll_f {
+ guint8 bitrate; /* 1 = 212 kbps, 2 = 424 kbps */
+ 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 */
+ NciModeParamListenF listen_f; /* Since 1.1.2 */
} NciModeParam;
/* Table 76: Activation Parameters for NFC-A/ISO-DEP Poll Mode */
@@ -141,8 +159,41 @@
GUtilData t1; /* T1 to Tk (otherwise called historical bytes) */
} 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 */
+ guint8 nfcid3[10];
+ guint8 did;
+ guint8 bs;
+ guint8 br;
+ guint8 to;
+ guint8 pp;
+ GUtilData g;
+} NciActivationParamNfcDepPoll; /* Since 1.0.8 */
+
+/* Table 83: Activation Parameters for NFC-DEP Listen Mode */
+typedef struct nci_activation_param_nfc_dep_listen {
+ /* ATR_REQ starting from and including Byte 3 */
+ guint8 nfcid3[10];
+ guint8 did;
+ guint8 bs;
+ guint8 br;
+ guint8 pp;
+ GUtilData g;
+} NciActivationParamNfcDepListen; /* Since 1.0.8 */
+
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;
/* See Table 61: Notification for RF Interface activation */
@@ -192,6 +243,37 @@
NCI_CORE_STATES
} NCI_STATE;
+/*
+ * Operation modes
+ *
+ * The relationship between op mode bits goes like this:
+ *
+ * +----------------+---------------------+----------------+
+ * | NFC R/W Modes | NFC Peer Modes | NFC CE Mode |
+ * | NFC_OP_MODE_RW | NFC_OP_MODE_PEER | NFC_OP_MODE_CE |
+ * +------+---------+-----------+---------+----------------+
+ * | Tags | ISO-DEP | NFC-DEP | NFC-DEP | ISO-DEP |
+ * | 1-3 | | Initiator | Target | |
+ * +------+---------+-----------+---------+----------------+
+ * | Poll side | Listen side |
+ * | NFC_OP_MODE_POLL | NFC_OP_MODE_LISTEN |
+ * +----------------------------+--------------------------+
+ *
+ * That hopefully explains why certain combinations don't make
+ * sense, specifically (NFC_OP_MODE_RW | NFC_OP_MODE_LISTEN)
+ * and (NFC_OP_MODE_CE | NFC_OP_MODE_POLL).
+ */
+
+typedef enum nci_op_mode {
+ NFC_OP_MODE_NONE = 0x00,
+ NFC_OP_MODE_RW = 0x01, /* Reader/Writer (requires POLL) */
+ NFC_OP_MODE_PEER = 0x02, /* Peer NFC-DEP (POLL and/or LISTEN) */
+ NFC_OP_MODE_CE = 0x04, /* Card Emulation (requires LISTEN) */
+ /* The next two are kind of orthogonal, see the diagram above */
+ NFC_OP_MODE_POLL = 0x08, /* Poll side/Initiator */
+ NFC_OP_MODE_LISTEN = 0x10 /* Listen side/Target */
+} NCI_OP_MODE; /* Since 1.1.0 */
+
/* Logging */
#define NCI_LOG_MODULE nci_log
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.10.tar.bz2/include/nci_version.h
^
|
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NCI_CORE_VERSION_H
+#define NCI_CORE_VERSION_H
+
+/* This file exists since version 1.0.6 */
+
+/* libncicore version */
+#define NCI_CORE_VERSION_MAJOR 1
+#define NCI_CORE_VERSION_MINOR 1
+#define NCI_CORE_VERSION_NANO 10
+
+#define NCI_CORE_VERSION_WORD(v1,v2,v3) \
+ ((((v1) & 0x7f) << 24) | \
+ (((v2) & 0xfff) << 12) | \
+ ((v3) & 0xfff))
+
+#define NCI_CORE_VERSION_GET_MAJOR(v) (((v) >> 24) & 0x7f)
+#define NCI_CORE_VERSION_GET_MINOR(v) (((v) >> 12) & 0xfff)
+#define NCI_CORE_VERSION_GET_NANO(v) ((v) & 0xfff)
+
+/* Current version as a single word */
+#define NCI_CORE_VERSION \
+ NCI_CORE_VERSION_WORD(NCI_CORE_VERSION_MAJOR, \
+ NCI_CORE_VERSION_MINOR, NCI_CORE_VERSION_NANO)
+
+#endif /* NCI_CORE_VERSION_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.10.tar.bz2/libncicore.map
^
|
@@ -0,0 +1,7 @@
+{
+ global:
+ nci_core_*;
+ nci_log;
+ local:
+ *;
+};
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.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.10.tar.bz2/src/nci_core.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:
*
@@ -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);
}
@@ -540,6 +542,18 @@
}
}
+void
+nci_core_set_op_mode(
+ NciCore* core,
+ NCI_OP_MODE op_mode) /* Since 1.1.0 */
+{
+ NciCoreObject* self = nci_core_object(core);
+
+ if (G_LIKELY(self)) {
+ nci_sm_set_op_mode(self->sm, op_mode);
+ }
+}
+
guint
nci_core_send_data_msg(
NciCore* core,
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_param.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -41,7 +41,7 @@
GObject object;
};
-GType nci_param_get_type(void);
+GType nci_param_get_type(void) NCI_INTERNAL;
#define NCI_TYPE_PARAM nci_param_get_type()
#define NCI_IS_PARAM(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), NCI_TYPE_PARAM)
#define NCI_PARAM(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), NCI_TYPE_PARAM, \
@@ -49,11 +49,13 @@
NciParam*
nci_param_ref(
- NciParam* param);
+ NciParam* param)
+ NCI_INTERNAL;
void
nci_param_unref(
- NciParam* param);
+ NciParam* param)
+ NCI_INTERNAL;
#endif /* NCI_PARAM_H */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_param_w4_all_discoveries.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -40,7 +40,7 @@
NciDiscoveryNtf* ntf;
} NciParamW4AllDiscoveries;
-GType nci_param_w4_all_discoveries_get_type(void);
+GType nci_param_w4_all_discoveries_get_type(void) NCI_INTERNAL;
#define NCI_TYPE_PARAM_W4_ALL_DISCOVERIES \
nci_param_w4_all_discoveries_get_type()
#define NCI_IS_PARAM_W4_ALL_DISCOVERIES(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj),\
@@ -50,7 +50,8 @@
NciParamW4AllDiscoveries*
nci_param_w4_all_discoveries_new(
- const NciDiscoveryNtf* ntf);
+ const NciDiscoveryNtf* ntf)
+ NCI_INTERNAL;
#endif /* NCI_PARAM_W4_ALL_DISCOVERIES_H */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_param_w4_host_select.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -41,7 +41,7 @@
guint count;
} NciParamW4HostSelect;
-GType nci_param_w4_host_select_get_type(void);
+GType nci_param_w4_host_select_get_type(void) NCI_INTERNAL;
#define NCI_TYPE_PARAM_W4_HOST_SELECT \
nci_param_w4_host_select_get_type()
#define NCI_IS_PARAM_W4_HOST_SELECT(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj),\
@@ -52,7 +52,8 @@
NciParamW4HostSelect*
nci_param_w4_host_select_new(
const NciDiscoveryNtf* const* ntfs,
- guint count);
+ guint count)
+ NCI_INTERNAL;
#endif /* NCI_PARAM_W4_HOST_SELECT_H */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.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.10.tar.bz2/src/nci_sar.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:
*
@@ -63,41 +63,55 @@
NciSar*
nci_sar_new(
NciHalIo* io,
- NciSarClient* client);
+ NciSarClient* client)
+ NCI_INTERNAL;
void
nci_sar_free(
- NciSar* sar);
+ NciSar* sar)
+ NCI_INTERNAL;
gboolean
nci_sar_start(
- NciSar* sar);
+ NciSar* sar)
+ NCI_INTERNAL;
void
nci_sar_reset(
- NciSar* sar);
+ NciSar* sar)
+ NCI_INTERNAL;
void
nci_sar_set_max_logical_connections(
NciSar* sar,
- guint8 max);
+ guint8 max)
+ NCI_INTERNAL;
void
-nci_sar_set_max_control_packet_size(
+nci_sar_set_max_control_payload_size(
NciSar* sar,
- guint8 max);
+ guint8 max)
+ NCI_INTERNAL;
+
+void
+nci_sar_set_max_data_payload_size(
+ NciSar* sar,
+ guint8 max)
+ NCI_INTERNAL;
void
nci_sar_set_initial_credits(
NciSar* sar,
guint8 cid,
- guint8 credits);
+ guint8 credits)
+ NCI_INTERNAL;
void
nci_sar_add_credits(
NciSar* sar,
guint8 cid,
- guint8 credits);
+ guint8 credits)
+ NCI_INTERNAL;
guint
nci_sar_send_command(
@@ -107,7 +121,8 @@
GBytes* payload,
NciSarCompletionFunc complete,
GDestroyNotify destroy,
- gpointer user_data);
+ gpointer user_data)
+ NCI_INTERNAL;
guint
nci_sar_send_data_packet(
@@ -116,12 +131,14 @@
GBytes* payload,
NciSarCompletionFunc complete,
GDestroyNotify destroy,
- gpointer user_data);
+ gpointer user_data)
+ NCI_INTERNAL;
void
nci_sar_cancel(
NciSar* sar,
- guint id);
+ guint id)
+ NCI_INTERNAL;
#endif /* NFC_SAR_H */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_sm.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:
*
@@ -37,7 +37,6 @@
#include "nci_transition.h"
#include "nci_log.h"
-#include <gutil_idlepool.h>
#include <gutil_macros.h>
#include <gutil_misc.h>
@@ -60,16 +59,22 @@
typedef struct nci_sm_object {
GObject object;
NciSm sm;
- GUtilIdlePool* pool;
GPtrArray* states;
GPtrArray* transitions;
NciTransition* reset_transition;
NciTransition* next_transition;
NciTransition* active_transition;
NciState* active_state;
+ gint entering_state;
+ guint pending_switch_id;
guint32 pending_signals;
} NciSmObject;
+typedef struct nci_sm_switch {
+ NciSmObject* obj;
+ NciState* state;
+} NciSmSwitch;
+
G_DEFINE_TYPE(NciSmObject, nci_sm_object, G_TYPE_OBJECT)
#define NCI_TYPE_SM (nci_sm_object_get_type())
#define NCI_SM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
@@ -299,6 +304,12 @@
{
NciTransition* next_transition;
+ /*
+ * Protect against nci_sm_switch_to() being invoked by
+ * nci_state_enter() or nci_state_reenter()
+ */
+ self->entering_state++;
+
/* Entering any state terminates the transition */
nci_sm_finish_active_transition(self);
@@ -331,6 +342,9 @@
nci_sm_set_next_state(self, state);
}
nci_sm_emit_pending_signals(self);
+
+ /* Allow direct nci_sm_switch_to() calls */
+ self->entering_state--;
}
/*
@@ -417,16 +431,15 @@
return NULL;
}
+static
void
-nci_sm_switch_to(
- NciSm* sm,
- NCI_STATE id)
+nci_sm_switch_internal(
+ NciSmObject* self,
+ NciState* next)
{
- NciState* next = nci_sm_get_state(sm, id);
-
- if (G_LIKELY(next) && sm->next_state != next) {
- NciSmObject* self = nci_sm_object(sm);
+ NciSm* sm = &self->sm;
+ if (sm->next_state != next) {
if (self->next_transition) {
nci_transition_unref(self->next_transition);
self->next_transition = NULL;
@@ -435,11 +448,12 @@
NciState* dest = self->active_transition->dest;
if (dest != next) {
- self->next_transition = nci_state_get_transition(dest, id);
+ self->next_transition =
+ nci_state_get_transition(dest, next->state);
if (self->next_transition) {
nci_transition_ref(self->next_transition);
nci_sm_set_next_state(self, next);
- } else if (NCI_IS_INTERNAL_STATE(id)) {
+ } else if (NCI_IS_INTERNAL_STATE(next->state)) {
/* Internal states are entered without transition
* and take no parameters */
nci_sm_enter_state_internal(self, next, NULL);
@@ -449,29 +463,37 @@
}
}
} else {
- NciTransition* next_transition =
- nci_state_get_transition(sm->last_state, id);
+ NciTransition* direct_transition =
+ nci_state_get_transition(sm->last_state, next->state);
- if (next_transition) {
- if (nci_sm_start_transition(self, next_transition)) {
+ if (direct_transition) {
+ /* Found direct transition */
+ if (nci_sm_start_transition(self, direct_transition)) {
nci_sm_set_next_state(self, next);
} else {
nci_sm_stall_internal(self, NCI_STALL_ERROR);
}
- } else if (NCI_IS_INTERNAL_STATE(id)) {
+ } else if (NCI_IS_INTERNAL_STATE(next->state)) {
/* Internal states are entered without transition and
* take no parameters. */
nci_sm_enter_state_internal(self, next, NULL);
} else {
- NciState* idle = nci_sm_state_by_id(self, NCI_RFST_IDLE);
-
/* Switch to idle state first */
- if (nci_sm_start_transition(self, self->reset_transition)) {
- if (id == NCI_RFST_IDLE) {
+ NciTransition* transition_to_idle =
+ nci_state_get_transition(sm->last_state, NCI_RFST_IDLE);
+
+ if (!transition_to_idle) {
+ /* No direct transition to IDLE, must reset */
+ transition_to_idle = self->reset_transition;
+ }
+ if (nci_sm_start_transition(self, transition_to_idle)) {
+ NciState* idle = nci_sm_state_by_id(self, NCI_RFST_IDLE);
+
+ if (next->state == NCI_RFST_IDLE) {
nci_sm_set_next_state(self, idle);
} else {
self->next_transition =
- nci_state_get_transition(idle, id);
+ nci_state_get_transition(idle, next->state);
if (self->next_transition) {
nci_transition_ref(self->next_transition);
nci_sm_set_next_state(self, next);
@@ -490,6 +512,62 @@
}
}
+static
+void
+nci_sm_switch_destroy(
+ gpointer user_data)
+{
+ NciSmSwitch* data = user_data;
+
+ nci_state_unref(data->state);
+ g_slice_free1(sizeof(*data), data);
+}
+
+static
+gboolean
+nci_sm_switch_proc(
+ gpointer user_data)
+{
+ NciSmSwitch* data = user_data;
+ NciSmObject* self = data->obj;
+
+ self->pending_switch_id = 0;
+ nci_sm_switch_internal(self, data->state);
+ return G_SOURCE_REMOVE;
+}
+
+void
+nci_sm_switch_to(
+ NciSm* sm,
+ NCI_STATE id)
+{
+ NciSmObject* self = nci_sm_object(sm);
+
+ if (G_LIKELY(self)) {
+ NciState* state = nci_sm_state_by_id(self, id);
+
+ if (G_LIKELY(state)) {
+ if (self->pending_switch_id) {
+ /* Cancel previously scheduled switch */
+ g_source_remove(self->pending_switch_id);
+ self->pending_switch_id = 0;
+ }
+ if (self->entering_state) {
+ /* Will do it later on a fresh stack */
+ NciSmSwitch* data = g_slice_new(NciSmSwitch);
+
+ data->obj = self;
+ data->state = nci_state_ref(state);
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_sm.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -256,6 +256,7 @@
NCI_NFCC_DISCOVERY nfcc_discovery;
NCI_NFCC_ROUTING nfcc_routing;
NCI_NFCC_POWER nfcc_power;
+ NCI_OP_MODE op_mode;
};
typedef
@@ -277,74 +278,93 @@
nci_sm_enter_state(
NciSm* sm,
NCI_STATE state,
- NciParam* param);
+ NciParam* param)
+ NCI_INTERNAL;
void
nci_sm_switch_to(
NciSm* sm,
- NCI_STATE id);
+ NCI_STATE id)
+ NCI_INTERNAL;
void
nci_sm_stall(
NciSm* sm,
- NCI_STALL type);
+ NCI_STALL type)
+ NCI_INTERNAL;
/* Interface for NciCore */
NciSm*
nci_sm_new(
- NciSmIo* io);
+ NciSmIo* io)
+ NCI_INTERNAL;
void
nci_sm_free(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
+
+void
+nci_sm_set_op_mode(
+ NciSm* sm,
+ NCI_OP_MODE op_mode)
+ NCI_INTERNAL;
void
nci_sm_handle_ntf(
NciSm* sm,
guint8 gid,
guint8 oid,
- const GUtilData* payload);
+ const GUtilData* payload)
+ NCI_INTERNAL;
void
nci_sm_add_state(
NciSm* sm,
- NciState* state);
+ NciState* state)
+ NCI_INTERNAL;
void
nci_sm_add_transition(
NciSm* sm,
NCI_STATE state,
- NciTransition* transition);
+ NciTransition* transition)
+ NCI_INTERNAL;
gulong
nci_sm_add_last_state_handler(
NciSm* sm,
NciSmFunc func,
- void* user_data);
+ void* user_data)
+ NCI_INTERNAL;
gulong
nci_sm_add_next_state_handler(
NciSm* sm,
NciSmFunc func,
- void* user_data);
+ void* user_data)
+ NCI_INTERNAL;
gulong
nci_sm_add_intf_activated_handler(
NciSm* sm,
NciSmIntfActivationFunc func,
- void* user_data);
+ void* user_data)
+ NCI_INTERNAL;
void
nci_sm_remove_handler(
NciSm* sm,
- gulong id);
+ gulong id)
+ NCI_INTERNAL;
void
nci_sm_remove_handlers(
NciSm* sm,
gulong* ids,
- guint count);
+ guint count)
+ NCI_INTERNAL;
#define nci_sm_remove_all_handlers(sm,ids) \
nci_sm_remove_handlers(sm, ids, G_N_ELEMENTS(ids))
@@ -353,30 +373,36 @@
void
nci_sm_add_weak_pointer(
- NciSm** ptr);
+ NciSm** ptr)
+ NCI_INTERNAL;
void
nci_sm_remove_weak_pointer(
- NciSm** ptr);
+ NciSm** ptr)
+ NCI_INTERNAL;
NciState*
nci_sm_get_state(
NciSm* sm,
- NCI_STATE state);
+ NCI_STATE state)
+ NCI_INTERNAL;
NciSar*
nci_sm_sar(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
gboolean
nci_sm_supports_protocol(
NciSm* sm,
- NCI_PROTOCOL protocol);
+ NCI_PROTOCOL protocol)
+ NCI_INTERNAL;
gboolean
nci_sm_active_transition(
NciSm* sm,
- NciTransition* transition);
+ NciTransition* transition)
+ NCI_INTERNAL;
gboolean
nci_sm_send_command(
@@ -385,7 +411,8 @@
guint8 oid,
GBytes* payload,
NciSmResponseFunc resp,
- gpointer user_data);
+ gpointer user_data)
+ NCI_INTERNAL;
gboolean
nci_sm_send_command_static(
@@ -395,22 +422,26 @@
const void* payload,
gsize payload_len,
NciSmResponseFunc resp,
- gpointer user_data);
+ gpointer user_data)
+ NCI_INTERNAL;
void
nci_sm_intf_activated(
NciSm* sm,
- const NciIntfActivationNtf* ntf);
+ const NciIntfActivationNtf* ntf)
+ NCI_INTERNAL;
void
nci_sm_handle_conn_credits_ntf(
NciSm* sm,
- const GUtilData* payload);
+ const GUtilData* payload)
+ NCI_INTERNAL;
void
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_state.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,6 +30,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
#include "nci_state_impl.h"
#include "nci_sm.h"
#include "nci_transition.h"
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_state.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -47,83 +47,109 @@
gboolean active;
};
-GType nci_state_get_type(void);
+GType nci_state_get_type(void) NCI_INTERNAL;
#define NCI_TYPE_STATE (nci_state_get_type())
#define NCI_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NCI_TYPE_STATE, NciState))
NciState*
nci_state_ref(
- NciState* state);
+ NciState* state)
+ NCI_INTERNAL;
void
nci_state_unref(
- NciState* state);
+ NciState* state)
+ NCI_INTERNAL;
NciTransition*
nci_state_get_transition(
NciState* state,
- NCI_STATE dest);
+ NCI_STATE dest)
+ NCI_INTERNAL;
void
nci_state_add_transition(
NciState* state,
- NciTransition* transition);
+ NciTransition* transition)
+ NCI_INTERNAL;
void
nci_state_enter(
NciState* state,
- void* param);
+ void* param)
+ NCI_INTERNAL;
void
nci_state_reenter(
NciState* state,
- void* param);
+ void* param)
+ NCI_INTERNAL;
void
nci_state_leave(
- NciState* state);
+ NciState* state)
+ NCI_INTERNAL;
void
nci_state_handle_ntf(
NciState* state,
guint8 gid,
guint8 oid,
- const GUtilData* payload);
+ const GUtilData* payload)
+ NCI_INTERNAL;
/* Specific states */
NciState* /* NCI_STATE_INIT */
nci_state_init_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
NciState* /* NCI_STATE_ERROR */
nci_state_error_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
NciState* /* NCI_STATE_STOP */
nci_state_stop_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
NciState* /* NCI_RFST_IDLE */
nci_state_idle_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
NciState* /* NCI_RFST_DISCOVERY */
nci_state_discovery_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
+
+NciState* /* NCI_RFST_LISTEN_ACTIVE */
+nci_state_listen_active_new(
+ NciSm* sm)
+ NCI_INTERNAL;
+
+NciState* /* NCI_RFST_LISTEN_SLEEP */
+nci_state_listen_sleep_new(
+ NciSm* sm)
+ NCI_INTERNAL;
NciState* /* NCI_RFST_POLL_ACTIVE */
nci_state_poll_active_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
NciState* /* NCI_RFST_W4_ALL_DISCOVERIES */
nci_state_w4_all_discoveries_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
NciState* /* NCI_RFST_W4_HOST_SELECT */
nci_state_w4_host_select_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
#endif /* NCI_STATE_PRIVATE_H */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_state_discovery.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -40,10 +40,12 @@
typedef NciState NciStateDiscovery;
typedef NciStateClass NciStateDiscoveryClass;
-G_DEFINE_TYPE(NciStateDiscovery, nci_state_discovery, NCI_TYPE_STATE)
+GType nci_state_discovery_get_type(void) NCI_INTERNAL;
#define THIS_TYPE (nci_state_discovery_get_type())
#define PARENT_CLASS (nci_state_discovery_parent_class)
+G_DEFINE_TYPE(NciStateDiscovery, nci_state_discovery, NCI_TYPE_STATE)
+
/*==========================================================================*
* Implementation
*==========================================================================*/
@@ -73,8 +75,17 @@
*/
if (nci_parse_intf_activated_ntf(&ntf, &mode_param, &activation_param,
payload->bytes, payload->size)) {
+ /*
+ * 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);
- nci_sm_enter_state(sm, NCI_RFST_POLL_ACTIVE, NULL);
} else {
/* Deactivate this target */
nci_sm_enter_state(sm, NCI_RFST_POLL_ACTIVE, NULL);
@@ -153,10 +164,21 @@
return TRUE;
}
}
- /* Unrecornized notification */
+ /* Unrecognized notification */
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
*==========================================================================*/
@@ -177,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,
@@ -200,9 +242,6 @@
case NCI_OID_RF_INTF_ACTIVATED:
nci_state_discovery_intf_activated_ntf(self, payload);
return;
- case NCI_OID_RF_DEACTIVATE:
- nci_sm_handle_rf_deactivate_ntf(nci_state_sm(self), payload);
- return;
}
break;
}
@@ -225,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.10.tar.bz2/src/nci_state_impl.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -55,7 +55,8 @@
NciState* state,
NciSm* sm,
NCI_STATE id,
- const char* name);
+ const char* name)
+ NCI_INTERNAL;
gboolean
nci_state_send_command(
@@ -64,15 +65,18 @@
guint8 oid,
GBytes* payload,
NciSmResponseFunc resp,
- gpointer user_data);
+ gpointer user_data)
+ NCI_INTERNAL;
void
nci_state_error(
- NciState* state);
+ NciState* state)
+ NCI_INTERNAL;
NciSm*
nci_state_sm(
- NciState* state);
+ NciState* state)
+ NCI_INTERNAL;
#endif /* NCI_STATE_IMPL_H */
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_state_listen_active.c
^
|
@@ -0,0 +1,219 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nci_sm.h"
+#include "nci_state_impl.h"
+#include "nci_log.h"
+
+typedef NciState NciStateListenActive;
+typedef NciStateClass NciStateListenActiveClass;
+
+GType nci_state_listen_active_get_type(void) NCI_INTERNAL;
+#define THIS_TYPE (nci_state_listen_active_get_type())
+#define PARENT_CLASS (nci_state_listen_active_parent_class)
+
+G_DEFINE_TYPE(NciStateListenActive, nci_state_listen_active, NCI_TYPE_STATE)
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+gboolean
+nci_state_listen_active_interface_error_ntf(
+ NciState* self,
+ const GUtilData* payload)
+{
+ const guint8* pkt = payload->bytes;
+ const guint len = payload->size;
+
+ /*
+ * Table 19: Control Messages for Interface Error
+ *
+ * CORE_INTERFACE_ERROR_NTF
+ *
+ * +=========================================================+
+ * | Offset | Size | Description |
+ * +=========================================================+
+ * | 0 | 1 | Status |
+ * | 1 | 1 | Conn ID |
+ * +=========================================================+
+ *
+ * 5.2.6 State RFST_LISTEN_ACTIVE
+ *
+ * ...
+ * When using the ISO-DEP or NFC-DEP RF interface, and the NFCC
+ * detects an error during the RF communication, which does not
+ * require returning to the IDLE state, as defined in the Listen
+ * Mode state machine, the NFCC SHALL send CORE_INTERFACE_ERROR_NTF,
+ * using the appropriate status out of RF_TRANSMISSION_ERROR,
+ * RF_PROTOCOL_ERROR and RF_TIMEOUT_ERROR. The state will then
+ * remain RFST_LISTEN_ACTIVE.
+ */
+ 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)");
+ break;
+ case NCI_RF_PROTOCOL_ERROR:
+ GDEBUG("CORE_INTERFACE_ERROR_NTF (Protocol Error)");
+ break;;
+ case NCI_RF_TIMEOUT_ERROR:
+ GDEBUG("CORE_INTERFACE_ERROR_NTF (Timeout)");
+ 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;
+}
+
+static
+void
+nci_state_listen_active_rf_deactivate_ntf(
+ NciState* self,
+ const GUtilData* payload)
+{
+ NciSm* sm = nci_state_sm(self);
+
+ /*
+ * Table 62: Control Messages for RF Interface Deactivation
+ *
+ * RF_DEACTIVATE_NTF
+ *
+ * +=========================================================+
+ * | Offset | Size | Description |
+ * +=========================================================+
+ * | 0 | 1 | Deactivation Type |
+ * | 1 | 1 | Deactivation Reason |
+ * +=========================================================+
+ */
+ if (payload->size >= 2) {
+ switch ((NCI_DEACTIVATION_TYPE)payload->bytes[0]) {
+ case NCI_DEACTIVATE_TYPE_SLEEP:
+ GDEBUG("RF_DEACTIVATE_NTF Sleep (%u)", payload->bytes[1]);
+ nci_sm_enter_state(sm, NCI_RFST_LISTEN_SLEEP, NULL);
+ return;
+ case NCI_DEACTIVATE_TYPE_SLEEP_AF:
+ GDEBUG("RF_DEACTIVATE_NTF Sleep_AF (%u)", payload->bytes[1]);
+ nci_sm_enter_state(sm, NCI_RFST_LISTEN_SLEEP, NULL);
+ return;
+ case NCI_DEACTIVATE_TYPE_IDLE:
+ case NCI_DEACTIVATE_TYPE_DISCOVERY:
+ break;
+ }
+ }
+ /* Default handling (transition to IDLE or DISCOVERY) */
+ nci_sm_handle_rf_deactivate_ntf(sm, payload);
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NciState*
+nci_state_listen_active_new(
+ NciSm* sm)
+{
+ NciState* self = g_object_new(THIS_TYPE, NULL);
+
+ nci_state_init_base(self, sm, NCI_RFST_LISTEN_ACTIVE, "RFST_LISTEN_ACTIVE");
+ return self;
+}
+
+/*==========================================================================*
+ * Methods
+ *==========================================================================*/
+
+static
+void
+nci_state_listen_active_handle_ntf(
+ NciState* self,
+ guint8 gid,
+ guint8 oid,
+ const GUtilData* payload)
+{
+ switch (gid) {
+ case NCI_GID_CORE:
+ switch (oid) {
+ case NCI_OID_CORE_INTERFACE_ERROR:
+ if (nci_state_listen_active_interface_error_ntf(self, payload)) {
+ return;
+ }
+ break;
+ }
+ break;
+ case NCI_GID_RF:
+ switch (oid) {
+ case NCI_OID_RF_DEACTIVATE:
+ nci_state_listen_active_rf_deactivate_ntf(self, payload);
+ return;
+ }
+ break;
+ }
+ NCI_STATE_CLASS(PARENT_CLASS)->handle_ntf(self, gid, oid, payload);
+}
+
+/*==========================================================================*
+ * Internals
+ *==========================================================================*/
+
+static
+void
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_state_listen_sleep.c
^
|
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2020 Jolla Ltd.
+ * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nci_sm.h"
+#include "nci_state_impl.h"
+#include "nci_util.h"
+#include "nci_log.h"
+
+typedef NciState NciStateListenSleep;
+typedef NciStateClass NciStateListenSleepClass;
+
+GType nci_state_listen_sleep_get_type(void) NCI_INTERNAL;
+#define THIS_TYPE (nci_state_listen_sleep_get_type())
+#define PARENT_CLASS (nci_state_listen_sleep_parent_class)
+
+G_DEFINE_TYPE(NciStateListenSleep, nci_state_listen_sleep, NCI_TYPE_STATE)
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+nci_state_listen_sleep_intf_activated_ntf(
+ NciState* self,
+ const GUtilData* payload)
+{
+ NciIntfActivationNtf ntf;
+ NciModeParam mode_param;
+ NciActivationParam activation_param;
+ NciSm* sm = nci_state_sm(self);
+
+ /*
+ * 5.2.7 State RFST_LISTEN_SLEEP
+ *
+ * ...
+ * If the NFCC receives a valid RF wake up command(s) followed
+ * by successful activation procedure, the NFCC SHALL send
+ * RF_INTF_ACTIVATED_NTF (Listen mode) to the DH. At that point,
+ * the state is changed back to RFST_LISTEN_ACTIVE.
+ */
+ if (nci_parse_intf_activated_ntf(&ntf, &mode_param, &activation_param,
+ payload->bytes, payload->size)) {
+ 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);
+ }
+ }
+ /* Oops */
+ nci_sm_stall(sm, NCI_STALL_ERROR);
+}
+
+static
+void
+nci_state_listen_sleep_rf_deactivate_ntf(
+ NciState* self,
+ const GUtilData* payload)
+{
+ NciSm* sm = nci_state_sm(self);
+
+ /*
+ * Table 62: Control Messages for RF Interface Deactivation
+ *
+ * RF_DEACTIVATE_NTF
+ *
+ * +=========================================================+
+ * | Offset | Size | Description |
+ * +=========================================================+
+ * | 0 | 1 | Deactivation Type |
+ * | 1 | 1 | Deactivation Reason |
+ * +=========================================================+
+ */
+ if (payload->size >= 2) {
+ const NCI_DEACTIVATION_TYPE type = payload->bytes[0];
+
+ switch (type) {
+ case NCI_DEACTIVATE_TYPE_DISCOVERY:
+ /*
+ * 5.2.7 State RFST_LISTEN_SLEEP
+ *
+ * ...
+ * On detection of remote RF field off, the NFCC SHALL send
+ * RF_DEACTIVATE_NTF (Discovery, RF Link Loss) to the DH. The
+ * RF Communication state will then change to RFST_DISCOVERY.
+ */
+ GDEBUG("RF_DEACTIVATE_NTF Discovery (%d)", payload->bytes[1]);
+ nci_sm_enter_state(sm, NCI_RFST_DISCOVERY, NULL);
+ return;
+ case NCI_DEACTIVATE_TYPE_SLEEP_AF:
+ case NCI_DEACTIVATE_TYPE_SLEEP:
+ case NCI_DEACTIVATE_TYPE_IDLE:
+ break;
+ }
+ GDEBUG("Unexpected RF_DEACTIVATE_NTF %d (%u)", type, payload->bytes[1]);
+ } else {
+ GWARN("Failed to parse RF_DEACTIVATE_NTF");
+ }
+ /* Oops */
+ nci_sm_stall(sm, NCI_STALL_ERROR);
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NciState*
+nci_state_listen_sleep_new(
+ NciSm* sm)
+{
+ NciState* self = g_object_new(THIS_TYPE, NULL);
+
+ nci_state_init_base(self, sm, NCI_RFST_LISTEN_SLEEP, "RFST_LISTEN_SLEEP");
+ return self;
+}
+
+/*==========================================================================*
+ * Methods
+ *==========================================================================*/
+
+static
+void
+nci_state_listen_sleep_handle_ntf(
+ NciState* self,
+ guint8 gid,
+ guint8 oid,
+ const GUtilData* payload)
+{
+ switch (gid) {
+ case NCI_GID_RF:
+ switch (oid) {
+ case NCI_OID_RF_INTF_ACTIVATED:
+ nci_state_listen_sleep_intf_activated_ntf(self, payload);
+ return;
+ case NCI_OID_RF_DEACTIVATE:
+ nci_state_listen_sleep_rf_deactivate_ntf(self, payload);
+ return;
+ }
+ break;
+ }
+ NCI_STATE_CLASS(PARENT_CLASS)->handle_ntf(self, gid, oid, payload);
+}
+
+/*==========================================================================*
+ * Internals
+ *==========================================================================*/
+
+static
+void
+nci_state_listen_sleep_init(
+ NciStateListenSleep* self)
+{
+}
+
+static
+void
+nci_state_listen_sleep_class_init(
+ NciStateListenSleepClass* klass)
+{
+ NCI_STATE_CLASS(klass)->handle_ntf = nci_state_listen_sleep_handle_ntf;
+}
+
+/*
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_state_poll_active.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:
*
@@ -77,18 +77,27 @@
*/
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)");
- return TRUE;
+ break;
case NCI_RF_PROTOCOL_ERROR:
GDEBUG("CORE_INTERFACE_ERROR_NTF (Protocol Error)");
- return TRUE;
+ break;;
case NCI_RF_TIMEOUT_ERROR:
GDEBUG("CORE_INTERFACE_ERROR_NTF (Timeout)");
- return TRUE;
+ break;
+ default:
+ /* Unrecognized notification */
+ return FALSE;
}
+ /* Deactivate the link */
+ nci_sm_switch_to(nci_state_sm(self), NCI_RFST_DISCOVERY);
+ return TRUE;
}
- /* Unrecornized notification */
+ /* Unrecognized notification */
return FALSE;
}
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_state_w4_host_select.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:
*
@@ -65,8 +65,9 @@
*/
if (ntf_a->protocol != ntf_b->protocol) {
static const NCI_PROTOCOL protocol_order[] = {
- NCI_PROTOCOL_T2T,
- NCI_PROTOCOL_ISO_DEP
+ NCI_PROTOCOL_NFC_DEP,
+ NCI_PROTOCOL_ISO_DEP,
+ NCI_PROTOCOL_T2T
};
guint i;
@@ -163,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);
@@ -176,6 +193,10 @@
payload, nci_state_w4_host_select_rsp, self);
g_bytes_unref(payload);
g_slist_free(selected);
+ } else {
+ /* We haven't found anything suitable */
+ GDEBUG("Nothing to select");
+ nci_sm_switch_to(sm, NCI_RFST_DISCOVERY);
}
}
}
@@ -206,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);
@@ -247,10 +273,11 @@
switch (pkt[0]) {
case NCI_DISCOVERY_TARGET_ACTIVATION_FAILED:
GDEBUG("CORE_GENERIC_ERROR_NTF (Activation Failed)");
+ nci_sm_switch_to(nci_state_sm(self), NCI_RFST_DISCOVERY);
return TRUE;
}
}
- /* Unrecornized notification */
+ /* Unrecognized notification */
return FALSE;
}
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_transition.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,6 +30,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
#include "nci_transition.h"
#include "nci_transition_impl.h"
#include "nci_state.h"
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_transition.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -47,7 +47,7 @@
NciState* dest;
};
-GType nci_transition_get_type(void);
+GType nci_transition_get_type(void) NCI_INTERNAL;
#define NCI_TYPE_TRANSITION (nci_transition_get_type())
#define NCI_TRANSITION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NCI_TYPE_TRANSITION, NciTransition))
@@ -60,48 +60,58 @@
NciTransition*
nci_transition_ref(
- NciTransition* transition);
+ NciTransition* transition)
+ NCI_INTERNAL;
void
nci_transition_unref(
- NciTransition* transition);
+ NciTransition* transition)
+ NCI_INTERNAL;
gboolean
nci_transition_start(
- NciTransition* self);
+ NciTransition* transition)
+ NCI_INTERNAL;
void
nci_transition_finished(
- NciTransition* self);
+ NciTransition* transition)
+ NCI_INTERNAL;
void
nci_transition_handle_ntf(
NciTransition* transition,
guint8 gid,
guint8 oid,
- const GUtilData* payload);
+ const GUtilData* payload)
+ NCI_INTERNAL;
/* Specific transitions */
-NciTransition*
+NciTransition*
nci_transition_reset_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
-NciTransition*
+NciTransition*
nci_transition_idle_to_discovery_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
+
+NciTransition*
+nci_transition_deactivate_to_discovery_new(
+ NciSm* sm)
+ NCI_INTERNAL;
-NciTransition*
+NciTransition*
nci_transition_deactivate_to_idle_new(
- NciSm* sm);
+ NciSm* sm)
+ NCI_INTERNAL;
-NciTransition*
-nci_transition_poll_active_to_discovery_new(
- NciSm* sm);
-
-NciTransition*
-nci_transition_poll_active_to_idle_new(
- NciSm* sm);
+NciTransition*
+nci_transition_active_to_idle_new(
+ NciSm* sm)
+ NCI_INTERNAL;
#endif /* NCI_TRANSITION_H */
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.10.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:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_transition_deactivate_to_discovery.c
^
|
@@ -0,0 +1,208 @@
+/*
+ * 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
+ *
+ * ...
+ * If the DH sends RF_DEACTIVATE_CMD (Discovery), the NFCC SHALL send
+ * RF_DEACTIVATE_RSP followed by RF_DEACTIVATE_NTF (Discovery, DH Request)
+ * upon successful deactivation. The state will then change to RFST_DISCOVERY
+ * where the NFCC SHALL either restart or continue the Polling discovery
+ * activity.
+ *
+ * 5.2.6 State RFST_LISTEN_ACTIVE
+ *
+ * ...
+ * DH SHALL send RF_DEACTIVATE_CMD (Discovery) to the NFCC, which SHALL
+ * answer RF_DEACTIVATE_RSP followed by RF_DEACTIVATE_NTF (Discovery,
+ * DH Request). The state will then change to RFST_DISCOVERY.
+ *==========================================================================*/
+
+typedef NciTransition NciTransitionDeactivateToDiscovery;
+typedef NciTransitionClass NciTransitionDeactivateToDiscoveryClass;
+
+GType nci_transition_deactivate_to_discovery_get_type(void) NCI_INTERNAL;
+#define THIS_TYPE (nci_transition_deactivate_to_discovery_get_type())
+#define PARENT_CLASS (nci_transition_deactivate_to_discovery_parent_class)
+
+G_DEFINE_TYPE(NciTransitionDeactivateToDiscovery,
+ nci_transition_deactivate_to_discovery, NCI_TYPE_TRANSITION)
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+void
+nci_transition_deactivate_to_discovery_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");
+ return;
+ } else if (status == NCI_REQUEST_TIMEOUT) {
+ GDEBUG("RF_DEACTIVATE (Idle) timed out");
+ } 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);
+ nci_sm_enter_state(nci_transition_sm(self), NCI_RFST_IDLE, NULL);
+ return;
+ } 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);
+}
+
+static
+void
+nci_transition_deactivate_to_discovery_rsp(
+ NCI_REQUEST_STATUS status,
+ const GUtilData* payload,
+ NciTransition* self)
+{
+ if (status == NCI_REQUEST_CANCELLED || !nci_transition_active(self)) {
+ GDEBUG("RF_DEACTIVATE (Discovery) cancelled");
+ } else if (status == NCI_REQUEST_TIMEOUT) {
+ GDEBUG("RF_DEACTIVATE (Discovery) 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 (Discovery) ok", DIR_IN);
+ /* Wait for RF_DEACTIVATE_NTF */
+ } else {
+ /* Try to deactivate to IDLE */
+ GWARN("RF_DEACTIVATE_CMD (Discovery) failed");
+ nci_transition_deactivate_to_idle(self,
+ nci_transition_deactivate_to_discovery_idle_rsp);
+ }
+ } else {
+ nci_transition_stall(self, NCI_STALL_ERROR);
+ }
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NciTransition*
+nci_transition_deactivate_to_discovery_new(
+ NciSm* sm)
+{
+ NciState* dest = nci_sm_get_state(sm, NCI_RFST_DISCOVERY);
+
+ if (dest) {
+ NciTransition* self = g_object_new(THIS_TYPE, NULL);
+
+ nci_transition_init_base(self, sm, dest);
+ return self;
+ }
+ return NULL;
+}
+
+/*==========================================================================*
+ * Methods
+ *==========================================================================*/
+
+static
+gboolean
+nci_transition_deactivate_to_discovery_start(
+ NciTransition* self)
+{
+ return nci_transition_deactivate_to_discovery(self,
+ nci_transition_deactivate_to_discovery_rsp);
+}
+
+static
+void
+nci_transition_deactivate_to_discovery_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);
+}
+
+/*==========================================================================*
+ * Internals
+ *==========================================================================*/
+
+static
+void
+nci_transition_deactivate_to_discovery_init(
+ NciTransitionDeactivateToDiscovery* self)
+{
+}
+
+static
+void
+nci_transition_deactivate_to_discovery_class_init(
+ NciTransitionDeactivateToDiscoveryClass* klass)
+{
+ klass->start = nci_transition_deactivate_to_discovery_start;
+ klass->handle_ntf = nci_transition_deactivate_to_discovery_handle_ntf;
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_transition_idle_to_discovery.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:
*
@@ -42,16 +42,34 @@
typedef NciTransition NciTransitionIdleToDiscovery;
typedef NciTransitionClass NciTransitionIdleToDiscoveryClass;
-G_DEFINE_TYPE(NciTransitionIdleToDiscovery, nci_transition_idle_to_discovery,
- NCI_TYPE_TRANSITION)
+GType nci_transition_idle_to_discovery_get_type(void) NCI_INTERNAL;
#define THIS_TYPE (nci_transition_idle_to_discovery_get_type())
#define PARENT_CLASS (nci_transition_idle_to_discovery_parent_class)
+G_DEFINE_TYPE(NciTransitionIdleToDiscovery, nci_transition_idle_to_discovery,
+ NCI_TYPE_TRANSITION)
+
/*==========================================================================*
* Implementation
*==========================================================================*/
static
+gboolean
+nci_transition_idle_to_discovery_send_byte_array(
+ NciTransition* self,
+ guint8 gid,
+ guint8 oid,
+ GByteArray* cmd,
+ NciTransitionResponseFunc resp)
+{
+ GBytes* bytes = g_byte_array_free_to_bytes(cmd);
+ gboolean ret = nci_transition_send_command(self, gid, oid, bytes, resp);
+
+ g_bytes_unref(bytes);
+ return ret;
+}
+
+static
void
nci_transition_idle_to_discovery_discover_rsp(
NCI_REQUEST_STATUS status,
@@ -97,6 +115,9 @@
nci_transition_idle_to_discovery_discover(
NciTransition* self)
{
+ NciSm* sm = nci_transition_sm(self);
+ GByteArray* cmd = g_byte_array_sized_new(7);
+
/*
* Table 52: Control Messages to Start Discovery
*
@@ -112,17 +133,92 @@
* | | | 1 | Frequency (1 = every period) |
* +=========================================================+
*/
- static const guint8 cmd[] = {
- 0x04,
- NCI_MODE_PASSIVE_POLL_A, 1,
- NCI_MODE_PASSIVE_POLL_B, 1,
- NCI_MODE_PASSIVE_POLL_F, 1,
- NCI_MODE_PASSIVE_POLL_15693, 1
+ static const guint8 cmd_header[] = {
+ 0x00, /* Number of Configurations */
};
GDEBUG("%c RF_DISCOVER_CMD", DIR_OUT);
- nci_transition_send_command_static(self, NCI_GID_RF, NCI_OID_RF_DISCOVER,
- cmd, sizeof(cmd), nci_transition_idle_to_discovery_discover_rsp);
+ 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)) {
+ static const guint8 entries[] = {
+ NCI_MODE_PASSIVE_POLL_A, 1,
+ NCI_MODE_ACTIVE_POLL_A, 1
+ };
+
+ GDEBUG(" PassivePollA");
+ GDEBUG(" ActivePollA");
+ 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_POLL)) ==
+ (NFC_OP_MODE_PEER|NFC_OP_MODE_POLL)) {
+ static const guint8 entries[] = {
+ NCI_MODE_PASSIVE_POLL_F, 1,
+ NCI_MODE_ACTIVE_POLL_F, 1
+ };
+
+ 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;
+ }
+ if ((sm->op_mode & NFC_OP_MODE_CE) ||
+ (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_A, 1,
+ NCI_MODE_ACTIVE_LISTEN_A, 1
+ };
+
+ GDEBUG(" PassiveListenA");
+ GDEBUG(" ActiveListenA");
+ 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,
+ nci_transition_idle_to_discovery_discover_rsp);
}
static
@@ -171,6 +267,9 @@
nci_transition_idle_to_discover_map(
NciTransition* self)
{
+ NciSm* sm = nci_transition_sm(self);
+ GByteArray* cmd = g_byte_array_sized_new(22);
+
/*
* Table 42: Control Messages for RF Interface Mapping Configuration
*
@@ -187,62 +286,79 @@
* | | | 2 | RF Interface |
* +=========================================================+
*/
- static const guint8 cmd[] = {
- 0x05,
-
- NCI_PROTOCOL_T1T,
- NCI_DISCOVER_MAP_MODE_POLL,
- NCI_RF_INTERFACE_FRAME,
-
- NCI_PROTOCOL_T2T,
- NCI_DISCOVER_MAP_MODE_POLL,
- NCI_RF_INTERFACE_FRAME,
-
- NCI_PROTOCOL_T3T,
- NCI_DISCOVER_MAP_MODE_POLL,
- NCI_RF_INTERFACE_FRAME,
-
- NCI_PROTOCOL_ISO_DEP,
- NCI_DISCOVER_MAP_MODE_POLL,
- NCI_RF_INTERFACE_ISO_DEP,
-
- NCI_PROTOCOL_NFC_DEP,
- NCI_DISCOVER_MAP_MODE_POLL,
- NCI_RF_INTERFACE_NFC_DEP
+ static const guint8 cmd_header[] = {
+ 0x00, /* Number of Mapping Configurations */
};
GDEBUG("%c RF_DISCOVER_MAP_CMD", DIR_OUT);
- return nci_transition_send_command_static(self, NCI_GID_RF,
- NCI_OID_RF_DISCOVER_MAP, cmd, sizeof(cmd),
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_transition_impl.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -57,54 +57,63 @@
void
nci_transition_init_base(
- NciTransition* self,
+ NciTransition* transition,
NciSm* sm,
- NciState* dest);
+ NciState* dest)
+ NCI_INTERNAL;
NciSm*
nci_transition_sm(
- NciTransition* self);
+ NciTransition* transition)
+ NCI_INTERNAL;
void
nci_transition_finish(
- NciTransition* self,
- void* param);
+ NciTransition* transition,
+ void* param)
+ NCI_INTERNAL;
void
nci_transition_stall(
- NciTransition* self,
- NCI_STALL stall);
+ NciTransition* transition,
+ NCI_STALL stall)
+ NCI_INTERNAL;
gboolean
nci_transition_active(
- NciTransition* self);
+ NciTransition* transition)
+ NCI_INTERNAL;
gboolean
nci_transition_send_command(
- NciTransition* self,
+ NciTransition* transition,
guint8 gid,
guint8 oid,
GBytes* payload,
- NciTransitionResponseFunc resp);
+ NciTransitionResponseFunc resp)
+ NCI_INTERNAL;
gboolean
nci_transition_send_command_static(
- NciTransition* self,
+ NciTransition* transition,
guint8 gid,
guint8 oid,
const void* payload,
gsize payload_len,
- NciTransitionResponseFunc resp);
+ NciTransitionResponseFunc resp)
+ NCI_INTERNAL;
gboolean
nci_transition_deactivate_to_idle(
- NciTransition* self,
- NciTransitionResponseFunc resp);
+ NciTransition* transition,
+ NciTransitionResponseFunc resp)
+ NCI_INTERNAL;
gboolean
nci_transition_deactivate_to_discovery(
- NciTransition* self,
- NciTransitionResponseFunc resp);
+ NciTransition* transition,
+ NciTransitionResponseFunc resp)
+ NCI_INTERNAL;
#endif /* NCI_TRANSITION_IMPL_H */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.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.10.tar.bz2/src/nci_types_p.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2020 Jolla Ltd.
+ * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -35,6 +35,8 @@
#include <nci_types.h>
+#define NCI_INTERNAL G_GNUC_INTERNAL
+
typedef struct nci_param NciParam;
typedef struct nci_sar NciSar;
typedef struct nci_sm NciSm;
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_util.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:
*
@@ -35,6 +35,30 @@
#include <gutil_macros.h>
+gboolean
+nci_listen_mode(
+ NCI_MODE mode)
+{
+ switch (mode) {
+ 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:
+ return TRUE;
+ case NCI_MODE_PASSIVE_POLL_A:
+ case NCI_MODE_PASSIVE_POLL_B:
+ case NCI_MODE_PASSIVE_POLL_F:
+ case NCI_MODE_ACTIVE_POLL_A:
+ case NCI_MODE_ACTIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_15693:
+ break;
+ }
+ /* Assume Poll by default */
+ return FALSE;
+}
+
const NciModeParam*
nci_parse_mode_param(
NciModeParam* param,
@@ -44,6 +68,10 @@
{
switch (mode) {
case NCI_MODE_ACTIVE_POLL_A:
+ if (!len) {
+ return NULL;
+ }
+ /* fallthrough */
case NCI_MODE_PASSIVE_POLL_A:
/*
* NFCForum-TS-NCI-1.0
@@ -103,7 +131,7 @@
* | Offset | Size | Description |
* +=========================================================+
* | 0 | 1 | SENSB_RES Response Length n (11 or 12) |
- * | 1 | n | Bytes 2-12 or 13 or SENSB_RES Response |
+ * | 1 | n | Bytes 2-12 or 13 of SENSB_RES Response |
* +=========================================================+
*
* NFCForum-TS-DigitalProtocol-1.0
@@ -150,19 +178,104 @@
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;
+
+#if GUTIL_LOG_DEBUG
+ if (GLOG_ENABLED(GLOG_LEVEL_DEBUG)) {
+ GString *buf = g_string_new(NULL);
+ guint 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]);
+ 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");
return NULL;
- default:
- GDEBUG("Unhandled activation mode %d", mode);
+ case NCI_MODE_ACTIVE_POLL_F:
+ case NCI_MODE_PASSIVE_POLL_F:
+ /*
+ * NFCForum-TS-NCI-1.0
+ * Table 58: Specific Parameters for NFC-F Poll Mode
+ *
+ * +=========================================================+
+ * | Offset | Size | Description |
+ * +=========================================================+
+ * | 0 | 1 | Bit Rate (1 = 212 kbps, 2 = 424 kbps) |
+ * | 1 | 1 | SENSB_REF Response Length n (16 or 18) |
+ * | 2 | n | Bytes 2-17 of SENSF_RES |
+ * +=========================================================+
+ */
+ if (len > 1 && bytes[1] >= 8 && (bytes[1] + 2) <= len) {
+ NciModeParamPollF* pf = ¶m->poll_f;
+
+ pf->bitrate = bytes[0];
+ memcpy(pf->nfcid2, bytes + 2, 8);
+ GDEBUG("NFC-F");
+ GDEBUG(" PollF.bitrate = %u%s", pf->bitrate,
+ (pf->bitrate == 1) ? " (212 kbps)" :
+ (pf->bitrate == 2) ? " (424 kbps)" : "");
+ GDEBUG(" PollF.nfcid2 = %02x %02x %02x %02x %02x %02x %02x %02x",
+ pf->nfcid2[0], pf->nfcid2[1], pf->nfcid2[2], pf->nfcid2[3],
+ pf->nfcid2[4], pf->nfcid2[5], pf->nfcid2[6], pf->nfcid2[7]);
+ return param;
+ }
+ /* 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_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;
}
gboolean
@@ -309,6 +422,200 @@
}
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 */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_util.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -35,19 +35,26 @@
#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);
+ guint len)
+ NCI_INTERNAL;
gboolean
nci_parse_discover_ntf(
NciDiscoveryNtf* ntf,
NciModeParam* param,
const guint8* bytes,
- guint len);
+ guint len)
+ NCI_INTERNAL;
gboolean
nci_parse_intf_activated_ntf(
@@ -55,16 +62,19 @@
NciModeParam* mode_param,
NciActivationParam* activation_param,
const guint8* pkt,
- guint len);
+ guint len)
+ NCI_INTERNAL;
NciDiscoveryNtf*
nci_discovery_ntf_copy_array(
const NciDiscoveryNtf* const* ntfs,
- guint count);
+ guint count)
+ NCI_INTERNAL;
NciDiscoveryNtf*
nci_discovery_ntf_copy(
- const NciDiscoveryNtf* ntf);
+ const NciDiscoveryNtf* ntf)
+ NCI_INTERNAL;
#endif /* NCI_UTIL_H */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.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.10.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.10.tar.bz2/unit/nci_core/test_nci_core.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:
*
@@ -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
@@ -136,9 +150,6 @@
static const guint8 CORE_SET_CONFIG_RSP_ERROR[] = {
0x40, 0x02, 0x02, NCI_STATUS_REJECTED, 0x00
};
-static const guint8 CORE_SET_CONFIG_RSP_INVALID_PARAM[] = {
- 0x40, 0x02, 0x03, NCI_STATUS_INVALID_PARAM, 0x01, 0x11
-};
static const guint8 RF_SET_LISTEN_MODE_ROUTING_RSP[] = {
0x41, 0x01, 0x01, 0x00
};
@@ -220,6 +231,19 @@
0x01, 0x09, 0x04, 0x00, 0x04, 0x37, 0xf4, 0x95,
0x95, 0x01, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00 /* Missing params */,
};
+static const guint8 RF_INTF_ACTIVATED_NTF_NFC_DEP_LISTEN_A[] = {
+ 0x61, 0x05, 0x2e, 0x01, 0x03, 0x05, 0x83, 0xfb,
+ 0x01, 0x00, 0x85, 0x02, 0x02, 0x23, 0x22, 0x10,
+ 0x5a, 0x37, 0xa5, 0x7b, 0x88, 0x6e, 0x6e, 0xef,
+ 0x45, 0x00, 0x00, 0x00, 0x32, 0x46, 0x66, 0x6d,
+ 0x01, 0x01, 0x12, 0x02, 0x02, 0x07, 0xff, 0x03,
+ 0x02, 0x00, 0x13, 0x04, 0x01, 0x64, 0x07, 0x01,
+ 0x03
+};
+static const guint8 RF_INTF_ACTIVATED_NTF_CE_A[] = {
+ 0x61, 0x05, 0x0c, 0x01, 0x02, 0x04, 0x80, 0xff,
+ 0x01, 0x00, 0x80, 0x00, 0x00, 0x01, 0x80
+};
static const guint8 RF_DEACTIVATE_RSP[] = {
0x41, 0x06, 0x01, 0x00
};
@@ -235,6 +259,15 @@
static const guint8 RF_DEACTIVATE_NTF_DISCOVERY[] = {
0x61, 0x06, 0x02, 0x03, 0x00
};
+static const guint8 RF_DEACTIVATE_NTF_DISCOVERY_EP_REQUEST[] = {
+ 0x61, 0x06, 0x02, 0x03, 0x01
+};
+static const guint8 RF_DEACTIVATE_NTF_SLEEP_EP_REQUEST[] = {
+ 0x61, 0x06, 0x02, 0x01, 0x01
+};
+static const guint8 RF_DEACTIVATE_NTF_SLEEP_AF_EP_REQUEST[] = {
+ 0x61, 0x06, 0x02, 0x02, 0x01
+};
static const guint8 RF_DEACTIVATE_NTF_BROKEN[] = {
0x61, 0x06, 0x00
};
@@ -244,6 +277,9 @@
static const guint8 CORE_GENERIC_TARGET_ACTIVATION_FAILED_ERROR_NTF[] = {
0x60, 0x07, 0x01, NCI_DISCOVERY_TARGET_ACTIVATION_FAILED
};
+static const guint8 CORE_GENERIC_TEAR_DOWN_ERROR_NTF[] = {
+ 0x60, 0x07, 0x01, NCI_DISCOVERY_TEAR_DOWN
+};
static const guint8 CORE_GENERIC_ERROR_NTF_BROKEN[] = {
0x60, 0x07, 0x00
};
@@ -259,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
};
@@ -290,6 +329,11 @@
0x00, 0x04, 0x4f, 0x01, 0x74, 0x01, 0x01, 0x08,
0x02
};
+static const guint8 RF_DISCOVER_NTF_PROPRIETARY_MORE[] = {
+ 0x61, 0x03, 0x0e, 0x02, 0x80, 0x00, 0x09, 0x04,
+ 0x00, 0x04, 0x4f, 0x01, 0x74, 0x01, 0x01, 0x08,
+ 0x02
+};
static const guint8 RF_DISCOVER_NTF_2_PROPRIETARY_LAST[] = {
0x61, 0x03, 0x0e, 0x02, 0x80, 0x00, 0x09, 0x04,
0x00, 0x04, 0x4f, 0x01, 0x74, 0x01, 0x01, 0x08,
@@ -305,32 +349,23 @@
};
static
-gboolean
-test_timeout(
- gpointer loop)
-{
- g_assert(!"TIMEOUT");
- return G_SOURCE_REMOVE;
-}
-
-static
-guint
-test_setup_timeout(
- GMainLoop* loop)
+void
+test_bytes_unref(
+ gpointer bytes)
{
- if (!(test_opt.flags & TEST_FLAG_DEBUG)) {
- return g_timeout_add_seconds(TEST_TIMEOUT, test_timeout, loop);
- } else {
- return 0;
- }
+ g_bytes_unref(bytes);
}
static
void
-test_bytes_unref(
- gpointer bytes)
+test_data_packet_handler_not_reached(
+ NciCore* nci,
+ guint8 cid,
+ const void* payload,
+ guint len,
+ void* user_data)
{
- g_bytes_unref(bytes);
+ g_assert_not_reached();
}
/*==========================================================================*
@@ -395,6 +430,7 @@
NciHalClient* sar;
void* test_data;
guint fail_write;
+ guint rsp_expected;
} TestHalIo;
typedef struct test_hal_io_read {
@@ -496,7 +532,8 @@
hal->read_id = 0;
test_hal_io_flush_ntf(hal);
- if (test_hal_io_next_rsp(hal)) {
+ if (hal->rsp_expected && test_hal_io_next_rsp(hal)) {
+ hal->rsp_expected--;
test_hal_io_read_one(hal);
test_hal_io_flush_ntf(hal);
}
@@ -513,6 +550,7 @@
g_assert(hal->write_id);
hal->write_id = 0;
+ hal->rsp_expected++;
g_ptr_array_add(hal->written, g_bytes_ref(write->bytes));
if (write->complete) {
write->complete(hal->sar, TRUE);
@@ -704,6 +742,7 @@
nci_core_remove_handler(nci, 0);
nci_core_set_state(NULL, NCI_STATE_INIT);
+ nci_core_set_op_mode(NULL, NFC_OP_MODE_NONE);
nci_core_cancel(NULL, 0);
nci_core_remove_handler(NULL, 0);
nci_core_restart(NULL);
@@ -734,7 +773,6 @@
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.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.10.tar.bz2/unit/nci_sm/test_nci_sm.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:
*
@@ -229,9 +229,8 @@
NciSm* null = NULL;
gulong zero = 0;
- g_assert(!nci_param_w4_all_discoveries_new(NULL));
-
nci_sm_free(null);
+ nci_sm_set_op_mode(null, NFC_OP_MODE_NONE);
nci_sm_handle_ntf(null, 0, 0, NULL);
nci_sm_add_state(null, NULL);
nci_sm_add_state(sm, NULL);
@@ -263,6 +262,7 @@
g_assert(!nci_sm_send_command(sm, 0, 0, NULL, NULL, NULL));
g_assert(!nci_sm_send_command_static(null, 0, 0, NULL, 0, NULL, NULL));
g_assert(!nci_sm_send_command_static(sm, 0, 0, NULL, 0, NULL, NULL));
+ nci_sm_handle_conn_credits_ntf(null, NULL);
nci_sm_intf_activated(null, NULL);
nci_sm_stall(null, NCI_STALL_ERROR);
nci_sm_switch_to(null, NCI_STATE_INIT);
@@ -307,8 +307,24 @@
test_transition(
void)
{
+ NciSm* sm = nci_sm_new(NULL);
NciTransition* null = NULL;
+ NciTransition* reset = nci_transition_reset_new(sm);
+ NciTransition* idle_to_discovery =
+ nci_transition_idle_to_discovery_new(sm);
+ NciTransition* deactivate_to_discovery =
+ nci_transition_deactivate_to_discovery_new(sm);
+ NciTransition* deactivate_to_idle =
+ nci_transition_deactivate_to_idle_new(sm);
+ NciTransition* active_to_idle = nci_transition_active_to_idle_new(sm);
+ g_assert(!nci_param_w4_all_discoveries_new(NULL));
+
+ g_assert(!nci_transition_reset_new(NULL));
+ 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_active_to_idle_new(NULL));
g_assert(!nci_transition_sm(null));
g_assert(!nci_transition_ref(null));
nci_transition_unref(null);
@@ -320,6 +336,70 @@
nci_transition_handle_ntf(null, 0, 0, NULL);
g_assert(!nci_transition_send_command(null, 0, 0, NULL, NULL));
g_assert(!nci_transition_send_command_static(null, 0, 0, NULL, 0, NULL));
+
+ /* No transition is ongoing */
+ g_assert(!nci_sm_active_transition(sm, reset));
+
+ /* Transitions keep weak pointer to NciSm. Once NciSm gets deallocated,
+ * nci_transition_start() must fail. */
+ nci_sm_free(sm);
+
+ g_assert(!nci_transition_start(reset));
+ 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(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(active_to_idle);
+}
+
+/*==========================================================================*
+ * protocol
+ *==========================================================================*/
+
+static
+void
+test_protocol(
+ void)
+{
+ NciSm* sm = nci_sm_new(NULL);
+ NciSm* null = NULL;
+
+ g_assert(!nci_sm_supports_protocol(null, NCI_PROTOCOL_T1T));
+ g_assert(!nci_sm_supports_protocol(null, NCI_PROTOCOL_T2T));
+ g_assert(!nci_sm_supports_protocol(null, NCI_PROTOCOL_T3T));
+ g_assert(!nci_sm_supports_protocol(null, NCI_PROTOCOL_ISO_DEP));
+ g_assert(!nci_sm_supports_protocol(null, NCI_PROTOCOL_NFC_DEP));
+ g_assert(!nci_sm_supports_protocol(null, NCI_PROTOCOL_UNDETERMINED));
+ g_assert(!nci_sm_supports_protocol(null, NCI_PROTOCOL_PROPRIETARY));
+
+ nci_sm_set_op_mode(sm, NFC_OP_MODE_NONE);
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_T1T));
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_T2T));
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_T3T));
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_ISO_DEP));
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_NFC_DEP));
+
+ nci_sm_set_op_mode(sm, NFC_OP_MODE_RW);
+ g_assert(nci_sm_supports_protocol(sm, NCI_PROTOCOL_T2T));
+ g_assert(nci_sm_supports_protocol(sm, NCI_PROTOCOL_ISO_DEP));
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_NFC_DEP));
+
+ nci_sm_set_op_mode(sm, NFC_OP_MODE_PEER);
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_T2T));
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_ISO_DEP));
+ g_assert(nci_sm_supports_protocol(sm, NCI_PROTOCOL_NFC_DEP));
+
+ nci_sm_set_op_mode(sm, NFC_OP_MODE_CE);
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_T2T));
+ g_assert(nci_sm_supports_protocol(sm, NCI_PROTOCOL_ISO_DEP));
+ g_assert(!nci_sm_supports_protocol(sm, NCI_PROTOCOL_NFC_DEP));
+
+ nci_sm_free(sm);
}
/*==========================================================================*
@@ -564,6 +644,7 @@
g_test_add_func(TEST_("null"), test_null);
g_test_add_func(TEST_("state"), test_state);
g_test_add_func(TEST_("transition"), test_transition);
+ g_test_add_func(TEST_("protocol"), test_protocol);
g_test_add_func(TEST_("weak_ptr"), test_weak_ptr);
g_test_add_func(TEST_("add_state"), test_add_state);
g_test_add_func(TEST_("last_state"), test_last_state);
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.10.tar.bz2/unit/nci_util/test_nci_util.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:
*
@@ -50,6 +50,35 @@
}
/*==========================================================================*
+ * listen_mode
+ *==========================================================================*/
+
+static
+void
+test_listen_mode(
+ void)
+{
+ /* Listen modes */
+ g_assert(nci_listen_mode(NCI_MODE_PASSIVE_LISTEN_A));
+ g_assert(nci_listen_mode(NCI_MODE_PASSIVE_LISTEN_B));
+ g_assert(nci_listen_mode(NCI_MODE_PASSIVE_LISTEN_F));
+ g_assert(nci_listen_mode(NCI_MODE_ACTIVE_LISTEN_A));
+ g_assert(nci_listen_mode(NCI_MODE_ACTIVE_LISTEN_F));
+ g_assert(nci_listen_mode(NCI_MODE_PASSIVE_LISTEN_15693));
+
+ /* Poll modes */
+ g_assert(!nci_listen_mode(NCI_MODE_PASSIVE_POLL_A));
+ g_assert(!nci_listen_mode(NCI_MODE_PASSIVE_POLL_B));
+ g_assert(!nci_listen_mode(NCI_MODE_PASSIVE_POLL_F));
+ g_assert(!nci_listen_mode(NCI_MODE_ACTIVE_POLL_A));
+ g_assert(!nci_listen_mode(NCI_MODE_ACTIVE_POLL_F));
+ g_assert(!nci_listen_mode(NCI_MODE_PASSIVE_POLL_15693));
+
+ /* Invalid mode */
+ g_assert(!nci_listen_mode((NCI_MODE)(-1)));
+}
+
+/*==========================================================================*
* mode_param_ok
*==========================================================================*/
@@ -85,6 +114,21 @@
{ 0x0b, 0x65, 0xe6, 0x70, 0x15, 0xe1, 0xf3, 0x5e, 0x11, 0x77, 0x87, 0x95 };
static const guint8 mode_param_success_data_poll_b_rfu[] =
{ 0x0b, 0x65, 0xe6, 0x70, 0x15, 0xe1, 0xf3, 0x5e, 0x11, 0x77, 0x97, 0x95 };
+static const guint8 mode_param_success_data_poll_f_1[] =
+ { 0x01, 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_poll_f_2[] =
+ { 0x02, 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_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",
@@ -107,12 +151,47 @@
.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,
+ .data = { TEST_ARRAY_AND_SIZE(mode_param_success_data_poll_f_1) },
+ .expected = { .poll_f = { 1, {0x01, 0xfe, 0xc0, 0xf1,
+ 0xc4, 0x41, 0x38, 0x21} } }
+ },{
+ .name = "passive_poll_f",
+ .mode = NCI_MODE_PASSIVE_POLL_F,
+ .data = { TEST_ARRAY_AND_SIZE(mode_param_success_data_poll_f_2) },
+ .expected = { .poll_f = { 2, {0x01, 0xfe, 0xc0, 0xf1,
+ 0xc4, 0x41, 0x38, 0x21} } }
+ },{
+ .name = "passive_poll_f_3",
+ .mode = NCI_MODE_PASSIVE_POLL_F,
+ .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) }
}
};
@@ -149,11 +228,26 @@
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x01, 0x20 };
static const guint8 mode_param_fail_pollb_data_too_short_1[] =
{ 0x0a, 0x65, 0xe6, 0x70, 0x15, 0xe1, 0xf3, 0x5e, 0x11, 0x77, 0x87 };
+static const guint8 mode_param_fail_pollf_data_too_short_1[] =
+ { 0x01, 0x12, 0x01, 0xfe, 0xc0, 0xf1, 0xc4, 0x41, 0x38, 0x21, 0xc0, 0xc1,
+ 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",
+ .mode = (NCI_MODE)(-1)
+ },{
.name = "unhandled_mode",
.mode = NCI_MODE_PASSIVE_LISTEN_15693
},{
+ .name = "listen_mode",
+ .mode = NCI_MODE_PASSIVE_LISTEN_A
+ },{
.name = "passive_poll_a_empty",
.mode = NCI_MODE_PASSIVE_POLL_A,
.data = { NULL, 0 }
@@ -170,6 +264,10 @@
.mode = NCI_MODE_ACTIVE_POLL_A,
.data = { TEST_ARRAY_AND_SIZE(mode_param_fail_data_too_short_1) }
},{
+ .name = "too_short/poll_f",
+ .mode = NCI_MODE_ACTIVE_POLL_F,
+ .data = { TEST_ARRAY_AND_SIZE(mode_param_fail_data_too_short_1) }
+ },{
.name = "too_short/2",
.mode = NCI_MODE_ACTIVE_POLL_A,
.data = { TEST_ARRAY_AND_SIZE(mode_param_fail_data_too_short_2) }
@@ -189,6 +287,360 @@
.name = "poll_b_too_short",
.mode = NCI_MODE_PASSIVE_POLL_B,
.data = { TEST_ARRAY_AND_SIZE(mode_param_fail_pollb_data_too_short_1) }
+ },{
+ .name = "poll_f_too_short_1",
+ .mode = NCI_MODE_PASSIVE_POLL_F,
+ .data = { TEST_ARRAY_AND_SIZE(mode_param_fail_pollf_data_too_short_1) }
+ },{
+ .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) }
+ }
+};
+
+/*==========================================================================*
+ * intf_activated_success
+ *==========================================================================*/
+
+typedef struct test_intf_activated_success_data {
+ const char* name;
+ GUtilData data;
+ const NciModeParam* mode_param;
+ const NciActivationParam* activation_param;
+} TestIntfActivatedSuccessData;
+
+static
+void
+test_intf_activated_success(
+ gconstpointer user_data)
+{
+ const TestIntfActivatedSuccessData* test = user_data;
+ NciIntfActivationNtf ntf;
+ NciModeParam mode_param;
|