[-]
[+]
|
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.1.10</param>
+ <param name="revision">1.1.18</param>
<param name="token"/>
<param name="debian">N</param>
<param name="dumb">N</param>
|
[-]
[+]
|
Deleted |
_service:tar_git:libncicore-1.1.10.tar.bz2/src/nci_util.h
^
|
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
- *
- * You may use this file under the terms of BSD license as follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef NCI_UTIL_H
-#define NCI_UTIL_H
-
-#include "nci_types_p.h"
-
-gboolean
-nci_listen_mode(
- NCI_MODE mode)
- NCI_INTERNAL;
-
-const NciModeParam*
-nci_parse_mode_param(
- NciModeParam* param,
- NCI_MODE mode,
- const guint8* bytes,
- guint len)
- NCI_INTERNAL;
-
-gboolean
-nci_parse_discover_ntf(
- NciDiscoveryNtf* ntf,
- NciModeParam* param,
- const guint8* bytes,
- guint len)
- NCI_INTERNAL;
-
-gboolean
-nci_parse_intf_activated_ntf(
- NciIntfActivationNtf* ntf,
- NciModeParam* mode_param,
- NciActivationParam* activation_param,
- const guint8* pkt,
- guint len)
- NCI_INTERNAL;
-
-NciDiscoveryNtf*
-nci_discovery_ntf_copy_array(
- const NciDiscoveryNtf* const* ntfs,
- guint count)
- NCI_INTERNAL;
-
-NciDiscoveryNtf*
-nci_discovery_ntf_copy(
- const NciDiscoveryNtf* ntf)
- NCI_INTERNAL;
-
-#endif /* NCI_UTIL_H */
-
-/*
- * Local Variables:
- * mode: C
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/LICENSE
^
|
@@ -1,6 +1,6 @@
-Copyright (C) 2018-2020 Jolla Ltd.
-Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
-Copyright (C) 2019 Open Mobile Platform LLC.
+Copyright (C) 2018-2021 Jolla Ltd.
+Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
+Copyright (C) 2019-2020 Open Mobile Platform LLC.
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/Makefile
^
|
@@ -48,6 +48,7 @@
SRC = \
nci_core.c \
+ nci_log.c \
nci_param.c \
nci_param_w4_all_discoveries.c \
nci_param_w4_host_select.c \
@@ -240,7 +241,7 @@
LIBDIR ?= usr/lib
ABS_LIBDIR := $(shell echo /$(LIBDIR) | sed -r 's|/+|/|g')
-$(PKGCONFIG): $(LIB_NAME).pc.in Makefile
+$(PKGCONFIG): $(LIB_NAME).pc.in $(VERSION_FILE)
sed -e 's|@version@|$(PCVERSION)|g' -e 's|@libdir@|$(ABS_LIBDIR)|g' $< > $@
debian/%.install: debian/%.install.in
@@ -259,7 +260,7 @@
INSTALL_PKGCONFIG_DIR = $(DESTDIR)$(ABS_LIBDIR)/pkgconfig
install: $(INSTALL_LIB_DIR)
- $(INSTALL_FILES) $(RELEASE_LIB) $(INSTALL_LIB_DIR)
+ $(INSTALL) -m 755 $(RELEASE_LIB) $(INSTALL_LIB_DIR)
ln -sf $(LIB) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK2)
ln -sf $(LIB_SYMLINK2) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK1)
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/README
^
|
@@ -16,3 +16,11 @@
This library doesn't provide any hardware access methods. It's up to
the code linking with this library to implement interfaces described
by nci_hal.h
+
+Optionally, NFC technologies supported by the chip can be specified
+in /etc/libncicore.conf file, e.g.
+
+ [Configuration]
+ Technologies = A,B,F
+
+By default all technologies are assumed to be supported.
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/debian/changelog
^
|
@@ -1,3 +1,56 @@
+libncicore (1.1.18) unstable; urgency=low
+
+ * Configure ATR_RES and ATR_REQ for NFC-DEP
+ * Tweaked NFC-DEP discovery modes
+
+ -- Slava Monich <slava.monich@jolla.com> Wed, 24 Feb 2021 20:20:52 +0200
+
+libncicore (1.1.17) unstable; urgency=low
+
+ * Improved NFC-DEP compatibility
+
+ -- Slava Monich <slava.monich@jolla.com> Wed, 13 Jan 2021 02:38:26 +0200
+
+libncicore (1.1.16) unstable; urgency=low
+
+ * Made supported technologies configurable
+ * Rolled back detection run time of NFC-F support
+
+ -- Slava Monich <slava.monich@jolla.com> Fri, 18 Dec 2020 19:19:40 +0200
+
+libncicore (1.1.15) unstable; urgency=low
+
+ * Detect NFC-F support at run time
+ * Use NFC-V terminology instead of ISO-15693
+
+ -- Slava Monich <slava.monich@jolla.com> Fri, 11 Dec 2020 03:10:55 +0200
+
+libncicore (1.1.14) unstable; urgency=low
+
+ * Fixed misleading "Invalid packet id" warning
+
+ -- Slava Monich <slava.monich@jolla.com> Mon, 28 Sep 2020 23:39:06 +0300
+
+libncicore (1.1.13) unstable; urgency=low
+
+ * Added nci_util_copy_mode_param() and nci_util_copy_activation_param()
+
+ -- Slava Monich <slava.monich@jolla.com> Mon, 21 Sep 2020 18:31:29 +0300
+
+libncicore (1.1.12) unstable; urgency=low
+
+ * Update libncicore.pc when version header changes
+
+ -- Slava Monich <slava.monich@jolla.com> Wed, 09 Sep 2020 19:41:13 +0300
+
+libncicore (1.1.11) unstable; urgency=low
+
+ * Added missing activation params for t4a tags
+ * Fixed TC presense bit in RATS response
+ * Avoid accessing data beyond the end of RATS response
+
+ -- Slava Monich <slava.monich@jolla.com> Thu, 20 Aug 2020 20:33:45 +0300
+
libncicore (1.1.10) unstable; urgency=low
* Set TOTAL_DURATION to 500ms
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/debian/copyright
^
|
@@ -1,6 +1,6 @@
Copyright (C) 2018-2020 Jolla Ltd.
Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
-Copyright (C) 2019 Open Mobile Platform LLC.
+Copyright (C) 2019-2020 Open Mobile Platform LLC.
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/include/nci_core.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -48,6 +48,25 @@
guint cmd_timeout;
} NciCore;
+/* NCI parameters */
+
+typedef enum nci_core_param_key {
+ NCI_CORE_PARAM_LLC_VERSION, /* uint8, default is 0x11 (v1.1) */
+ NCI_CORE_PARAM_LLC_WKS, /* uint16, default is 0x0003 (SDP-only) */
+ NCI_CORE_PARAM_COUNT
+} NCI_CORE_PARAM; /* Since 1.1.18 */
+
+typedef union nci_core_param_value {
+ guint8 uint8;
+ guint16 uint16;
+ guint32 uint32;
+} NciCoreParamValue; /* Since 1.1.18 */
+
+typedef struct nci_core_param {
+ NCI_CORE_PARAM key;
+ NciCoreParamValue value;
+} NciCoreParam; /* Since 1.1.18 */
+
typedef
void
(*NciCoreFunc)(
@@ -99,6 +118,12 @@
NciCore* nci,
NCI_OP_MODE op_mode); /* Since 1.1.0 */
+void
+nci_core_set_params(
+ NciCore* nci,
+ const NciCoreParam* const* params, /* NULL terminated list */
+ gboolean reset); /* Since 1.1.18 */
+
guint
nci_core_send_data_msg(
NciCore* nci,
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/include/nci_types.h
^
|
@@ -77,15 +77,19 @@
NCI_MODE_PASSIVE_POLL_F = 0x02,
NCI_MODE_ACTIVE_POLL_A = 0x03,
NCI_MODE_ACTIVE_POLL_F = 0x05,
- NCI_MODE_PASSIVE_POLL_15693 = 0x06,
+ NCI_MODE_PASSIVE_POLL_V = 0x06, /* Since 1.1.15 */
NCI_MODE_PASSIVE_LISTEN_A = 0x80,
NCI_MODE_PASSIVE_LISTEN_B = 0x81,
NCI_MODE_PASSIVE_LISTEN_F = 0x82,
NCI_MODE_ACTIVE_LISTEN_A = 0x83,
NCI_MODE_ACTIVE_LISTEN_F = 0x85,
- NCI_MODE_PASSIVE_LISTEN_15693 = 0x86
+ NCI_MODE_PASSIVE_LISTEN_V = 0x86 /* Since 1.1.15 */
} NCI_MODE;
+/* These names were used before 1.1.15 */
+#define NCI_MODE_PASSIVE_POLL_15693 NCI_MODE_PASSIVE_POLL_V
+#define NCI_MODE_PASSIVE_LISTEN_15693 NCI_MODE_PASSIVE_LISTEN_V
+
/* Table 97: Bit Rates */
typedef enum nci_bit_rate {
NFC_BIT_RATE_106 = 0x00, /* 106 Kbit/s */
@@ -157,6 +161,17 @@
typedef struct nci_activation_param_iso_dep_poll_a {
guint fsc; /* FSC (FSCI converted to bytes) */
GUtilData t1; /* T1 to Tk (otherwise called historical bytes) */
+ /* Since 1.1.11 */
+ guint8 t0; /* Format byte T0 */
+
+#define NFC_T4A_ATS_T0_A (0x10) /* TA is transmitted */
+#define NFC_T4A_ATS_T0_B (0x20) /* TB is transmitted */
+#define NFC_T4A_ATS_T0_C (0x40) /* TC is transmitted */
+#define NFC_T4A_ATS_T0_FSCI_MASK (0x0f) /* FSCI mask */
+
+ guint8 ta; /* Interface byte TA (optional) */
+ guint8 tb; /* Interface byte TB (optional) */
+ guint8 tc; /* Interface byte TC (optional) */
} NciActivationParamIsoDepPollA;
/* Table 75: Activation Parameters for NFC-B/ISO-DEP Poll Mode */
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.18.tar.bz2/include/nci_util.h
^
|
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2019-2020 Jolla Ltd.
+ * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NCI_UTIL_H
+#define NCI_UTIL_H
+
+#include <nci_types.h>
+
+G_BEGIN_DECLS
+
+/* Free the result with g_free() */
+NciModeParam*
+nci_util_copy_mode_param(
+ const NciModeParam* param,
+ NCI_MODE mode); /* Since 1.1.13 */
+
+/* Free the result with g_free() */
+NciActivationParam*
+nci_util_copy_activation_param(
+ const NciActivationParam* param,
+ NCI_RF_INTERFACE intf,
+ NCI_MODE mode); /* Since 1.1.13 */
+
+G_END_DECLS
+
+#endif /* NCI_UTIL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/include/nci_version.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2020 Jolla Ltd.
- * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -38,7 +38,7 @@
/* libncicore version */
#define NCI_CORE_VERSION_MAJOR 1
#define NCI_CORE_VERSION_MINOR 1
-#define NCI_CORE_VERSION_NANO 10
+#define NCI_CORE_VERSION_NANO 18
#define NCI_CORE_VERSION_WORD(v1,v2,v3) \
((((v1) & 0x7f) << 24) | \
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/libncicore.map
^
|
@@ -2,6 +2,7 @@
global:
nci_core_*;
nci_log;
+ nci_util_*;
local:
*;
};
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_core.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -41,8 +41,6 @@
#include <glib-object.h>
-GLOG_MODULE_DEFINE("nci");
-
typedef struct nci_core_closure {
GCClosure cclosure;
NciCoreFunc func;
@@ -113,6 +111,16 @@
#define DEFAULT_TIMEOUT (2000) /* msec */
+static const NciCoreParamValue NCI_DEFAULT_LLC_VERSION = { .uint8 = 0x11 };
+static const NciCoreParamValue NCI_DEFAULT_LLC_WKS = { .uint16 = 0x0003 };
+
+typedef struct nci_core_param_desc {
+ NciCoreParamValue* (*get)(NciCoreObject*);
+ void (*set)(NciCoreObject*, const NciCoreParamValue*);
+ void (*reset)(NciCoreObject*);
+ gboolean (*equal)(const NciCoreParamValue*, const NciCoreParamValue*);
+} NciCoreParamDesc;
+
static inline NciCoreObject* nci_core_object(NciCore* ptr)
{ return G_LIKELY(ptr) ? /* This one should be NULL safe */
NCI_CORE(G_CAST(ptr, NciCoreObject, core)) : NULL; }
@@ -334,6 +342,150 @@
return 0;
}
+static
+void
+nci_core_restart_internal(
+ NciCoreObject* self)
+{
+ nci_core_cancel_command(self);
+ nci_sar_reset(self->io.sar);
+ nci_sm_enter_state(self->sm, NCI_STATE_INIT, NULL);
+ nci_sm_switch_to(self->sm, NCI_RFST_IDLE);
+}
+
+/*==========================================================================*
+ * Parameters
+ *==========================================================================*/
+
+static
+NciCoreParamValue*
+nci_core_param_uint8_new(
+ guint8 value)
+{
+ NciCoreParamValue* v = g_new0(NciCoreParamValue, 1);
+
+ v->uint8 = value;
+ return v;
+}
+
+static
+NciCoreParamValue*
+nci_core_param_uint16_new(
+ guint16 value)
+{
+ NciCoreParamValue* v = g_new0(NciCoreParamValue, 1);
+
+ v->uint16 = value;
+ return v;
+}
+
+static
+gboolean
+nci_core_param_equal_uint8(
+ const NciCoreParamValue* v1,
+ const NciCoreParamValue* v2)
+{
+ return v1->uint8 == v2->uint8;
+}
+
+static
+gboolean
+nci_core_param_equal_uint16(
+ const NciCoreParamValue* v1,
+ const NciCoreParamValue* v2)
+{
+ return v1->uint16 == v2->uint16;
+}
+
+static
+NciCoreParamValue*
+nci_core_param_get_llc_version(
+ NciCoreObject* core)
+{
+ return nci_core_param_uint8_new(core->sm->llc_version);
+}
+
+static
+void
+nci_core_param_set_llc_version(
+ NciCoreObject* core,
+ const NciCoreParamValue* value)
+{
+ const guint8 version = value->uint8;
+ NciSm* sm = core->sm;
+
+ if (sm->llc_version != version) {
+ sm->llc_version = version;
+ GDEBUG("LLC Version => 0x%02x", version);
+ }
+}
+
+static
+void
+nci_core_param_reset_llc_version(
+ NciCoreObject* core)
+{
+ nci_core_param_set_llc_version(core, &NCI_DEFAULT_LLC_VERSION);
+}
+
+static
+NciCoreParamValue*
+nci_core_param_get_llc_wks(
+ NciCoreObject* core)
+{
+ return nci_core_param_uint16_new(core->sm->llc_wks);
+}
+
+static
+void
+nci_core_param_set_llc_wks(
+ NciCoreObject* core,
+ const NciCoreParamValue* value)
+{
+ /*
+ * [NFCForum-TS-LLCP_1.1]
+ * 4.5.3 Well-Known Service List, WKS
+ *
+ * ...
+ * As the LLC Link Management Service is bound to SAP 00h, the least
+ * significant bit, representing SAP 00h, SHALL always be set to '1'
+ * by the sender and SHALL be ignored by the receiver.
+ */
+ const guint16 wks = value->uint16 | 0x01;
+ NciSm* sm = core->sm;
+
+ if (sm->llc_wks != wks) {
+ sm->llc_wks = wks;
+ GDEBUG("WKS => 0x%04x", wks);
+ }
+}
+
+static
+void
+nci_core_param_reset_llc_wks(
+ NciCoreObject* core)
+{
+ nci_core_param_set_llc_wks(core, &NCI_DEFAULT_LLC_WKS);
+}
+
+static const NciCoreParamDesc nci_core_params[] = {
+ { /* NCI_PARAM_LLC_VERSION */
+ nci_core_param_get_llc_version,
+ nci_core_param_set_llc_version,
+ nci_core_param_reset_llc_version,
+ nci_core_param_equal_uint8
+ },{ /* NCI_PARAM_LLC_WKS */
+ nci_core_param_get_llc_wks,
+ nci_core_param_set_llc_wks,
+ nci_core_param_reset_llc_wks,
+ nci_core_param_equal_uint16
+ }
+};
+
+G_STATIC_ASSERT(NCI_CORE_PARAM_LLC_VERSION == 0);
+G_STATIC_ASSERT(NCI_CORE_PARAM_LLC_WKS == 1);
+G_STATIC_ASSERT(NCI_CORE_PARAM_COUNT == G_N_ELEMENTS(nci_core_params));
+
/*==========================================================================*
* NciSmIo callbacks
*==========================================================================*/
@@ -481,10 +633,15 @@
NciCoreObject* self = g_object_new(NCI_TYPE_CORE, NULL);
NciCore* core = &self->core;
NciSm* sm;
+ guint i;
self->io.sar = nci_sar_new(hal, &self->sar_client);
self->sm = sm = nci_sm_new(&self->io);
+ for (i = 0; i < G_N_ELEMENTS(nci_core_params); i++) {
+ nci_core_params[i].reset(self);
+ }
+
core->current_state = sm->last_state->state;
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_log.c
^
|
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nci_log.h"
+
+GLOG_MODULE_DEFINE("nci");
+
+#if GUTIL_LOG_DEBUG
+void
+nci_dump_invalid_config_params(
+ guint nparams,
+ const GUtilData* params)
+{
+ /*
+ * [NFCForum-TS-NCI-1.0]
+ * 4.3.2 Retrieve the Configuration
+ *
+ * If the DH tries to retrieve any parameter(s) that
+ * are not available in the NFCC, the NFCC SHALL respond
+ * with a CORE_GET_CONFIG_RSP with a Status field of
+ * STATUS_INVALID_PARAM, containing each unavailable
+ * Parameter ID with a Parameter Len field of value zero.
+ * In this case, the CORE_GET_CONFIG_RSP SHALL NOT include
+ * any parameter(s) that are available on the NFCC.
+ */
+ if (GLOG_ENABLED(GLOG_LEVEL_DEBUG)) {
+ const guint8* ptr = params->bytes;
+ const guint8* end = ptr + params->size;
+ GString* buf = g_string_new(NULL);
+ guint i;
+
+ for (i = 0; i < nparams && (ptr + 1) < end; i++, ptr += 2) {
+ g_string_append_printf(buf, " %02x", *ptr);
+ }
+ GDEBUG("%c CORE_GET_CONFIG_RSP invalid parameter(s):%s", DIR_IN,
+ buf->str);
+ g_string_free(buf, TRUE);
+ }
+}
+#endif
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_log.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -33,11 +33,23 @@
#ifndef NCI_LOG_H
#define NCI_LOG_H
-#include <nci_types.h>
+#include "nci_types_p.h"
#define GLOG_MODULE_NAME NCI_LOG_MODULE
#include <gutil_log.h>
+#if GUTIL_LOG_DEBUG
+void
+nci_dump_invalid_config_params(
+ guint nparams,
+ const GUtilData* params)
+ NCI_INTERNAL;
+# define NCI_DUMP_INVALID_CONFIG_PARAMS(n,params) \
+ nci_dump_invalid_config_params(n,params)
+#else
+# define NCI_DUMP_INVALID_CONFIG_PARAMS(n,params) ((void)0)
+#endif
+
#endif /* NCI_LOG_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_param_w4_all_discoveries.c
^
|
@@ -32,7 +32,7 @@
#include "nci_param_w4_all_discoveries.h"
#include "nci_param_impl.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
typedef NciParamClass NciParamW4AllDiscoveriesClass;
G_DEFINE_TYPE(NciParamW4AllDiscoveries, nci_param_w4_all_discoveries,
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_param_w4_host_select.c
^
|
@@ -32,7 +32,7 @@
#include "nci_param_w4_host_select.h"
#include "nci_param_impl.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
typedef NciParamClass NciParamW4HostSelectClass;
G_DEFINE_TYPE(NciParamW4HostSelect, nci_param_w4_host_select, NCI_TYPE_PARAM)
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_sar.c
^
|
@@ -915,7 +915,6 @@
/* We can't really cancel the packet once we started writing it.
* Just clear the completion callback. */
self->writing->complete = NULL;
- return;
} else if (!nci_sar_cancel_queue(self, &self->cmd, id)) {
guint i;
@@ -926,8 +925,8 @@
return;
}
}
+ GWARN("Invalid packet id %u", id);
}
- GWARN("Invalid packet id %u", id);
}
}
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_sm.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -97,6 +97,29 @@
#define NCI_IS_INTERNAL_STATE(state) ((state) < NCI_RFST_IDLE)
+/* Config file name is extern for unit tests */
+const char* nci_sm_config_file = "/etc/libncicore.conf";
+static const char CONFIG_SECTION[] = "Configuration";
+static const char CONFIG_LIST_SEPARATORS[] = ";,";
+static const char CONFIG_ENTRY_TECHNOLOGIES[] = "Technologies";
+static const char CONFIG_TECHNOLOGY_TYPE_A[] = "A";
+static const char CONFIG_TECHNOLOGY_TYPE_B[] = "B";
+static const char CONFIG_TECHNOLOGY_TYPE_F[] = "F";
+static const char CONFIG_TECHNOLOGY_TYPE_V[] = "V";
+static const char CONFIG_TECHNOLOGY_POLL_A[] = "Poll-A";
+static const char CONFIG_TECHNOLOGY_POLL_B[] = "Poll-B";
+static const char CONFIG_TECHNOLOGY_POLL_F[] = "Poll-F";
+static const char CONFIG_TECHNOLOGY_POLL_V[] = "Poll-V";
+static const char CONFIG_TECHNOLOGY_LISTEN_A[] = "Listen-A";
+static const char CONFIG_TECHNOLOGY_LISTEN_B[] = "Listen-B";
+static const char CONFIG_TECHNOLOGY_LISTEN_F[] = "Listen-F";
+static const char CONFIG_TECHNOLOGY_LISTEN_V[] = "Listen-V";
+
+typedef struct nci_technolofy_option {
+ const char* name;
+ NCI_OPTIONS opt;
+} NciTechnologyOption;
+
static inline NciSmObject* nci_sm_object(NciSm* sm) /* NULL safe */
{ return G_LIKELY(sm) ? NCI_SM(G_CAST(sm, NciSmObject, sm)) : NULL; }
@@ -398,6 +421,82 @@
return 0;
}
+static
+void
+nci_sm_parse_config(
+ NciSm* sm,
+ GKeyFile* config)
+{
+ char* sval = g_key_file_get_string(config, CONFIG_SECTION,
+ CONFIG_ENTRY_TECHNOLOGIES, NULL);
+
+ if (sval) {
+ static const NciTechnologyOption nci_tech_options[] = {
+ /* A and B are always enabled */
+ { CONFIG_TECHNOLOGY_TYPE_A, NCI_OPTION_NONE },
+ { CONFIG_TECHNOLOGY_TYPE_B, NCI_OPTION_NONE },
+ { CONFIG_TECHNOLOGY_TYPE_F, NCI_OPTION_TYPE_F },
+ { CONFIG_TECHNOLOGY_TYPE_V, NCI_OPTION_TYPE_V },
+ { CONFIG_TECHNOLOGY_POLL_A, NCI_OPTION_NONE },
+ { CONFIG_TECHNOLOGY_POLL_B, NCI_OPTION_NONE },
+ { CONFIG_TECHNOLOGY_POLL_F, NCI_OPTION_POLL_F },
+ { CONFIG_TECHNOLOGY_POLL_V, NCI_OPTION_POLL_V },
+ { CONFIG_TECHNOLOGY_LISTEN_A, NCI_OPTION_NONE },
+ { CONFIG_TECHNOLOGY_LISTEN_B, NCI_OPTION_NONE },
+ { CONFIG_TECHNOLOGY_LISTEN_F, NCI_OPTION_LISTEN_F },
+ { CONFIG_TECHNOLOGY_LISTEN_V, NCI_OPTION_LISTEN_V }
+ };
+
+ char** techs = g_strsplit_set(sval, CONFIG_LIST_SEPARATORS, -1);
+ char** val = techs;
+
+ sm->options = NCI_OPTION_NONE;
+ for (val = techs; *val; val++) {
+ const NciTechnologyOption* opt = NULL;
+ guint i;
+
+ g_strstrip(*val);
+ for (i = 0; i < G_N_ELEMENTS(nci_tech_options); i++) {
+ if (!g_ascii_strcasecmp(*val, nci_tech_options[i].name)) {
+ opt = nci_tech_options + i;
+ break;
+ }
+ }
+
+ if (opt) {
+ GDEBUG(" %s", opt->name);
+ sm->options |= opt->opt;
+ } else {
+ GWARN("Unexpected technology '%s' in configuration", *val);
+ }
+ }
+ g_strfreev(techs);
+ g_free(sval);
+ }
+}
+
+static
+void
+nci_sm_load_config(
+ NciSm* sm)
+{
+ if (nci_sm_config_file &&
+ g_file_test(nci_sm_config_file, G_FILE_TEST_EXISTS)) {
+ GError* error = NULL;
+ GKeyFile* config = g_key_file_new();
+
+ if (g_key_file_load_from_file(config, nci_sm_config_file,
+ G_KEY_FILE_NONE, &error)) {
+ GDEBUG("Parsing %s", nci_sm_config_file);
+ nci_sm_parse_config(sm, config);
+ } else {
+ GERR("Error loading %s: %s", nci_sm_config_file, error->message);
+ g_error_free(error);
+ }
+ g_key_file_unref(config);
+ }
+}
+
/*==========================================================================*
* Interface
*==========================================================================*/
@@ -639,6 +738,8 @@
/* And these are not reusable */
nci_sm_add_new_transition(sm, NCI_RFST_IDLE,
nci_transition_idle_to_discovery_new);
+
+ nci_sm_load_config(sm);
return sm;
}
@@ -1033,7 +1134,8 @@
NciSm* sm = &self->sm;
/* Only poll modes by default */
- sm->op_mode = NFC_OP_MODE_RW | NFC_OP_MODE_PEER | NFC_OP_MODE_POLL;
+ sm->op_mode = NFC_OP_MODE_RW | NFC_OP_MODE_POLL;
+ sm->options = NCI_OPTIONS_DEFAULT;
self->transitions = g_ptr_array_new_with_free_func((GDestroyNotify)
nci_transition_unref);
self->states = g_ptr_array_new_full(NCI_CORE_STATES, (GDestroyNotify)
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_sm.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -43,6 +43,18 @@
NCI_INTERFACE_VERSION_2
} NCI_INTERFACE_VERSION;
+typedef enum nci_options {
+ NCI_OPTION_NONE = 0x00,
+ NCI_OPTION_POLL_F = 0x01,
+ NCI_OPTION_LISTEN_F = 0x02,
+ NCI_OPTION_POLL_V = 0x04,
+ NCI_OPTION_LISTEN_V = 0x08
+} NCI_OPTIONS;
+
+#define NCI_OPTION_TYPE_F (NCI_OPTION_POLL_F|NCI_OPTION_LISTEN_F)
+#define NCI_OPTION_TYPE_V (NCI_OPTION_POLL_V|NCI_OPTION_LISTEN_V)
+#define NCI_OPTIONS_DEFAULT NCI_OPTION_TYPE_F /* A and B support always on*/
+
/* Table 9: NFCC Features */
typedef enum nci_nfcc_discovery {
NCI_NFCC_DISCOVERY_NONE = 0x00,
@@ -63,6 +75,17 @@
NCI_NFCC_POWER_SWITCH_OFF = 0x02
} NCI_NFCC_POWER;
+/* Table 31: LA_SEL_INFO coding */
+typedef enum nci_la_sel_info {
+ NCI_LA_SEL_INFO_ISO_DEP = 0x20,
+ NCI_LA_SEL_INFO_NFC_DEP = 0x40
+} NCI_LA_SEL_INFO;
+
+/* Table 36: Supported Protocols for Listen F */
+typedef enum nci_lf_protocol_type {
+ NCI_LF_PROTOCOL_TYPE_NFC_DEP = 0x02
+} NCI_LF_PROTOCOL_TYPE;
+
/* Table 43: Value Field for Mode */
#define NCI_DISCOVER_MAP_MODE_POLL (0x01)
#define NCI_DISCOVER_MAP_MODE_LISTEN (0x02)
@@ -120,10 +143,10 @@
/* Table 95: RF Technologies */
typedef enum nci_rf_technology {
- NCI_RF_TECHNOLOGY_A = 0x00,
- NCI_RF_TECHNOLOGY_B = 0x01,
- NCI_RF_TECHNOLOGY_F = 0x02,
- NCI_RF_TECHNOLOGY_15693 = 0x03
+ NCI_RF_TECHNOLOGY_A = 0x00,
+ NCI_RF_TECHNOLOGY_B = 0x01,
+ NCI_RF_TECHNOLOGY_F = 0x02,
+ NCI_RF_TECHNOLOGY_V = 0x03
} NCI_RF_TECHNOLOGY;
/* Table 101: Configuration Parameter Tags */
@@ -252,11 +275,14 @@
NciState* next_state;
GBytes* rf_interfaces;
guint max_routing_table_size;
+ NCI_OPTIONS options;
NCI_INTERFACE_VERSION version;
NCI_NFCC_DISCOVERY nfcc_discovery;
NCI_NFCC_ROUTING nfcc_routing;
NCI_NFCC_POWER nfcc_power;
NCI_OP_MODE op_mode;
+ guint8 llc_version;
+ guint16 llc_wks;
};
typedef
@@ -443,6 +469,10 @@
const GUtilData* payload)
NCI_INTERNAL;
+/* And this one is currently only for unit tests */
+
+extern const char* nci_sm_config_file NCI_INTERNAL;
+
#endif /* NCI_STATE_MACHINE_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_state_discovery.c
^
|
@@ -34,7 +34,7 @@
#include "nci_sar.h"
#include "nci_state_impl.h"
#include "nci_param_w4_all_discoveries.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
#include "nci_log.h"
typedef NciState NciStateDiscovery;
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_state_listen_sleep.c
^
|
@@ -32,7 +32,7 @@
#include "nci_sm.h"
#include "nci_state_impl.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
#include "nci_log.h"
typedef NciState NciStateListenSleep;
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_state_w4_all_discoveries.c
^
|
@@ -34,7 +34,7 @@
#include "nci_state_impl.h"
#include "nci_param_w4_all_discoveries.h"
#include "nci_param_w4_host_select.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
typedef NciStateClass NciStateW4AllDiscoveriesClass;
typedef struct nci_state_w4_all_discoveries {
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_state_w4_host_select.c
^
|
@@ -33,7 +33,7 @@
#include "nci_sm.h"
#include "nci_state_impl.h"
#include "nci_param_w4_host_select.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
#include "nci_log.h"
typedef NciStateClass NciStateW4HostSelectClass;
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_transition_idle_to_discovery.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -32,11 +32,84 @@
#include "nci_transition.h"
#include "nci_transition_impl.h"
+#include "nci_util_p.h"
#include "nci_sm.h"
#include "nci_log.h"
/*==========================================================================*
* NCI_RFST_IDLE -> NCI_RFST_DISCOVERY transition
+ *
+ * +---------------------+
+ * | CORE_GET_CONFIG_CMD |
+ * | 1. LA_SEL_INFO |
+ * | 2. LF_PROTOCOL_TYPE |
+ * +---------------------+
+ * | |
+ * error ok
+ * | |
+ * | v
+ * | +--------------------+
+ * | | All parameters OK? |------------\
+ * | +--------------------+ |
+ * | | |
+ * | yes no
+ * | | |
+ * v v v
+ * +---------------------------+ +----------------+
+ * | Are listen modes enabled? |<------| SET_CONFIG_CMD |
+ * +---------------------------+ +----------------+
+ * | |
+ * no yes
+ * | |
+ * | v
+ * | +------------------------------------+
+ * | | What kind of routing is supported? |
+ * | +------------------------------------+
+ * | | | | |
+ * | | | protocol all
+ * | | | | |
+ * | | technology | v
+ * | | | | +----------------------------+
+ * | none | | | RF_SET_LISTEN_MODE_ROUTING |-------------\
+ * | | | | | (Mixed) | |
+ * | | | | +----------------------------+ ok
+ * | | | | | |
+ * | | | | error |
+ * | | | | | |
+ * | | | | v |
+ * | | | | +----------------------------+ |
+ * | | | | | RF_SET_LISTEN_MODE_ROUTING | |
+ * | | | | | (Protocol) |------\ |
+ * | | | | +----------------------------+ | |
+ * | | | v | ok |
+ * | | | +----------------------------+ | | |
+ * | | | | RF_SET_LISTEN_MODE_ROUTING | | | |
+ * | | | | (Protocol) | | | |
+ * | | | +----------------------------+ | | |
+ * | | v | error | |
+ * | | +----------------------------+ | | | |
+ * | | | RF_SET_LISTEN_MODE_ROUTING |<--|-----/ | |
+ * | | | (Technology) | | | |
+ * | | +----------------------------+ | | |
+ * | | | | / |
+ * | \--------------------------\ | | / |
+ * v | | | / |
+ * +------------------------------+ | | | / |
+ * | Is routing supported at all? | | | | / |
+ * +------------------------------+ | | | / |
+ * | \ | | | / |
+ * yes no | | | / |
+ * | \ | | | / |
+ * v \ | | | / |
+ * +----------------------------+ v v v v v |
+ * | RF_SET_LISTEN_MODE_ROUTING | +---------------------+ |
+ * | (default) |-->| RF_DISCOVER_MAP_CMD |<------------/
+ * +----------------------------+ +---------------------+
+ * |
+ * v
+ * +-----------------+
+ * | RF_DISCOVER_CMD |
+ * +-----------------+
*==========================================================================*/
typedef NciTransition NciTransitionIdleToDiscovery;
@@ -49,6 +122,8 @@
G_DEFINE_TYPE(NciTransitionIdleToDiscovery, nci_transition_idle_to_discovery,
NCI_TYPE_TRANSITION)
+#define ARRAY_AND_SIZE(a) a, sizeof(a)
+
/*==========================================================================*
* Implementation
*==========================================================================*/
@@ -116,7 +191,16 @@
NciTransition* self)
{
NciSm* sm = nci_transition_sm(self);
- GByteArray* cmd = g_byte_array_sized_new(7);
+ GByteArray* cmd = g_byte_array_sized_new(9);
+ const gboolean peer_poll = (sm->op_mode &
+ (NFC_OP_MODE_PEER|NFC_OP_MODE_POLL)) ==
+ (NFC_OP_MODE_PEER|NFC_OP_MODE_POLL);
+ const gboolean peer_listen = (sm->op_mode &
+ (NFC_OP_MODE_PEER|NFC_OP_MODE_LISTEN)) ==
+ (NFC_OP_MODE_PEER|NFC_OP_MODE_LISTEN);
+ const gboolean ce_listen = (sm->op_mode &
+ (NFC_OP_MODE_CE|NFC_OP_MODE_LISTEN)) ==
+ (NFC_OP_MODE_CE|NFC_OP_MODE_LISTEN);
/*
* Table 52: Control Messages to Start Discovery
@@ -133,87 +217,87 @@
* | | | 1 | Frequency (1 = every period) |
* +=========================================================+
*/
+
static const guint8 cmd_header[] = {
0x00, /* Number of Configurations */
};
GDEBUG("%c RF_DISCOVER_CMD", DIR_OUT);
- g_byte_array_append(cmd, cmd_header, sizeof(cmd_header));
+ g_byte_array_append(cmd, ARRAY_AND_SIZE(cmd_header));
/*
- * RW Modes: Poll A/B/V
+ * RW Modes: Poll A/B/F/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[] = {
+ /* Poll side */
+ if ((sm->op_mode & NFC_OP_MODE_RW) || peer_poll) {
+ static const guint8 poll_ab[] = {
+ NCI_MODE_ACTIVE_POLL_A, 1,
NCI_MODE_PASSIVE_POLL_A, 1,
- NCI_MODE_ACTIVE_POLL_A, 1
+ NCI_MODE_PASSIVE_POLL_B, 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(" PassivePollA");
+ GDEBUG(" PassivePollB");
+ cmd->data[0] += 3; /* Number of entries */
+ g_byte_array_append(cmd, ARRAY_AND_SIZE(poll_ab));
+
+ if (sm->options & NCI_OPTION_POLL_F) {
+ static const guint8 poll_f[] = {
+ NCI_MODE_ACTIVE_POLL_F, 1,
+ NCI_MODE_PASSIVE_POLL_F, 1
+ };
+
+ /* NFC-DEP or T3T */
+ GDEBUG(" ActivePollF");
+ GDEBUG(" PassivePollF");
+ cmd->data[0] += 2; /* Number of entries */
+ g_byte_array_append(cmd, ARRAY_AND_SIZE(poll_f));
+ }
- GDEBUG(" PassivePollF");
- GDEBUG(" ActivePollF");
- g_byte_array_append(cmd, entries, sizeof(entries));
- cmd->data[0] += sizeof(entries)/2;
+ if (sm->options & NCI_OPTION_POLL_V) {
+ static const guint8 poll_v[] = {
+ NCI_MODE_PASSIVE_POLL_V, 1
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_transition_reset.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -32,6 +32,7 @@
#include "nci_transition.h"
#include "nci_transition_impl.h"
+#include "nci_util_p.h"
#include "nci_sar.h"
#include "nci_sm.h"
#include "nci_log.h"
@@ -43,44 +44,82 @@
#define THIS_TYPE (nci_transition_reset_get_type())
#define PARENT_CLASS (nci_transition_reset_parent_class)
+/*
+ * The reset sequence goes like this:
+ *
+ * +-----------+ +=========+
+ * | RESET_CMD |----- error ---------------->| Failure |
+ * +-----------+ +=========+
+ * | ^
+ * ok |
+ * | |
+ * v |
+ * +-----------------------+ |
+ * | Determine NCI version |---- unexpected ---------->+
+ * +-----------------------+ |
+ * | | |
+ * v1 v2 |
+ * | | |
+ * | +-------------------------+ |
+ * | | Wait for CORE_RESET_NTF | |
+ * v +-------------------------+ |
+ * +-------------+ | |
+ * | INIT_CMD v1 |-- error -----|----------------------->+
+ * +-------------+ v |
+ * | +------------------------+ |
+ * ok | CORE_RESET_NTF arrives | |
+ * | +------------------------+ |
+ * | | |
+ * | v |
+ * | +-------------+ |
+ * | | INIT_CMD v2 |-- error ------->/
+ * | +-------------+
+ * | |
+ * | ok
+ * | |
+ * v v
+ * +-------------------------+
+ * | SET_CONFIG_CMD |
+ * +-------------------------+
+ * |
+ * v
+ * +=========+
+ * | Success |
+ * +=========+
+ */
+
#define DEFAULT_TOTAL_DURATION (500) /* ms */
+enum llcp_param {
+ LLCP_PARAM_VERSION = 1,
+ LLCP_PARAM_MIUX = 2,
+ LLCP_PARAM_WKS = 3,
+ LLCP_PARAM_LTO = 4,
+ LLCP_PARAM_RW = 5,
+ LLCP_PARAM_SN = 6,
+ LLCP_PARAM_OPT = 7,
+ LLCP_PARAM_SDREQ = 8, /* LLCP 1.1 */
+ LLCP_PARAM_SDRES = 9 /* LLCP 1.1 */
+};
+
+static const guint8 NFC_DEP_LLCP_MAGIC[] = { 0x46, 0x66, 0x6d };
+static const guint8 NFC_DEP_PARAM_MIUX[] = {
+ LLCP_PARAM_MIUX, 0x02, 0x07, 0xff /* 0x7ff + 128 = 2175 bytes */
+};
+static const guint8 NFC_DEP_PARAM_LTO[] = {
+ LLCP_PARAM_LTO, 0x01, 0x64 /* LTO: 1000 ms */
+};
+static const guint8 NFC_DEP_PARAM_OPT[] = {
+ LLCP_PARAM_OPT, 0x01, 0x03 /* OPT: CO+CL */
+};
+
+#define ARRAY_AND_SIZE(a) a, sizeof(a)
+
/*==========================================================================*
* 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,
@@ -142,151 +181,55 @@
* | | | Val | m | The value of the parameter |
* +=========================================================+
*/
- static const guint8 cmd[] = {
- 3,
+ static const guint8 cmd_prefix[] = {
+ 7, /* Includes LN_ATR_RES_GEN_BYTES and PN_ATR_REQ_GEN_BYTES */
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
+ NCI_CONFIG_PB_BAIL_OUT, 0x01, 0x00,
+ NCI_CONFIG_LN_ATR_RES_CONFIG, 0x01, 0x30,
+ NCI_CONFIG_PN_ATR_REQ_CONFIG, 0x01, 0x30
};
- GDEBUG("%c CORE_SET_CONFIG_CMD", DIR_OUT);
- nci_transition_send_command_static(self,
- NCI_GID_CORE, NCI_OID_CORE_SET_CONFIG, cmd, sizeof(cmd),
- nci_transition_reset_set_config_rsp);
-}
-
-static
-void
-nci_transition_reset_get_config_rsp(
- NCI_REQUEST_STATUS status,
- const GUtilData* payload,
- NciTransition* self)
-{
NciSm* sm = nci_transition_sm(self);
+ GByteArray* gb = g_byte_array_sized_new(20);
+ GByteArray* cmd = g_byte_array_sized_new(61);
+ GBytes* cmd_bytes;
+ guint8 tlv[4];
+
+ /* Build ATR_REQ/ATR_RES General Bytes (LLCP Magic + TLVs) */
+ g_byte_array_append(gb, ARRAY_AND_SIZE(NFC_DEP_LLCP_MAGIC));
+ tlv[0] = LLCP_PARAM_VERSION;
+ tlv[1] = 1;
+ tlv[2] = sm->llc_version;
+ g_byte_array_append(gb, tlv, 3);
+ g_byte_array_append(gb, ARRAY_AND_SIZE(NFC_DEP_PARAM_MIUX));
+ tlv[0] = LLCP_PARAM_WKS;
+ tlv[1] = 2;
+ tlv[2] = (guint8)(sm->llc_wks >> 8);
+ tlv[3] = (guint8)(sm->llc_wks);
+ g_byte_array_append(gb, tlv, 4);
+ g_byte_array_append(gb, ARRAY_AND_SIZE(NFC_DEP_PARAM_LTO));
+ g_byte_array_append(gb, ARRAY_AND_SIZE(NFC_DEP_PARAM_OPT));
+
+ /* Append LN_ATR_RES_GEN_BYTES and PN_ATR_REQ_GEN_BYTES to the template */
+ g_byte_array_append(cmd, ARRAY_AND_SIZE(cmd_prefix));
+ tlv[0] = NCI_CONFIG_LN_ATR_RES_GEN_BYTES;
+ tlv[1] = (guint8)gb->len;
+ g_byte_array_append(cmd, tlv, 2); /* Only type and length */
+ g_byte_array_append(cmd, gb->data, gb->len);
+ tlv[0] = NCI_CONFIG_PN_ATR_REQ_GEN_BYTES;
+ g_byte_array_append(cmd, tlv, 2); /* Same length */
+ g_byte_array_append(cmd, gb->data, gb->len);
- if (status == NCI_REQUEST_CANCELLED || !nci_transition_active(self)) {
- GDEBUG("CORE_GET_CONFIG cancelled");
- return;
- } else if (status == NCI_REQUEST_TIMEOUT) {
- GDEBUG("CORE_GET_CONFIG timed out");
- } else if (sm) {
- /*
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_util.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,7 +31,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "nci_util.h"
+#include "nci_util_p.h"
#include "nci_log.h"
#include <gutil_macros.h>
@@ -45,20 +46,78 @@
case NCI_MODE_PASSIVE_LISTEN_F:
case NCI_MODE_ACTIVE_LISTEN_A:
case NCI_MODE_ACTIVE_LISTEN_F:
- case NCI_MODE_PASSIVE_LISTEN_15693:
+ case NCI_MODE_PASSIVE_LISTEN_V:
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:
+ case NCI_MODE_PASSIVE_POLL_V:
break;
}
/* Assume Poll by default */
return FALSE;
}
+static
+gboolean
+nci_parse_find_config_param(
+ guint nparams,
+ const GUtilData* params,
+ guint8 id,
+ GUtilData* value)
+{
+ const guint8* ptr = params->bytes;
+ const guint8* end = ptr + params->size;
+
+ /*
+ * +-----------------------------------------+
+ * | 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;
+}
+
+guint
+nci_parse_config_param_uint(
+ guint nparams,
+ const GUtilData* params,
+ guint8 id,
+ guint* value)
+{
+ GUtilData data;
+
+ if (nci_parse_find_config_param(nparams, params, id, &data) &&
+ data.size > 0 && data.size <= sizeof(guint)) {
+ gsize i;
+
+ /*
+ * 1.11 Coding Conventions
+ *
+ * All values greater than 1 octet are sent and
+ * received in Little Endian format.
+ */
+ for (*value = 0, i = 0; i < data.size; i++) {
+ *value += ((guint)data.bytes[i]) << (8 * i);
+ }
+ return data.size;
+ } else {
+ return 0;
+ }
+}
+
const NciModeParam*
nci_parse_mode_param(
NciModeParam* param,
@@ -265,8 +324,8 @@
/* 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:
+ case NCI_MODE_PASSIVE_POLL_V:
+ case NCI_MODE_PASSIVE_LISTEN_V:
break;
case NCI_MODE_PASSIVE_LISTEN_A:
case NCI_MODE_PASSIVE_LISTEN_B:
@@ -373,17 +432,14 @@
const guint8* ats = bytes + 1;
const guint8* ats_end = ats + ats_len;
const guint8* ats_ptr = ats;
+ const guint8* ta = NULL;
+ const guint8* tb = NULL;
+ const guint8* tc = NULL;
const guint8 t0 = *ats_ptr++;
-#define NFC_T4A_ATS_T0_A (0x10) /* TA is transmitted */
-#define NFC_T4A_ATS_T0_B (0x20) /* TB is transmitted */
-#define NFC_T4A_ATS_T0_C (0x30) /* TC is transmitted */
-#define NFC_T4A_ATS_T0_FSCI_MASK (0x0f) /* FSCI mask */
-
- /* Skip TA, TB and TC if they are present */
- if (t0 & NFC_T4A_ATS_T0_A) ats_ptr++;
- if (t0 & NFC_T4A_ATS_T0_B) ats_ptr++;
- if (t0 & NFC_T4A_ATS_T0_C) ats_ptr++;
+ if (t0 & NFC_T4A_ATS_T0_A) ta = ats_ptr++;
+ if (t0 & NFC_T4A_ATS_T0_B) tb = ats_ptr++;
+ if (t0 & NFC_T4A_ATS_T0_C) tc = ats_ptr++;
if (ats_ptr <= ats_end) {
/* NFCForum-TS-DigitalProtocol-1.01
* Table 66: FSCI to FSC Conversion */
@@ -392,6 +448,11 @@
16, 24, 32, 40, 48, 64, 96, 128, 256
};
+ /* Save TA, TB and TC if they are present */
+ param->t0 = t0;
+ if (ta) param->ta = *ta;
+ if (tb) param->tb = *tb;
+ if (tc) param->tc = *tc;
param->fsc = (fsci < G_N_ELEMENTS(fsc_table)) ?
fsc_table[fsci] :
fsc_table[G_N_ELEMENTS(fsc_table) - 1];
@@ -413,6 +474,16 @@
GDEBUG(" T1 =%s", buf->str);
g_string_free(buf, TRUE);
}
+ GDEBUG(" T0 = 0x%02x", param->t0);
+ if (param->t0 & NFC_T4A_ATS_T0_A) {
+ GDEBUG(" TA = 0x%02x", param->ta);
+ }
+ if (param->t0 & NFC_T4A_ATS_T0_B) {
+ GDEBUG(" TB = 0x%02x", param->tb);
+ }
+ if (param->t0 & NFC_T4A_ATS_T0_C) {
+ GDEBUG(" TC = 0x%02x", param->tc);
+ }
}
#endif
return TRUE;
@@ -644,13 +715,13 @@
break;
case NCI_MODE_PASSIVE_POLL_F:
case NCI_MODE_ACTIVE_POLL_F:
- case NCI_MODE_PASSIVE_POLL_15693:
+ case NCI_MODE_PASSIVE_POLL_V:
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:
+ case NCI_MODE_PASSIVE_LISTEN_V:
break;
}
break;
@@ -680,9 +751,9 @@
GDEBUG("Failed to parse parameters for NFC-DEP listen mode");
break;
case NCI_MODE_PASSIVE_POLL_B:
- case NCI_MODE_PASSIVE_POLL_15693:
+ case NCI_MODE_PASSIVE_POLL_V:
case NCI_MODE_PASSIVE_LISTEN_B:
- case NCI_MODE_PASSIVE_LISTEN_15693:
+ case NCI_MODE_PASSIVE_LISTEN_V:
break;
}
break;
@@ -806,11 +877,11 @@
case NCI_MODE_ACTIVE_POLL_F:
active_mode = TRUE;
break;
- case NCI_MODE_PASSIVE_LISTEN_15693:
+ case NCI_MODE_PASSIVE_LISTEN_V:
case NCI_MODE_PASSIVE_POLL_A:
case NCI_MODE_PASSIVE_POLL_B:
|
[-]
[+]
|
Added |
_service:tar_git:libncicore-1.1.18.tar.bz2/src/nci_util_p.h
^
|
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NCI_UTIL_PRIVATE_H
+#define NCI_UTIL_PRIVATE_H
+
+#include <nci_util.h>
+#include "nci_types_p.h"
+
+gboolean
+nci_listen_mode(
+ NCI_MODE mode)
+ NCI_INTERNAL;
+
+guint
+nci_parse_config_param_uint(
+ guint nparams,
+ const GUtilData* params,
+ guint8 id,
+ guint* value)
+ NCI_INTERNAL;
+
+const NciModeParam*
+nci_parse_mode_param(
+ NciModeParam* param,
+ NCI_MODE mode,
+ const guint8* bytes,
+ guint len)
+ NCI_INTERNAL;
+
+gboolean
+nci_parse_discover_ntf(
+ NciDiscoveryNtf* ntf,
+ NciModeParam* param,
+ const guint8* bytes,
+ guint len)
+ NCI_INTERNAL;
+
+gboolean
+nci_parse_intf_activated_ntf(
+ NciIntfActivationNtf* ntf,
+ NciModeParam* mode_param,
+ NciActivationParam* activation_param,
+ const guint8* pkt,
+ guint len)
+ NCI_INTERNAL;
+
+NciDiscoveryNtf*
+nci_discovery_ntf_copy_array(
+ const NciDiscoveryNtf* const* ntfs,
+ guint count)
+ NCI_INTERNAL;
+
+NciDiscoveryNtf*
+nci_discovery_ntf_copy(
+ const NciDiscoveryNtf* ntf)
+ NCI_INTERNAL;
+
+#endif /* NCI_UTIL_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/unit/nci_core/test_nci_core.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2020 Jolla Ltd.
- * Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2018-2021 Jolla Ltd.
+ * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -37,6 +37,7 @@
#include "nci_sm.h"
#include <gutil_macros.h>
+#include <gutil_misc.h>
#include <gutil_log.h>
#include <glib-object.h> /* For g_type_init() */
@@ -44,7 +45,15 @@
static TestOpt test_opt;
#define TEST_DEFAULT_CMD_TIMEOUT (10000) /* milliseconds */
+#define TEST_SHORT_TIMEOUT (500) /* milliseconds */
+#define TMP_DIR_TEMPLATE "test-nci-core-XXXXXX"
+#define CONFIG_SECTION "[Configuration]"
+#define CONFIG_ENTRY_TECHNOLOGIES "Technologies"
+
+static const guint8 CORE_RESET_CMD[] = {
+ 0x20, 0x00, 0x01, 0x00
+};
static const guint8 CORE_RESET_RSP[] = {
0x40, 0x00, 0x03, 0x00, 0x10, 0x00
};
@@ -54,6 +63,9 @@
static const guint8 CORE_RESET_V2_RSP[] = {
0x40, 0x00, 0x01, 0x00
};
+static const guint8 CORE_RESET_V2_RSP_ERROR[] = {
+ 0x40, 0x00, 0x01, 0x03
+};
static const guint8 CORE_RESET_V2_NTF[] = {
0x60, 0x00, 0x1f, 0x02, 0x01, 0x20, 0x02, 0x1a,
0x04, 0x04, 0x01, 0x03, 0x63, 0x94, 0x02, 0x02,
@@ -64,6 +76,12 @@
static const guint8 CORE_RESET_RSP_BROKEN[] = {
0x40, 0x00, 0x02, 0x00, 0x00
};
+static const guint8 CORE_INIT_CMD_V1[] = {
+ 0x20, 0x01, 0x00
+};
+static const guint8 CORE_INIT_CMD_V2[] = {
+ 0x20, 0x01, 0x02, 0x00, 0x00
+};
static const guint8 CORE_INIT_RSP[] = {
0x40, 0x01, 0x19, 0x00, 0x03, 0x0e, 0x02, 0x00,
0x08, 0x00, 0x01, 0x02, 0x03, 0x80, 0x82, 0x83,
@@ -76,6 +94,12 @@
0x84, 0x02, 0x5c, 0x03, 0xff, 0x02, 0x00, 0x04,
0x41, 0x11, 0x01, 0x1a
};
+static const guint8 CORE_INIT_RSP_NO_ROUTING[] = {
+ 0x40, 0x01, 0x19, 0x00, 0x03, 0x0e, 0x02, 0x00,
+ 0x08, 0x00, 0x01, 0x02, 0x03, 0x80, 0x82, 0x83,
+ 0x84, 0x02, 0x00, 0x00, 0xff, 0x02, 0x00, 0x04,
+ 0x41, 0x11, 0x01, 0x18
+};
static const guint8 CORE_INIT_V2_RSP[] = {
0x40, 0x01, 0x18, 0x00, 0x1a, 0x7e, 0x06, 0x00,
0x02, 0x00, 0x02, 0xff, 0xff, 0x00, 0x0c, 0x01,
@@ -116,39 +140,174 @@
static const guint8 CORE_INIT_RSP_BROKEN[] = {
0x40, 0x01, 0x00
};
-static const guint8 CORE_GET_CONFIG_RSP[] = {
- 0x40, 0x03, 0x08, 0x00, 0x02, 0x08, 0x01, 0x00,
- 0x11, 0x01, 0x00
+#define LLCP_MAGIC 0x46, 0x66, 0x6d
+static const guint8 CORE_SET_CONFIG_CMD_DEFAULT[] = {
+ 0x20, 0x02, 0x3d,
+ 0x07,
+ NCI_CONFIG_TOTAL_DURATION, 0x02, 0xf4, 0x01,
+ NCI_CONFIG_PA_BAIL_OUT, 0x01, 0x00,
+ NCI_CONFIG_PB_BAIL_OUT, 0x01, 0x00,
+ NCI_CONFIG_LN_ATR_RES_CONFIG, 0x01, 0x30,
+ NCI_CONFIG_PN_ATR_REQ_CONFIG, 0x01, 0x30,
+ NCI_CONFIG_LN_ATR_RES_GEN_BYTES, 0x14,
+ LLCP_MAGIC,
+ 0x01, 0x01, 0x11, /* VERSION */
+ 0x02, 0x02, 0x07, 0xff, /* MIUX */
+ 0x03, 0x02, 0x00, 0x03, /* WKS */
+ 0x04, 0x01, 0x64, /* LTO */
+ 0x07, 0x01, 0x03, /* OPT */
+ NCI_CONFIG_PN_ATR_REQ_GEN_BYTES, 0x14,
+ LLCP_MAGIC,
+ 0x01, 0x01, 0x11, /* VERSION */
+ 0x02, 0x02, 0x07, 0xff, /* MIUX */
+ 0x03, 0x02, 0x00, 0x03, /* WKS */
+ 0x04, 0x01, 0x64, /* LTO */
+ 0x07, 0x01, 0x03 /* OPT */
+};
+static const guint8 CORE_SET_CONFIG_CMD_VERSION_10_WKS_0101[] = {
+ 0x20, 0x02, 0x3d,
+ 0x07,
+ NCI_CONFIG_TOTAL_DURATION, 0x02, 0xf4, 0x01,
+ NCI_CONFIG_PA_BAIL_OUT, 0x01, 0x00,
+ NCI_CONFIG_PB_BAIL_OUT, 0x01, 0x00,
+ NCI_CONFIG_LN_ATR_RES_CONFIG, 0x01, 0x30,
+ NCI_CONFIG_PN_ATR_REQ_CONFIG, 0x01, 0x30,
+ NCI_CONFIG_LN_ATR_RES_GEN_BYTES, 0x14,
+ LLCP_MAGIC,
+ 0x01, 0x01, 0x10, /* VERSION */
+ 0x02, 0x02, 0x07, 0xff, /* MIUX */
+ 0x03, 0x02, 0x01, 0x01, /* WKS */
+ 0x04, 0x01, 0x64, /* LTO */
+ 0x07, 0x01, 0x03, /* OPT */
+ NCI_CONFIG_PN_ATR_REQ_GEN_BYTES, 0x14,
+ LLCP_MAGIC,
+ 0x01, 0x01, 0x10, /* VERSION */
+ 0x02, 0x02, 0x07, 0xff, /* MIUX */
+ 0x03, 0x02, 0x01, 0x01, /* WKS */
+ 0x04, 0x01, 0x64, /* LTO */
+ 0x07, 0x01, 0x03 /* OPT */
};
-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_SET_CONFIG_RSP[] = {
+ 0x40, 0x02, 0x02, 0x00, 0x00
};
-static const guint8 CORE_GET_CONFIG_RSP_BROKEN_DURATION_1[] = {
- 0x40, 0x03, 0x05, 0x00, 0x01, 0x00, 0x02, 0xf4
+static const guint8 CORE_SET_CONFIG_RSP_ERROR[] = {
+ 0x40, 0x02, 0x02, NCI_STATUS_REJECTED, 0x00
};
-static const guint8 CORE_GET_CONFIG_RSP_BROKEN_DURATION_2[] = {
- 0x40, 0x03, 0x05, 0x00, 0x01, 0x00, 0x01, 0xf4
+static const guint8 CORE_GET_CONFIG_CMD_DISCOVERY[] = {
+ 0x20, 0x03, 0x03, 0x02, 0x32, 0x50 /* LA_SEL_INFO, LF_PROTOCOL_TYPE */
};
-static const guint8 CORE_GET_CONFIG_RSP_BROKEN_DURATION_3[] = {
- 0x40, 0x03, 0x03, 0x00, 0x01, 0x00
+static const guint8 CORE_GET_CONFIG_RSP_DISCOVERY_INVALID_PARAM[] = {
+ 0x40, 0x03, 0x06, NCI_STATUS_INVALID_PARAM, 0x02,
+ 0x32, 0x00, 0x50, 0x00
+};
+static const guint8 CORE_GET_CONFIG_RSP_DISCOVERY_RW[] = {
+ 0x40, 0x03, 0x08, 0x00, 0x02,
+ 0x32, 0x01, 0x00, /* LA_SEL_INFO = 0 */
+ 0x50, 0x01, 0x00 /* LF_PROTOCOL_TYPE = 0 */
+};
+static const guint8 CORE_GET_CONFIG_RSP_DISCOVERY_PEER[] = {
+ 0x40, 0x03, 0x08, 0x00, 0x02,
+ 0x32, 0x01, 0x40, /* LA_SEL_INFO = 0x40 */
+ 0x50, 0x01, 0x02 /* LF_PROTOCOL_TYPE = 0x02 */
+};
+static const guint8 CORE_GET_CONFIG_RSP_DISCOVERY_CE[] = {
+ 0x40, 0x03, 0x08, 0x00, 0x02,
+ 0x32, 0x01, 0x20, /* LA_SEL_INFO = 0x20 */
+ 0x50, 0x01, 0x00 /* LF_PROTOCOL_TYPE = 0x00 */
+};
+static const guint8 CORE_GET_CONFIG_RSP_DISCOVERY_CE_PEER[] = {
+ 0x40, 0x03, 0x08, 0x00, 0x02,
+ 0x32, 0x01, 0x60, /* LA_SEL_INFO = 0x60 */
+ 0x50, 0x01, 0x02 /* LF_PROTOCOL_TYPE = 0x02 */
+};
+static const guint8 CORE_GET_CONFIG_RSP_DISCOVERY_CE_A[] = {
+ 0x40, 0x03, 0x08, 0x00, 0x02,
+ 0x32, 0x01, 0x60, /* LA_SEL_INFO = 0x60 */
+ 0x50, 0x01, 0x00 /* LF_PROTOCOL_TYPE = 0x00 */
};
static const guint8 CORE_GET_CONFIG_RSP_ERROR[] = {
0x40, 0x03, 0x02, 0x03, 0x00
};
-static const guint8 CORE_GET_CONFIG_RSP_INVALID_PARAM[] = {
- 0x40, 0x03, 0x04, NCI_STATUS_INVALID_PARAM, 0x01, 0x11, 0x00
-};
-static const guint8 CORE_GET_CONFIG_BROKEN[] = {
- 0x40, 0x03, 0x00
-};
-static const guint8 CORE_SET_CONFIG_RSP[] = {
- 0x40, 0x02, 0x02, 0x00, 0x00
-};
-static const guint8 CORE_SET_CONFIG_RSP_ERROR[] = {
- 0x40, 0x02, 0x02, NCI_STATUS_REJECTED, 0x00
+static const guint8 CORE_SET_CONFIG_CMD_DISCOVERY_RW[] = {
+ 0x20, 0x02, 0x07, 0x02,
+ 0x32, 0x01, 0x00, /* LA_SEL_INFO = 0 */
+ 0x50, 0x01, 0x00 /* LF_PROTOCOL_TYPE = 0 */
+};
+static const guint8 CORE_SET_CONFIG_CMD_DISCOVERY_PEER[] = {
+ 0x20, 0x02, 0x07, 0x02,
+ 0x32, 0x01, 0x40, /* LA_SEL_INFO = 0x40 */
+ 0x50, 0x01, 0x02 /* LF_PROTOCOL_TYPE = 0x02 */
+};
+static const guint8 CORE_SET_CONFIG_CMD_DISCOVERY_CE[] = {
+ 0x20, 0x02, 0x07, 0x02,
+ 0x32, 0x01, 0x20, /* LA_SEL_INFO = 0x20 */
+ 0x50, 0x01, 0x00 /* LF_PROTOCOL_TYPE = 0x00 */
|
[-]
[+]
|
Changed |
_service:tar_git:libncicore-1.1.18.tar.bz2/unit/nci_util/test_nci_util.c
^
|
@@ -1,6 +1,7 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2020 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
@@ -32,7 +33,9 @@
#include "test_common.h"
-#include "nci_util.h"
+#include "nci_util_p.h"
+
+#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
static TestOpt test_opt;
@@ -47,6 +50,8 @@
{
g_assert(!nci_discovery_ntf_copy_array(NULL, 0));
g_assert(!nci_discovery_ntf_copy(NULL));
+ g_assert(!nci_util_copy_mode_param(NULL, 0));
+ g_assert(!nci_util_copy_activation_param(NULL, 0, 0));
}
/*==========================================================================*
@@ -64,7 +69,7 @@
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));
+ g_assert(nci_listen_mode(NCI_MODE_PASSIVE_LISTEN_V));
/* Poll modes */
g_assert(!nci_listen_mode(NCI_MODE_PASSIVE_POLL_A));
@@ -72,7 +77,7 @@
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));
+ g_assert(!nci_listen_mode(NCI_MODE_PASSIVE_POLL_V));
/* Invalid mode */
g_assert(!nci_listen_mode((NCI_MODE)(-1)));
@@ -243,7 +248,7 @@
.mode = (NCI_MODE)(-1)
},{
.name = "unhandled_mode",
- .mode = NCI_MODE_PASSIVE_LISTEN_15693
+ .mode = NCI_MODE_PASSIVE_LISTEN_V
},{
.name = "listen_mode",
.mode = NCI_MODE_PASSIVE_LISTEN_A
@@ -383,27 +388,52 @@
0x02, 0x02, 0x07, 0xff, 0x03, 0x02, 0x00, 0x13,
0x04, 0x01, 0xff
};
-
static const guint8 test_intf_activated_ntf_nfc_dep_listen_2[] = {
0x01, 0x03, 0x05, 0x83, 0xfb, 0x01, 0x00, 0x83,
0x00, 0x00, 0x0f, 0x0e, 0xc5, 0x47, 0xe4, 0x98,
0x4d, 0x88, 0x04, 0xb4, 0x92, 0xe5, 0x00, 0x00,
0x00, 0x32
};
-
-static const guint8 test_intf_activated_ntf_iso_dep_poll_1[] = {
+static const guint8 test_intf_activated_ntf_isodep_poll_1[] = {
0x01, 0x02, 0x04, 0x01, 0xff, 0x01, 0x0c, 0x0b,
0xdb, 0xa2, 0xa2, 0x2b, 0x52, 0x74, 0x4d, 0x43,
0x00, 0x81, 0xc1, 0x01, 0x00, 0x00, 0x02, 0x01,
0x00
};
-
-static const guint8 test_intf_activated_ntf_iso_dep_poll_2[] = {
+static const guint8 test_intf_activated_ntf_isodep_poll_2[] = {
0x01, 0x02, 0x04, 0x01, 0xff, 0x01, 0x0c, 0x0b,
0xdb, 0xa2, 0xa2, 0x2b, 0x52, 0x74, 0x4d, 0x43,
0x00, 0x81, 0xc1, 0x01, 0x00, 0x00, 0x05, 0x04,
0x00, 0x01, 0x02, 0x03
};
+static const guint8 test_intf_activated_ntf_isodep_polla_1[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x05, 0x04, 0x78, 0x77, 0x95,
+ 0x02
+};
+static const guint8 test_intf_activated_ntf_isodep_polla_2[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x04, 0x03, 0x38, 0x77, 0x95
+};
+static const guint8 test_intf_activated_ntf_isodep_polla_3[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x03, 0x02, 0x18, 0x77
+};
+static const guint8 test_intf_activated_ntf_isodep_polla_4[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x02, 0x01, 0x08
+};
+static const guint8 test_intf_activated_ntf_isodep_polla_5[] = {
+ 0x01, 0x02, 0x04, 0x00, 0xff, 0x01, 0x09, 0x04,
+ 0x00, 0x04, 0x08, 0x46, 0x91, 0xde, 0x01, 0x20,
+ 0x00, 0x00, 0x00, 0x14, 0x13, 0x78, 0x77, 0x95,
+ 0x02, 0x80, 0x31, 0xb8, 0x65, 0xb0, 0x85, 0x03,
+ 0x00, 0xef, 0x12, 0x00, 0xf6, 0x82, 0x90, 0x00
+};
static const NciModeParam test_intf_activated_ntf_mifare_mp = {
.poll_a = {
@@ -423,12 +453,21 @@
.sel_res = 0x40
}
};
+static const NciModeParam test_intf_activated_ntf_polla_mp_1 = {
+ .poll_a = {
+ .sens_res = { 0x04, 0x00 },
+ .nfcid1_len = 4,
+ .nfcid1 = { 0x08, 0x46, 0x91, 0xde },
+ .sel_res_len = 1,
+ .sel_res = 0x20
+ }
+};
static const NciModeParam test_intf_activated_ntf_poll_b_mp_1 = {
.poll_b = {
.nfcid0 = {0xdb, 0xa2, 0xa2, 0x2b},
.fsc = 256,
.app_data = {0x52, 0x74, 0x4d, 0x43},
- .prot_info = { test_intf_activated_ntf_iso_dep_poll_1 + 0x10, 3 }
+ .prot_info = { test_intf_activated_ntf_isodep_poll_1 + 0x10, 3 }
}
};
static const NciModeParam test_intf_activated_ntf_poll_b_mp_2 = {
@@ -436,7 +475,7 @@
.nfcid0 = {0xdb, 0xa2, 0xa2, 0x2b},
.fsc = 256,
.app_data = {0x52, 0x74, 0x4d, 0x43},
- .prot_info = { test_intf_activated_ntf_iso_dep_poll_2 + 0x10, 3 }
+ .prot_info = { test_intf_activated_ntf_isodep_poll_2 + 0x10, 3 }
}
};
static const NciActivationParam test_intf_activated_ntf_nfc_dep_poll_ap_1 = {
@@ -495,19 +534,58 @@
.pp = 0x32
}
};
-static const NciActivationParam test_intf_activated_ntf_iso_dep_poll_ap_1 = {
+static const NciActivationParam test_intf_activated_ntf_isodep_poll_ap_1 = {
.iso_dep_poll_b = {
.mbli = 0x00,
.did = 0x00,
.hlr = { NULL, 0 },
}
};
-
-static const NciActivationParam test_intf_activated_ntf_iso_dep_poll_ap_2 = {
+static const NciActivationParam test_intf_activated_ntf_isodep_poll_ap_2 = {
.iso_dep_poll_b = {
.mbli = 0x00,
.did = 0x00,
- .hlr = { test_intf_activated_ntf_iso_dep_poll_2 + 0x19, 3 },
+ .hlr = { test_intf_activated_ntf_isodep_poll_2 + 0x19, 3 },
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_1 = {
+ .iso_dep_poll_a = {
+ .fsc = 256,
+ .t0 = 0x78,
+ .ta = 0x77,
+ .tb = 0x95,
+ .tc = 0x02
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_2 = {
+ .iso_dep_poll_a = {
+ .fsc = 256,
+ .t0 = 0x38,
+ .ta = 0x77,
+ .tb = 0x95
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_3 = {
+ .iso_dep_poll_a = {
+ .fsc = 256,
+ .t0 = 0x18,
+ .ta = 0x77
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_4 = {
+ .iso_dep_poll_a = {
+ .fsc = 256,
+ .t0 = 0x08
+ }
+};
+static const NciActivationParam test_intf_activated_ntf_isodep_polla_ap_5 = {
|