[-]
[+]
|
Changed |
_service:tar_git:nfcd.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,6 +2,6 @@
<service name="tar_git">
<param name="url">https://git.monich.net/git/nfcd.git</param>
<param name="branch">master</param>
- <param name="revision">b3bc0b7</param>
+ <param name="revision">45f0e26</param>
</service>
</services>
\ No newline at end of file
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/README
^
|
@@ -3,5 +3,5 @@
Arbitrates access to NFC hardware and provides D-Bus interfaces
to NFC-aware applications.
-Reader/writer (ISO-DEP and Type 2 tags) and Peer-to-Peer (NFC-DEP)
-modes are supported. No Card Emulation yet.
+Reader/writer (ISO-DEP and Type 2 tags), Peer-to-Peer (NFC-DEP)
+and Card Emulation modes are supported.
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/Makefile
^
|
@@ -33,6 +33,9 @@
nfc_crc.c \
nfc_config.c \
nfc_core.c \
+ nfc_host.c \
+ nfc_host_app.c \
+ nfc_host_service.c \
nfc_initiator.c \
nfc_llc.c \
nfc_llc_io.c \
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_adapter.h
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_ADAPTER_H
@@ -82,6 +89,13 @@
NfcPeer* peer,
void* user_data); /* Since 1.1.0 */
+typedef
+void
+(*NfcAdapterHostFunc)(
+ NfcAdapter* adapter,
+ NfcHost* host,
+ void* user_data); /* Since 1.2.0 */
+
NfcAdapter*
nfc_adapter_ref(
NfcAdapter* adapter)
@@ -109,6 +123,16 @@
NfcAdapter* adapter) /* Since 1.1.0 */
NFCD_EXPORT;
+NfcHost**
+nfc_adapter_hosts(
+ NfcAdapter* adapter) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
+NFC_TECHNOLOGY
+nfc_adapter_get_supported_techs(
+ NfcAdapter* adapter) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
NfcTag*
nfc_adapter_add_tag_t2(
NfcAdapter* adapter,
@@ -190,6 +214,12 @@
const char* name) /* Since 1.1.0 */
NFCD_EXPORT;
+NfcHost*
+nfc_adapter_add_host(
+ NfcAdapter* adapter,
+ NfcInitiator* initiator) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
gulong
nfc_adapter_add_target_presence_handler(
NfcAdapter* adapter,
@@ -226,6 +256,20 @@
NFCD_EXPORT;
gulong
+nfc_adapter_add_host_added_handler(
+ NfcAdapter* adapter,
+ NfcAdapterHostFunc func,
+ void* user_data) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
+gulong
+nfc_adapter_add_host_removed_handler(
+ NfcAdapter* adapter,
+ NfcAdapterHostFunc func,
+ void* user_data) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
+gulong
nfc_adapter_add_powered_changed_handler(
NfcAdapter* adapter,
NfcAdapterFunc func,
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_adapter_impl.h
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_ADAPTER_IMPL_H
@@ -49,6 +56,10 @@
gboolean (*submit_mode_request)(NfcAdapter* adapter, NFC_MODE mode);
void (*cancel_mode_request)(NfcAdapter* adapter);
+ /* Since 1.2.0 */
+ NFC_TECHNOLOGY (*get_supported_techs)(NfcAdapter* adapter);
+ void (*set_allowed_techs)(NfcAdapter* adapter, NFC_TECHNOLOGY techs);
+
/* Padding for future expansion */
void (*_reserved1)(void);
void (*_reserved2)(void);
@@ -58,8 +69,6 @@
void (*_reserved6)(void);
void (*_reserved7)(void);
void (*_reserved8)(void);
- void (*_reserved9)(void);
- void (*_reserved10)(void);
} NfcAdapterClass;
#define NFC_ADAPTER_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_host.h
^
|
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef NFC_HOST_H
+#define NFC_HOST_H
+
+#include "nfc_types.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Since 1.2.0 */
+
+typedef struct nfc_host_priv NfcHostPriv;
+
+struct nfc_host {
+ GObject object;
+ NfcHostPriv* priv;
+ NfcInitiator* initiator;
+ const char* name;
+ NfcHostApp* app; /* Selected app */
+};
+
+GType nfc_host_get_type(void) NFCD_EXPORT;
+#define NFC_TYPE_HOST (nfc_host_get_type())
+#define NFC_IS_HOST(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, NFC_TYPE_HOST)
+#define NFC_HOST(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, NFC_TYPE_HOST, NfcHost)
+
+typedef
+void
+(*NfcHostFunc)(
+ NfcHost* host,
+ void* user_data);
+
+typedef
+void
+(*NfcHostResultFunc)(
+ NfcHost* host,
+ gboolean ok,
+ void* user_data);
+
+NfcHost*
+nfc_host_ref(
+ NfcHost* host)
+ NFCD_EXPORT;
+
+void
+nfc_host_unref(
+ NfcHost* host)
+ NFCD_EXPORT;
+
+void
+nfc_host_select_app(
+ NfcHost* host,
+ const char* aid)
+ NFCD_EXPORT;
+
+void
+nfc_host_deselect_app(
+ NfcHost* host)
+ NFCD_EXPORT;
+
+void
+nfc_host_deactivate(
+ NfcHost* host)
+ NFCD_EXPORT;
+
+gulong
+nfc_host_add_app_changed_handler(
+ NfcHost* host,
+ NfcHostFunc func,
+ void* user_data)
+ NFCD_EXPORT;
+
+gulong
+nfc_host_add_gone_handler(
+ NfcHost* host,
+ NfcHostFunc func,
+ void* user_data)
+ NFCD_EXPORT;
+
+void
+nfc_host_remove_handler(
+ NfcHost* host,
+ gulong id)
+ NFCD_EXPORT;
+
+void
+nfc_host_remove_handlers(
+ NfcHost* host,
+ gulong* ids,
+ guint count)
+ NFCD_EXPORT;
+
+#define nfc_host_remove_all_handlers(host,ids) \
+ nfc_host_remove_handlers(host, ids, G_N_ELEMENTS(ids))
+
+G_END_DECLS
+
+#endif /* NFC_HOST_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_host_app.h
^
|
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef NFC_HOST_APP_H
+#define NFC_HOST_APP_H
+
+#include "nfc_types.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Since 1.2.0 */
+
+typedef enum nfc_host_app_flags {
+ NFC_HOST_APP_FLAGS_NONE = 0,
+ NFC_HOST_APP_FLAG_ALLOW_IMPLICIT_SELECTION = 0x01
+} NFC_HOST_APP_FLAGS;
+
+typedef struct nfc_host_app_priv NfcHostAppPriv;
+
+struct nfc_host_app {
+ GObject object;
+ NfcHostAppPriv* priv;
+ GUtilData aid;
+ const char* name;
+ NFC_HOST_APP_FLAGS flags;
+};
+
+GType nfc_host_app_get_type(void) NFCD_EXPORT;
+#define NFC_TYPE_HOST_APP (nfc_host_app_get_type())
+#define NFC_HOST_APP(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ NFC_TYPE_HOST_APP, NfcHostApp)
+
+NfcHostApp*
+nfc_host_app_ref(
+ NfcHostApp* app)
+ NFCD_EXPORT;
+
+void
+nfc_host_app_unref(
+ NfcHostApp* app)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_HOST_APP_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_host_app_impl.h
^
|
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef NFC_HOST_APP_IMPL_H
+#define NFC_HOST_APP_IMPL_H
+
+#include "nfc_host_app.h"
+
+G_BEGIN_DECLS
+
+/* Since 1.2.0 */
+
+/* Internal API for use by NfcHostApp implemenations */
+
+typedef
+void
+(*NfcHostAppBoolFunc)(
+ NfcHostApp* app,
+ gboolean result,
+ void* user_data);
+
+typedef struct nfc_host_app_response {
+ guint sw; /* 16 bits (SW1 << 8)|SW2 */
+ GUtilData data; /* Optional, may be all zeros */
+ NfcHostAppBoolFunc sent; /* Optional */
+ void* user_data; /* Passed to NfcHostAppBoolFunc */
+} NfcHostAppResponse;
+
+/*
+ * The response argument may be NULL if APDU wasn't handled. If no
+ * service or app handles the APDU, then 6F00 (No precise diagnosis)
+ * is returned to the card reader.
+ */
+
+typedef
+void
+(*NfcHostAppResponseFunc)(
+ NfcHostApp* app,
+ const NfcHostAppResponse* resp,
+ void* user_data);
+
+/*
+ * Potentially asynchronous operations return NFCD_ID_FAIL (zero) on
+ * failure (in which case neither completion nor destroy callbacks are
+ * invoked), NFCD_ID_SYNC on successful synchronous completion (in this
+ * case the completion and destroy callbacks, if provided, have already
+ * been invoked on the same stack) or any other non-zero value which
+ * indicates a cancellable asynchronous operation.
+ *
+ * If a non-zero value is returned, the destroy callback is always
+ * invoked in any case, regardless of whether the operation gets
+ * completed or cancelled.
+ */
+typedef struct nfc_host_app_class {
+ GObjectClass parent;
+
+ /*
+ * The first call, right after the host has appeared and the app
+ * has been registered. No other call is made until this one gets
+ * completed or cancelled.
+ *
+ * N.B. The app is not notified when the host is gone, the
+ * implementation can use nfc_host_add_gone_handler()
+ * if it needs such a notification.
+ */
+ guint (*start)(NfcHostApp* app, NfcHost* host,
+ NfcHostAppBoolFunc complete, void* user_data, GDestroyNotify destroy);
+
+ /*
+ * Called when the other side deactivates the interface and quickly
+ * reconnects it back. That should be interpreted as a signal to
+ * reset the state of the card emulator to default. The host is the
+ * same as the one already passed to start() and possibly other methods.
+ *
+ * If the app was selected, it should consider itself deselected.
+ * This call will be followed by implicit_select or select if the
+ * app needs to be reselected. The default implementation calls the
+ * deselect() method.
+ */
+ guint (*restart)(NfcHostApp* app, NfcHost* host,
+ NfcHostAppBoolFunc complete, void* user_data, GDestroyNotify destroy);
+
+ guint (*implicit_select)(NfcHostApp* app, NfcHost* host,
+ NfcHostAppBoolFunc complete, void* user_data, GDestroyNotify destroy);
+
+ guint (*select)(NfcHostApp* app, NfcHost* host,
+ NfcHostAppBoolFunc complete, void* user_data, GDestroyNotify destroy);
+
+ void (*deselect)(NfcHostApp* app, NfcHost* host);
+
+ guint (*process)(NfcHostApp* app, NfcHost* host, const NfcApdu* apdu,
+ NfcHostAppResponseFunc resp, void* user_data, GDestroyNotify destroy);
+
+ /*
+ * The cancel() method can be used to cancel a pending operation.
+ * The implementation must guarantee that the operation completion
+ * callback is not invoked for cancelled operations (the destroy
+ * callback still is).
+ *
+ * NFCD_ID_FAIL and NFCD_ID_SYNC ids are ignored (but allowed),
+ * even though they don't actually cancel anything.
+ */
+ void (*cancel)(NfcHostApp* app, guint id);
+
+ /* Padding for future expansion */
+ void (*_reserved1)(void);
+ void (*_reserved2)(void);
+ void (*_reserved3)(void);
+ void (*_reserved4)(void);
+ void (*_reserved5)(void);
+ void (*_reserved6)(void);
+ void (*_reserved7)(void);
+ void (*_reserved8)(void);
+ void (*_reserved9)(void);
+ void (*_reserved10)(void);
+} NfcHostAppClass;
+
+#define NFC_HOST_APP_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
+ NFC_TYPE_HOST_APP, NfcHostAppClass)
+
+void
+nfc_host_app_init_base(
+ NfcHostApp* app,
+ const GUtilData* aid,
+ const char* name,
+ NFC_HOST_APP_FLAGS flags)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_HOST_APP_IMPL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_host_service.h
^
|
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef NFC_HOST_SERVICE_H
+#define NFC_HOST_SERVICE_H
+
+#include "nfc_types.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Since 1.2.0 */
+
+typedef struct nfc_host_service_priv NfcHostServicePriv;
+
+struct nfc_host_service {
+ GObject object;
+ NfcHostServicePriv* priv;
+ const char* name;
+};
+
+GType nfc_host_service_get_type(void) NFCD_EXPORT;
+#define NFC_TYPE_HOST_SERVICE (nfc_host_service_get_type())
+#define NFC_HOST_SERVICE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ NFC_TYPE_HOST_SERVICE, NfcHostService)
+
+NfcHostService*
+nfc_host_service_ref(
+ NfcHostService* service)
+ NFCD_EXPORT;
+
+void
+nfc_host_service_unref(
+ NfcHostService* service)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_HOST_SERVICE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_host_service_impl.h
^
|
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef NFC_HOST_SERVICE_IMPL_H
+#define NFC_HOST_SERVICE_IMPL_H
+
+#include "nfc_host_service.h"
+
+G_BEGIN_DECLS
+
+/* Since 1.2.0 */
+
+/* Internal API for use by NfcHostService implemenations */
+
+typedef
+void
+(*NfcHostServiceBoolFunc)(
+ NfcHostService* service,
+ gboolean result,
+ void* user_data);
+
+typedef struct nfc_host_service_response {
+ guint sw; /* 16 bits (SW1 << 8)|SW2 */
+ GUtilData data; /* Optional, may be all zeros */
+ NfcHostServiceBoolFunc sent; /* Optional */
+ void* user_data; /* Passed to NfcHostServiceBoolFunc */
+} NfcHostServiceResponse;
+
+/*
+ * The response argument may be NULL if APDU wasn't handled. If no
+ * service or app handles the APDU, then 6F00 (No precise diagnosis)
+ * is returned to the card reader.
+ */
+
+typedef
+void
+(*NfcHostServiceResponseFunc)(
+ NfcHostService* service,
+ const NfcHostServiceResponse* resp,
+ void* user_data);
+
+/*
+ * Internal API for use by NfcHostService implemenations.
+ *
+ * NfcHostServices are registered with NfcManager and remain
+ * registered until they are unregistered, even when NFC is idle.
+ *
+ * When NFC reader is detected, first all services and then all apps
+ * have their start() method called. From that point on, it's the
+ * selected (implicitly or explicitly) instance of NfcHostApp is
+ * primarily responsible for communicating with the reader.
+ *
+ * However, if no app is selected or the selected app refuses to handle
+ * the incoming APDU, services will have a chance to process such APDU.
+ * Deselected apps are not bothered with any APDUs at all.
+ */
+
+typedef struct nfc_host_service_class {
+ GObjectClass parent;
+
+ /* Called when the other side starts talking to us */
+ guint (*start)(NfcHostService* service, NfcHost* host,
+ NfcHostServiceBoolFunc complete, void* user_data,
+ GDestroyNotify destroy);
+
+ /*
+ * Called when the other side deactivates the interface and quickly
+ * reconnects it back. That should be interpreted as a signal to
+ * reset the state of the card emulator to default. The host is the
+ * same as the one already passed to start() and possibly other methods.
+ */
+ guint (*restart)(NfcHostService* service, NfcHost* host,
+ NfcHostServiceBoolFunc complete, void* user_data,
+ GDestroyNotify destroy);
+
+ /*
+ * If process() returns zero, neither resp not destroy callback
+ * is invoked.
+ *
+ * If non-zero operation id is returned, the resp and destroy
+ * callbacks are eventually invoked when the operation completes.
+ * Returning NFCD_ID_SYNC means that the completion and destroy
+ * callbacks, if provided, have already been invoked on the same
+ * stack. Otherwise callbacks will be invoked on a fresh stask
+ * when operation completes, successfully or not.
+ *
+ * If a non-zero value is returned, the destroy callback is always
+ * invoked in any case, regardless of whether the operation gets
+ * completed or cancelled.
+ */
+ guint (*process)(NfcHostService* service, NfcHost* host,
+ const NfcApdu* apdu, NfcHostServiceResponseFunc resp,
+ void* user_data, GDestroyNotify destroy);
+
+ /*
+ * The cancel() method can be used to cancel a pending operation.
+ * The implementation must guarantee that the operation completion
+ * callback is not invoked for cancelled operations (the destroy
+ * callback still is).
+ *
+ * NFCD_ID_FAIL and NFCD_ID_SYNC ids are ignored (but allowed),
+ * even though they don't actually cancel anything.
+ */
+ void (*cancel)(NfcHostService* service, guint id);
+
+ /* Padding for future expansion */
+ void (*_reserved1)(void);
+ void (*_reserved2)(void);
+ void (*_reserved3)(void);
+ void (*_reserved4)(void);
+ void (*_reserved5)(void);
+ void (*_reserved6)(void);
+ void (*_reserved7)(void);
+ void (*_reserved8)(void);
+ void (*_reserved9)(void);
+ void (*_reserved10)(void);
+} NfcHostServiceClass;
+
+#define NFC_HOST_SERVICE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
+ NFC_TYPE_HOST_SERVICE, NfcHostServiceClass)
+
+void
+nfc_host_service_init_base(
+ NfcHostService* service,
+ const char* name)
+ NFCD_EXPORT;
+
+G_END_DECLS
+
+#endif /* NFC_HOST_SERVICE_IMPL_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_initiator_impl.h
^
|
@@ -2,32 +2,39 @@
* Copyright (C) 2020-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2020-2021 Jolla Ltd.
*
- * You may use this file under the terms of BSD license as follows:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_INITIATOR_IMPL_H
@@ -129,6 +136,11 @@
NfcInitiator* initiator)
NFCD_EXPORT;
+void
+nfc_initiator_reactivated(
+ NfcInitiator* initiator) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
G_END_DECLS
#endif /* NFC_INITIATOR_IMPL_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_manager.h
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_MANAGER_H
@@ -53,6 +60,8 @@
/* Since 1.1.1 */
NFC_LLCP_VERSION llcp_version;
NfcPeerService* const* services;
+ /* Since 1.2.0 */
+ NFC_TECHNOLOGY techs;
};
GType nfc_manager_get_type() NFCD_EXPORT;
@@ -146,6 +155,30 @@
NfcPeerService* service) /* Since 1.1.0 */
NFCD_EXPORT;
+gboolean
+nfc_manager_register_host_service(
+ NfcManager* manager,
+ NfcHostService* service) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
+void
+nfc_manager_unregister_host_service(
+ NfcManager* manager,
+ NfcHostService* service) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
+gboolean
+nfc_manager_register_host_app(
+ NfcManager* manager,
+ NfcHostApp* app) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
+void
+nfc_manager_unregister_host_app(
+ NfcManager* manager,
+ NfcHostApp* app) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
gulong
nfc_manager_add_adapter_added_handler(
NfcManager* manager,
@@ -195,6 +228,13 @@
void* user_data) /* Since 1.1.1 */
NFCD_EXPORT;
+gulong
+nfc_manager_add_techs_changed_handler(
+ NfcManager* manager,
+ NfcManagerFunc func,
+ void* user_data) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
void
nfc_manager_remove_handler(
NfcManager* manager,
@@ -215,17 +255,19 @@
* Plugins can ask NfcManager to enable and/or disable certain NFC modes.
* The last submitted request takes precedence, i.e. if first a request
* is submitted to enable certain mode and then another another request
- * to disable the same mode, the mode remains enabled until the first
- * request is dropped.
+ * to disable the same mode, the mode gets disabled.
*
* If the same bits are set in both enable and disable masks, the enabling
* bits take precedence. If both are zero, nfc_manager_mode_request_new()
* returns NULL which is tolerated by nfc_manager_mode_request_free()
*
* Note that each NfcModeRequest carries an implicit reference to NfcManager.
+ *
+ * NfcTechRequest behaves similarly with respect to allowed NFC technologies.
*/
typedef struct nfc_mode_request NfcModeRequest; /* Since 1.1.0 */
+typedef struct nfc_tech_request NfcTechRequest; /* Since 1.2.0 */
NfcModeRequest*
nfc_manager_mode_request_new(
@@ -240,6 +282,19 @@
NfcModeRequest* req) /* Since 1.1.0 */
NFCD_EXPORT;
+NfcTechRequest*
+nfc_manager_tech_request_new(
+ NfcManager* manager,
+ NFC_TECHNOLOGY enable,
+ NFC_TECHNOLOGY disable) /* Since 1.2.0 */
+ G_GNUC_WARN_UNUSED_RESULT
+ NFCD_EXPORT;
+
+void
+nfc_manager_tech_request_free(
+ NfcTechRequest* req) /* Since 1.2.0 */
+ NFCD_EXPORT;
+
G_END_DECLS
#endif /* NFC_MANAGER_H */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_types.h
^
|
@@ -11,23 +11,27 @@
*
* 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -45,6 +49,9 @@
typedef struct nfc_adapter NfcAdapter;
typedef struct nfc_configurable NfcConfigurable; /* Since 1.1.10 */
+typedef struct nfc_host NfcHost; /* Since 1.2.0 */
+typedef struct nfc_host_app NfcHostApp; /* Since 1.2.0 */
+typedef struct nfc_host_service NfcHostService; /* Since 1.2.0 */
typedef struct nfc_initiator NfcInitiator; /* Since 1.1.0 */
typedef struct nfc_language NfcLanguage; /* Since 1.0.15 */
typedef struct nfc_peer_connection NfcPeerConnection; /* Since 1.1.0 */
@@ -102,7 +109,7 @@
NFC_PROTOCOL_T2_TAG = 0x02, /* Type 2 Tag */
NFC_PROTOCOL_T3_TAG = 0x04, /* Type 3 Tag */
NFC_PROTOCOL_T4A_TAG = 0x08, /* Type 4A Tag (ISO-DEP, ISO 14443) */
- NFC_PROTOCOL_T4B_TAG = 0x10, /* Type 4B Tag,(ISO-DEP, ISO 14443) */
+ NFC_PROTOCOL_T4B_TAG = 0x10, /* Type 4B Tag (ISO-DEP, ISO 14443) */
NFC_PROTOCOL_NFC_DEP = 0x20 /* NFC-DEP Protocol (ISO 18092) */
} NFC_PROTOCOL;
@@ -149,9 +156,9 @@
GUtilData nfcid0;
/* Since 1.0.40 */
/*
- * NFCForum-TS-DigitalProtocol-1.0
- * Table 25: SENSB_RES Format
- */
+ * NFCForum-TS-DigitalProtocol-1.0
+ * Table 25: SENSB_RES Format
+ */
guint8 app_data[4];
GUtilData prot_info;
} NfcParamPollB; /* Since 1.0.20 */
@@ -171,6 +178,25 @@
NfcParamPollF f;
} NfcParamPoll; /* Since 1.0.33 */
+/* Parsed ISO-DEP APDU */
+typedef struct nfc_apdu {
+ guint8 cla; /* Class byte */
+ guint8 ins; /* Instruction byte */
+ guint8 p1; /* Parameter byte 1 */
+ guint8 p2; /* Parameter byte 2 */
+ GUtilData data; /* Command data */
+ guint le; /* Expected length, zero if none */
+} NfcApdu; /* Since 1.2.0 */
+
+/*
+ * Some APIs that support both synchronous and synchronous completion
+ * use NFCD_ID_SYNC return value to indicate synchronous successful
+ * completion. When this value is returned, the completion and destroy
+ * callbacks have already been invoked on the same stack.
+ */
+#define NFCD_ID_FAIL (0)
+#define NFCD_ID_SYNC ((unsigned int)-1)
+
/* Mark functions exported to plugins as weak */
#ifndef NFCD_EXPORT
# define NFCD_EXPORT __attribute__((weak))
@@ -181,10 +207,12 @@
#define NFC_LLC_LOG_MODULE nfc_llc_log
#define NFC_PEER_LOG_MODULE nfc_peer_log
#define NFC_SNEP_LOG_MODULE nfc_snep_log
+#define NFC_HOST_LOG_MODULE nfc_host_log
extern GLogModule NFC_CORE_LOG_MODULE NFCD_EXPORT;
extern GLogModule NFC_LLC_LOG_MODULE NFCD_EXPORT; /* Since 1.1.0 */
extern GLogModule NFC_PEER_LOG_MODULE NFCD_EXPORT; /* Since 1.1.0 */
extern GLogModule NFC_SNEP_LOG_MODULE NFCD_EXPORT; /* Since 1.1.0 */
+extern GLogModule NFC_HOST_LOG_MODULE NFCD_EXPORT; /* Since 1.2.0 */
G_END_DECLS
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/include/nfc_version.h
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018-2023 Slava Monich <slava@monich.com>
+ * Copyright (C) 2018-2024 Slava Monich <slava@monich.com>
* Copyright (C) 2018-2022 Jolla Ltd.
*
* You may use this file under the terms of the BSD license as follows:
@@ -10,23 +10,27 @@
*
* 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -37,8 +41,8 @@
#define NFC_VERSION_H
#define NFC_VERSION_MAJOR 1
-#define NFC_VERSION_MINOR 1
-#define NFC_VERSION_RELEASE 19
+#define NFC_VERSION_MINOR 2
+#define NFC_VERSION_RELEASE 0
#define NFC_VERSION_WORD(v1,v2,v3) \
((((v1) & 0x7f) << 24) | \
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_adapter.c
^
|
@@ -2,67 +2,74 @@
* Copyright (C) 2018-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2018-2021 Jolla Ltd.
*
- * You may use this file under the terms of BSD license as follows:
+ * You may use this file under the terms of the 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.
+ * 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.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
+ * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "nfc_adapter_p.h"
#include "nfc_adapter_impl.h"
-#include "nfc_peer_services.h"
+#include "nfc_host_p.h"
+#include "nfc_initiator.h"
+#include "nfc_manager_p.h"
#include "nfc_tag_p.h"
#include "nfc_tag_t4_p.h"
#include "nfc_peer_p.h"
#include "nfc_log.h"
#include <gutil_misc.h>
+#include <gutil_macros.h>
+#include <gutil_objv.h>
+#include <gutil_weakref.h>
#include <stdlib.h>
#define NFC_TAG_NAME_FORMAT "tag%u"
#define NFC_PEER_NAME_FORMAT "peer%u"
+#define NFC_HOST_NAME_FORMAT "host%u"
-typedef struct nfc_adapter_tag_entry {
- NfcTag* tag;
- gulong gone_id;
-} NfcAdapterTagEntry;
-
-typedef struct nfc_adapter_peer_entry {
- NfcPeer* peer;
+typedef struct nfc_adapter_object_entry {
+ gpointer obj;
gulong gone_id;
-} NfcAdapterPeerEntry;
+} NfcAdapterObjectEntry;
struct nfc_adapter_priv {
char* name;
- NfcPeerServices* services;
+ GUtilWeakRef* manager_ref;
GHashTable* tag_table;
GHashTable* peer_table;
+ GHashTable* host_table;
NfcPeer** peers;
+ NfcHost** hosts;
guint next_tag_index;
guint next_peer_index;
+ guint next_host_index;
guint32 pending_signals;
NFC_MODE mode_submitted;
gboolean mode_pending;
@@ -89,6 +96,8 @@
SIGNAL_TARGET_PRESENCE,
SIGNAL_PEER_ADDED,
SIGNAL_PEER_REMOVED,
+ SIGNAL_HOST_ADDED,
+ SIGNAL_HOST_REMOVED,
SIGNAL_COUNT
};
@@ -104,12 +113,17 @@
#define SIGNAL_TARGET_PRESENCE_NAME "nfc-adapter-target-presence"
#define SIGNAL_PEER_ADDED_NAME "nfc-adapter-peer-added"
#define SIGNAL_PEER_REMOVED_NAME "nfc-adapter-peer-removed"
+#define SIGNAL_HOST_ADDED_NAME "nfc-adapter-host-added"
+#define SIGNAL_HOST_REMOVED_NAME "nfc-adapter-host-removed"
static guint nfc_adapter_signals[SIGNAL_COUNT] = { 0 };
#define NEW_SIGNAL(name,type) nfc_adapter_signals[SIGNAL_##name] = \
g_signal_new(SIGNAL_##name##_NAME, type, G_SIGNAL_RUN_FIRST, \
0, NULL, NULL, NULL, G_TYPE_NONE, 0)
+#define NEW_OBJECT_SIGNAL(name,type) nfc_adapter_signals[SIGNAL_##name] = \
+ g_signal_new(SIGNAL_##name##_NAME, type, G_SIGNAL_RUN_FIRST, \
+ 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_OBJECT)
static
void
@@ -173,8 +187,7 @@
ptr = self->tags = g_new(NfcTag*, count + 1);
g_hash_table_iter_init(&iter, priv->tag_table);
while (g_hash_table_iter_next(&iter, NULL, &value)) {
- NfcAdapterTagEntry* entry = value;
- *ptr++ = entry->tag;
+ *ptr++ = NFC_TAG(((NfcAdapterObjectEntry*)value)->obj);
}
*ptr = NULL;
@@ -208,8 +221,7 @@
ptr = priv->peers = g_new(NfcPeer*, count + 1);
g_hash_table_iter_init(&iter, priv->peer_table);
while (g_hash_table_iter_next(&iter, NULL, &value)) {
- NfcAdapterPeerEntry* entry = value;
- *ptr++ = entry->peer;
+ *ptr++ = NFC_PEER(((NfcAdapterObjectEntry*)value)->obj);
}
*ptr = NULL;
@@ -218,6 +230,40 @@
}
static
+int
+nfc_adapter_compare_hosts(
+ const void* p1,
+ const void* p2)
+{
+ NfcHost* c1 = *(NfcHost* const*)p1;
+ NfcHost* c2 = *(NfcHost* const*)p2;
+
+ return strcmp(c1->name, c2->name);
+}
+
+static
+void
+nfc_adapter_update_hosts(
+ NfcAdapterPriv* priv)
+{
+ const guint count = g_hash_table_size(priv->host_table);
+ NfcHost** ptr;
+ GHashTableIter iter;
+ gpointer value;
+
+ g_free(priv->hosts);
+ ptr = priv->hosts = g_new(NfcHost*, count + 1);
+ g_hash_table_iter_init(&iter, priv->host_table);
+ while (g_hash_table_iter_next(&iter, NULL, &value)) {
+ *ptr++ = NFC_HOST(((NfcAdapterObjectEntry*)value)->obj);
+ }
+ *ptr = NULL;
+
+ /* Sort hosts by name */
+ qsort(priv->hosts, count, sizeof(NfcHost*), nfc_adapter_compare_hosts);
+}
+
+static
void
nfc_adapter_set_presence(
NfcAdapter* self,
@@ -242,13 +288,23 @@
g_hash_table_iter_init(&it, priv->tag_table);
while (g_hash_table_iter_next(&it, NULL, &value) && !present) {
- present = ((NfcAdapterTagEntry*)value)->tag->present;
+ present = NFC_TAG(((NfcAdapterObjectEntry*)value)->obj)->
+ present;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_adapter_p.h
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_ADAPTER_PRIVATE_H
@@ -43,15 +50,21 @@
gboolean enabled); /* It used to be public and stays exported */
void
+nfc_adapter_set_manager_ref(
+ NfcAdapter* adapter,
+ GUtilWeakRef* ref)
+ NFCD_INTERNAL;
+
+void
nfc_adapter_set_name(
NfcAdapter* adapter,
const char* name)
NFCD_INTERNAL;
void
-nfc_adapter_set_services(
+nfc_adapter_set_allowed_techs(
NfcAdapter* adapter,
- NfcPeerServices* services)
+ NFC_TECHNOLOGY techs)
NFCD_INTERNAL;
#endif /* NFC_ADAPTER_PRIVATE_H */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_host.c
^
|
@@ -0,0 +1,1411 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_host_p.h"
+#include "nfc_host_app_p.h"
+#include "nfc_host_service_p.h"
+#include "nfc_initiator_p.h"
+#include "nfc_util.h"
+#include "nfc_tag_t4.h"
+
+#define GLOG_MODULE_NAME NFC_HOST_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_macros.h>
+#include <gutil_misc.h>
+#include <gutil_objv.h>
+#include <gutil_weakref.h>
+
+GLOG_MODULE_DEFINE2("nfc-host", NFC_CORE_LOG_MODULE);
+
+enum {
+ INITIATOR_GONE,
+ INITIATOR_REACTIVATED,
+ INITIATOR_TRANSMISSION,
+ INITIATOR_EVENT_COUNT
+};
+
+typedef struct nfc_host_apdu NfcHostApdu;
+typedef struct nfc_host_apdu_processor NfcHostApduProcessor;
+
+struct nfc_host_priv {
+ char* name;
+ gulong event_id[INITIATOR_EVENT_COUNT];
+ NfcHostApp** apps;
+ NfcHostService** services;
+ NfcHostApduProcessor* processors;
+ NfcHostApdu* apdu;
+ GSList* pending_ops;
+ GUtilWeakRef* ref;
+};
+
+#define THIS(obj) NFC_HOST(obj)
+#define THIS_TYPE NFC_TYPE_HOST
+#define PARENT_TYPE G_TYPE_OBJECT
+#define PARENT_CLASS nfc_host_parent_class
+
+typedef GObjectClass NfcHostClass;
+G_DEFINE_TYPE(NfcHost, nfc_host, PARENT_TYPE)
+
+enum nfc_host_signal {
+ SIGNAL_APP_CHANGED,
+ SIGNAL_GONE,
+ SIGNAL_COUNT
+};
+
+#define SIGNAL_APP_CHANGED_NAME "nfc-host-app-changed"
+#define SIGNAL_GONE_NAME "nfc-host-gone"
+
+static guint nfc_host_signals[SIGNAL_COUNT] = { 0 };
+
+typedef
+void
+(*NfcHostCallbackFunc)(
+ NfcHost* self);
+
+typedef
+guint
+(*NfcHostStartServiceFunc)(
+ NfcHostService* service,
+ NfcHost* host,
+ NfcHostServiceBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy);
+
+typedef
+guint
+(*NfcHostStartAppFunc)(
+ NfcHostApp* app,
+ NfcHost* host,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy);
+
+typedef
+void
+(*NfcHostOpCancelFunc)(
+ GObject* obj,
+ guint id);
+
+typedef
+void
+(*NfcHostCompleteBool)(
+ NfcHost* host,
+ GObject* obj,
+ gboolean result);
+
+typedef
+void
+(*NfcHostAppCompleteBool)(
+ NfcHost* host,
+ NfcHostApp* app,
+ gboolean result);
+
+typedef
+void
+(*NfcHostServiceCompleteBool)(
+ NfcHost* host,
+ NfcHostService* service,
+ gboolean result);
+
+typedef struct nfc_host_app_response_sent {
+ NfcHostApp* app;
+ NfcTransmission* tx;
+ NfcHostAppBoolFunc sent;
+ void* user_data;
+} NfcHostAppResponseSent;
+
+typedef struct nfc_host_service_response_sent {
+ NfcHostService* service;
+ NfcTransmission* tx;
+ NfcHostServiceBoolFunc sent;
+ void* user_data;
+} NfcHostServiceResponseSent;
+
+typedef struct nfc_host_op {
+ gint ref_count;
+ NfcHostOpCancelFunc cancel;
+ GUtilWeakRef* host_ref;
+ GObject* obj;
+ gboolean completed;
+ GCallback complete;
+ const char* name;
+ guint id;
+} NfcHostOp;
+
+/* Processors are freed with a plain g_free() */
+
+struct nfc_host_apdu_processor {
+ gboolean (*process)(NfcHostApduProcessor*);
+ NfcHostApduProcessor* next;
+ NfcHost* host; /* Not a reference */
+};
+
+typedef struct nfc_host_service_apdu_processor {
+ NfcHostApduProcessor processor;
+ NfcHostService* service; /* Not a reference */
+} NfcHostServiceApduProcessor;
+
+struct nfc_host_apdu {
+ NfcHostApduProcessor* processor;
+ NfcTransmission* tx;
+ NfcApdu apdu;
+};
+
+static
+void
+nfc_host_process_apdu(
+ NfcHost* self);
+
+/*==========================================================================*
+ * NfcHostOp
+ *==========================================================================*/
+
+#define nfc_host_op_destroy ((GDestroyNotify) nfc_host_op_unref)
+
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_host_app.c
^
|
@@ -0,0 +1,314 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_host_app_p.h"
+#include "nfc_host_app_impl.h"
+
+#define GLOG_MODULE_NAME NFC_HOST_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_macros.h>
+#include <gutil_misc.h>
+#include <gutil_weakref.h>
+
+struct nfc_host_app_priv {
+ GUtilWeakRef* self_ref;
+ GWeakRef service_ref;
+ guint8* aid;
+ char* name;
+};
+
+#define THIS(obj) NFC_HOST_APP(obj)
+#define THIS_TYPE NFC_TYPE_HOST_APP
+#define PARENT_TYPE G_TYPE_OBJECT
+#define PARENT_CLASS nfc_host_app_parent_class
+#define GET_THIS_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS(obj, THIS_TYPE, \
+ NfcHostAppClass)
+
+G_DEFINE_ABSTRACT_TYPE(NfcHostApp, nfc_host_app, PARENT_TYPE)
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+void
+nfc_host_app_init_base(
+ NfcHostApp* self,
+ const GUtilData* aid,
+ const char* name,
+ NFC_HOST_APP_FLAGS flags)
+{
+ NfcHostAppPriv* priv = self->priv;
+
+ if (aid) {
+ self->aid.bytes = priv->aid = gutil_memdup(aid->bytes, aid->size);
+ self->aid.size = aid->size;
+ }
+
+ if (name) {
+ self->name = priv->name = g_strdup(name);
+ } else if (aid) {
+ GString* buf = g_string_sized_new(aid->size * 2);
+ guint i;
+
+ for (i = 0; i < aid->size; i++) {
+ g_string_append_printf(buf, "%02X", aid->bytes[i]);
+ }
+ self->name = priv->name = g_string_free(buf, FALSE);
+ } else {
+ self->name = "?";
+ }
+
+ self->flags = flags;
+}
+
+NfcHostApp*
+nfc_host_app_ref(
+ NfcHostApp* self)
+{
+ if (G_LIKELY(self)) {
+ g_object_ref(THIS(self));
+ }
+ return self;
+}
+
+void
+nfc_host_app_unref(
+ NfcHostApp* self)
+{
+ if (G_LIKELY(self)) {
+ g_object_unref(THIS(self));
+ }
+}
+
+/*==========================================================================*
+ * Internal interface
+ *==========================================================================*/
+
+guint
+nfc_host_app_start(
+ NfcHostApp* self,
+ NfcHost* host,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ /* Caller is supposed to check the arguments */
+ return GET_THIS_CLASS(self)->start(self, host, complete,
+ user_data, destroy);
+}
+
+guint
+nfc_host_app_restart(
+ NfcHostApp* self,
+ NfcHost* host,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ /* Caller is supposed to check the arguments */
+ return GET_THIS_CLASS(self)->restart(self, host, complete,
+ user_data, destroy);
+}
+
+guint
+nfc_host_app_implicit_select(
+ NfcHostApp* self,
+ NfcHost* host,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ /* Caller is supposed to check the arguments */
+ return GET_THIS_CLASS(self)->implicit_select(self, host, complete,
+ user_data, destroy);
+}
+
+guint
+nfc_host_app_select(
+ NfcHostApp* self,
+ NfcHost* host,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ /* Caller is supposed to check the arguments */
+ return GET_THIS_CLASS(self)->select(self, host, complete,
+ user_data, destroy);
+}
+
+void
+nfc_host_app_deselect(
+ NfcHostApp* self,
+ NfcHost* host)
+{
+ /* Caller is supposed to check the arguments */
+ return GET_THIS_CLASS(self)->deselect(self, host);
+}
+
+guint
+nfc_host_app_process(
+ NfcHostApp* self,
+ NfcHost* host,
+ const NfcApdu* apdu,
+ NfcHostAppResponseFunc resp,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ /* Caller is supposed to check the arguments */
+ return GET_THIS_CLASS(self)->process(self, host, apdu, resp,
+ user_data, destroy);
+}
+
+void
+nfc_host_app_cancel(
+ NfcHostApp* self,
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_host_app_p.h
^
|
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef NFC_HOST_APP_PRIVATE_H
+#define NFC_HOST_APP_PRIVATE_H
+
+#include "nfc_types_p.h"
+#include "nfc_host_app_impl.h"
+
+/*
+ * Asynchronous operations can be cancelled with nfc_host_app_cancel().
+ * The operation id is invalidated before callbacks are invoked, i.e.
+ * it's an error to call nfc_host_app_cancel() from either complete
+ * or destroy callback - at best it's going to be ignored by the
+ * implementation, at worst it can cause trouble.
+ */
+
+guint
+nfc_host_app_start(
+ NfcHostApp* app,
+ NfcHost* host,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+ NFCD_INTERNAL;
+
+guint
+nfc_host_app_restart(
+ NfcHostApp* app,
+ NfcHost* host,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+ NFCD_INTERNAL;
+
+guint
+nfc_host_app_implicit_select(
+ NfcHostApp* app,
+ NfcHost* host,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+ NFCD_INTERNAL;
+
+guint
+nfc_host_app_select(
+ NfcHostApp* app,
+ NfcHost* host,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+ NFCD_INTERNAL;
+
+void
+nfc_host_app_deselect(
+ NfcHostApp* app,
+ NfcHost* host)
+ NFCD_INTERNAL;
+
+guint
+nfc_host_app_process(
+ NfcHostApp* app,
+ NfcHost* host,
+ const NfcApdu* apdu,
+ NfcHostAppResponseFunc resp,
+ void* user_data,
+ GDestroyNotify destroy)
+ NFCD_INTERNAL;
+
+void
+nfc_host_app_cancel(
+ NfcHostApp* app,
+ guint id)
+ NFCD_INTERNAL;
+
+#endif /* NFC_HOST_APP_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_host_p.h
^
|
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef NFC_HOST_PRIVATE_H
+#define NFC_HOST_PRIVATE_H
+
+#include "nfc_types_p.h"
+
+#include <nfc_host.h>
+
+NfcHost*
+nfc_host_new(
+ const char* name,
+ NfcInitiator* initiator,
+ NfcHostService* const* services,
+ NfcHostApp* const* apps)
+ NFCD_INTERNAL;
+
+void
+nfc_host_start(
+ NfcHost* host)
+ NFCD_INTERNAL;
+
+#endif /* NFC_HOST_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_host_service.c
^
|
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_host_service_p.h"
+#include "nfc_host_service_impl.h"
+
+#define GLOG_MODULE_NAME NFC_HOST_LOG_MODULE
+#include <gutil_log.h>
+#include <gutil_macros.h>
+
+struct nfc_host_service_priv {
+ char* name;
+};
+
+#define THIS(obj) NFC_HOST_SERVICE(obj)
+#define THIS_TYPE NFC_TYPE_HOST_SERVICE
+#define PARENT_TYPE G_TYPE_OBJECT
+#define PARENT_CLASS nfc_host_service_parent_class
+#define GET_THIS_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS(obj, THIS_TYPE, \
+ NfcHostServiceClass)
+
+G_DEFINE_ABSTRACT_TYPE(NfcHostService, nfc_host_service, PARENT_TYPE)
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+NfcHostService*
+nfc_host_service_ref(
+ NfcHostService* self)
+{
+ if (G_LIKELY(self)) {
+ g_object_ref(THIS(self));
+ }
+ return self;
+}
+
+void
+nfc_host_service_unref(
+ NfcHostService* self)
+{
+ if (G_LIKELY(self)) {
+ g_object_unref(THIS(self));
+ }
+}
+
+void
+nfc_host_service_init_base(
+ NfcHostService* self,
+ const char* name)
+{
+ if (G_LIKELY(self)) {
+ NfcHostServicePriv* priv = self->priv;
+
+ g_free(priv->name);
+ self->name = priv->name = g_strdup(name);
+ }
+}
+
+/*==========================================================================*
+ * Internal interface
+ *==========================================================================*/
+
+guint
+nfc_host_service_start(
+ NfcHostService* self,
+ NfcHost* host,
+ NfcHostServiceBoolFunc complete,
+ void* data,
+ GDestroyNotify destroy)
+{
+ /* Caller is supposed to check the argument for NULL */
+ return GET_THIS_CLASS(self)->start(self, host, complete, data, destroy);
+}
+
+guint
+nfc_host_service_restart(
+ NfcHostService* self,
+ NfcHost* host,
+ NfcHostServiceBoolFunc complete,
+ void* data,
+ GDestroyNotify destroy)
+{
+ /* Caller is supposed to check the argument for NULL */
+ return GET_THIS_CLASS(self)->restart(self, host, complete, data, destroy);
+}
+
+guint
+nfc_host_service_process(
+ NfcHostService* self,
+ NfcHost* host,
+ const NfcApdu* apdu,
+ NfcHostServiceResponseFunc resp,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ /* Caller is supposed to check the argument for NULL */
+ return GET_THIS_CLASS(self)->process(self, host, apdu, resp,
+ user_data, destroy);
+}
+
+void
+nfc_host_service_cancel(
+ NfcHostService* self,
+ guint id)
+{
+ /* Caller is supposed to check the argument for NULL */
+ return GET_THIS_CLASS(self)->cancel(self, id);
+}
+
+/*==========================================================================*
+ * Internals
+ *==========================================================================*/
+
+static
+guint
+nfc_host_service_default_start(
+ NfcHostService* service,
+ NfcHost* host,
+ NfcHostServiceBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ if (complete) {
+ complete(service, TRUE, user_data);
+ }
+ if (destroy) {
+ destroy(user_data);
+ }
+ return NFCD_ID_SYNC;
+}
+
+static
+guint
+nfc_host_service_default_process(
+ NfcHostService* service,
+ NfcHost* host,
+ const NfcApdu* apdu,
+ NfcHostServiceResponseFunc resp,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ return NFCD_ID_FAIL;
+}
+
+static
+void
+nfc_host_service_default_cancel(
+ NfcHostService* service,
+ guint id)
+{
+}
+
+static
+void
+nfc_host_service_init(
+ NfcHostService* self)
+{
+ NfcHostServicePriv* priv = G_TYPE_INSTANCE_GET_PRIVATE(self, THIS_TYPE,
+ NfcHostServicePriv);
+
+ self->priv = priv;
+}
+
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_host_service_p.h
^
|
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef NFC_HOST_SERVICE_PRIVATE_H
+#define NFC_HOST_SERVICE_PRIVATE_H
+
+#include "nfc_types_p.h"
+#include "nfc_host_service_impl.h"
+
+guint
+nfc_host_service_start(
+ NfcHostService* service,
+ NfcHost* host,
+ NfcHostServiceBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+ NFCD_INTERNAL;
+
+guint
+nfc_host_service_restart(
+ NfcHostService* service,
+ NfcHost* host,
+ NfcHostServiceBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+ NFCD_INTERNAL;
+
+guint
+nfc_host_service_process(
+ NfcHostService* service,
+ NfcHost* host,
+ const NfcApdu* apdu,
+ NfcHostServiceResponseFunc resp,
+ void* user_data,
+ GDestroyNotify destroy)
+ NFCD_INTERNAL;
+
+void
+nfc_host_service_cancel(
+ NfcHostService* service,
+ guint id)
+ NFCD_INTERNAL;
+
+#endif /* NFC_HOST_SERVICE_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_initiator.c
^
|
@@ -10,23 +10,27 @@
*
* 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -57,11 +61,13 @@
G_DEFINE_ABSTRACT_TYPE(NfcInitiator, nfc_initiator, PARENT_TYPE)
enum nfc_initiator_signal {
+ SIGNAL_REACTIVATED,
SIGNAL_TRANSMISSION,
SIGNAL_GONE,
SIGNAL_COUNT
};
+#define SIGNAL_REACTIVATED_NAME "nfc-initiator-reactivated"
#define SIGNAL_TRANSMISSION_NAME "nfc-initiator-transmission"
#define SIGNAL_GONE_NAME "nfc-initiator-gone"
@@ -305,6 +311,16 @@
SIGNAL_GONE_NAME, G_CALLBACK(func), user_data) : 0;
}
+gulong
+nfc_initiator_add_reactivated_handler(
+ NfcInitiator* self,
+ NfcInitiatorFunc func,
+ void* user_data)
+{
+ return (G_LIKELY(self) && G_LIKELY(func)) ? g_signal_connect(self,
+ SIGNAL_REACTIVATED_NAME, G_CALLBACK(func), user_data) : 0;
+}
+
void
nfc_initiator_remove_handler(
NfcInitiator* self,
@@ -457,6 +473,17 @@
}
}
+void
+nfc_initiator_reactivated(
+ NfcInitiator* self) /* Since 1.2.0 */
+{
+ if (G_LIKELY(self) && self->present) {
+ nfc_initiator_ref(self);
+ g_signal_emit(self, nfc_initiator_signals[SIGNAL_REACTIVATED], 0);
+ nfc_initiator_unref(self);
+ }
+}
+
/*==========================================================================*
* Methods
*==========================================================================*/
@@ -541,6 +568,9 @@
klass->deactivate = nfc_initiator_nop;
klass->gone = nfc_initiator_default_gone;
G_OBJECT_CLASS(klass)->finalize = nfc_initiator_finalize;
+ nfc_initiator_signals[SIGNAL_REACTIVATED] =
+ g_signal_new(SIGNAL_REACTIVATED_NAME, type, G_SIGNAL_RUN_FIRST, 0,
+ NULL, NULL, NULL, G_TYPE_NONE, 0);
nfc_initiator_signals[SIGNAL_TRANSMISSION] =
g_signal_new(SIGNAL_TRANSMISSION_NAME, type, G_SIGNAL_RUN_LAST, 0,
g_signal_accumulator_true_handled, NULL, NULL,
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_initiator_p.h
^
|
@@ -2,32 +2,39 @@
* Copyright (C) 2020-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2020 Jolla Ltd.
*
- * You may use this file under the terms of BSD license as follows:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_INITIATOR_PRIVATE_H
@@ -77,6 +84,13 @@
NfcInitiator* initiator,
NfcInitiatorFunc func,
void* user_data)
+ NFCD_INTERNAL;
+
+gulong
+nfc_initiator_add_reactivated_handler(
+ NfcInitiator* initiator,
+ NfcInitiatorFunc func,
+ void* user_data)
NFCD_INTERNAL;
void
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_manager.c
^
|
@@ -2,37 +2,46 @@
* Copyright (C) 2018-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2018-2021 Jolla Ltd.
*
- * You may use this file under the terms of BSD license as follows:
+ * You may use this file under the terms of the 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.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
*
- * 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "nfc_manager_p.h"
#include "internal/nfc_manager_i.h"
#include "nfc_adapter_p.h"
+#include "nfc_host_app.h"
+#include "nfc_host_service.h"
#include "nfc_peer_service.h"
#include "nfc_peer_services.h"
#include "nfc_plugins.h"
@@ -40,6 +49,8 @@
#include <gutil_misc.h>
#include <gutil_macros.h>
+#include <gutil_objv.h>
+#include <gutil_weakref.h>
#include <stdlib.h>
@@ -48,21 +59,31 @@
#define NFC_ADAPTER_NAME_FORMAT "nfc%u"
struct nfc_mode_request {
- NfcModeRequest* next;
NfcManager* manager;
NFC_MODE enable;
NFC_MODE disable;
};
+struct nfc_tech_request {
+ NfcManager* manager;
+ NFC_TECHNOLOGY enable;
+ NFC_TECHNOLOGY disable;
+};
+
struct nfc_manager_priv {
+ GUtilWeakRef* ref;
NfcPlugins* plugins;
- NfcPeerServices* services;
+ NfcPeerServices* peer_services;
+ NfcHostService** host_services;
+ NfcHostApp** host_apps;
NfcModeRequest* p2p_request;
+ NfcModeRequest* host_request;
GHashTable* adapters;
guint next_adapter_index;
gboolean requested_power;
NFC_MODE default_mode;
- NfcModeRequest* mode_requests;
+ GQueue mode_requests;
+ GQueue tech_requests;
};
#define THIS(obj) NFC_MANAGER(obj)
@@ -80,6 +101,7 @@
SIGNAL_SERVICE_UNREGISTERED,
SIGNAL_ENABLED_CHANGED,
SIGNAL_MODE_CHANGED,
+ SIGNAL_TECHS_CHANGED,
SIGNAL_STOPPED,
SIGNAL_COUNT
};
@@ -90,10 +112,18 @@
#define SIGNAL_SERVICE_UNREGISTERED_NAME "nfc-manager-service-unregistered"
#define SIGNAL_ENABLED_CHANGED_NAME "nfc-manager-enabled-changed"
#define SIGNAL_MODE_CHANGED_NAME "nfc-manager-mode-changed"
+#define SIGNAL_TECHS_CHANGED_NAME "nfc-manager-techs-changed"
#define SIGNAL_STOPPED_NAME "nfc-manager-stopped"
static guint nfc_manager_signals[SIGNAL_COUNT] = { 0 };
+#define NEW_SIGNAL(name,type) nfc_manager_signals[SIGNAL_##name] = \
+ g_signal_new(SIGNAL_##name##_NAME, type, G_SIGNAL_RUN_FIRST, \
+ 0, NULL, NULL, NULL, G_TYPE_NONE, 0)
+#define NEW_OBJECT_SIGNAL(name,type) nfc_manager_signals[SIGNAL_##name] = \
+ g_signal_new(SIGNAL_##name##_NAME, type, G_SIGNAL_RUN_FIRST, \
+ 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_OBJECT)
+
/*==========================================================================*
* Implementation
*==========================================================================*/
@@ -167,35 +197,53 @@
static
void
-nfc_manager_update_adapter_modes(
- NfcManager* self)
+nfc_manager_foreach_adapter(
+ NfcManager* self,
+ void (*fn)(NfcManager*, NfcAdapter*))
{
NfcAdapter** adapters = nfc_manager_ref_adapters(self->priv);
if (adapters) {
- const NFC_MODE mode = self->mode;
NfcAdapter** ptr = adapters;
while (*ptr) {
- nfc_adapter_request_mode(*ptr++, mode);
+ fn(self, *ptr++);
}
nfc_manager_unref_adapters(adapters);
}
}
static
+void
+nfc_manager_update_adapter_mode(
+ NfcManager* manager,
+ NfcAdapter* adapter)
+{
+ nfc_adapter_request_mode(adapter, manager->mode);
+}
+
+static
+void
+nfc_manager_update_mode_cb(
+ gpointer list_data,
+ gpointer user_data)
+{
+ const NfcModeRequest* req = list_data;
+ NfcManager* self = THIS(user_data);
+
+ self->mode = (self->mode & ~req->disable) | req->enable;
+}
+
+static
gboolean
nfc_manager_update_mode(
NfcManager* self)
{
NfcManagerPriv* priv = self->priv;
const NFC_MODE prev_mode = self->mode;
- const NfcModeRequest* req = priv->mode_requests;
self->mode = priv->default_mode;
- for (req = priv->mode_requests; req; req = req->next) {
- self->mode = (self->mode & ~req->disable) | req->enable;
- }
+ g_queue_foreach(&priv->mode_requests, nfc_manager_update_mode_cb, self);
if (self->mode != prev_mode) {
GDEBUG("NFC mode 0x%02x", self->mode);
g_signal_emit(self, nfc_manager_signals[SIGNAL_MODE_CHANGED], 0);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_manager_p.h
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2021-2023 Slava Monich <slava@monich.com>
* 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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_MANAGER_PRIVATE_H
@@ -42,6 +49,21 @@
NfcManager* manager,
NFC_MODE mode); /* It used to be public and stays exported */
+NfcPeerServices*
+nfc_manager_peer_services(
+ NfcManager* manager)
+ NFCD_INTERNAL;
+
+NfcHostService* const*
+nfc_manager_host_services(
+ NfcManager* manager)
+ NFCD_INTERNAL;
+
+NfcHostApp* const*
+nfc_manager_host_apps(
+ NfcManager* manager)
+ NFCD_INTERNAL;
+
#endif /* NFC_MANAGER_PRIVATE_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_tag_t4.c
^
|
@@ -100,123 +100,10 @@
#define NDEF_CC_LEN (15)
#define NDEF_DATA_OFFSET (2)
-/* ISO/IEC 7816-4 */
-
-#define ISO_MF (0x3F00)
-
-#define ISO_CLA (0x00) /* Basic channel */
-
-#define ISO_SHORT_FID_MASK (0x1f) /* Short File ID mask */
-
-/* Instruction byte */
-#define ISO_INS_SELECT (0xA4)
-#define ISO_INS_READ_BINARY (0xB0)
-
-/* Selection by file identifier */
-#define ISO_P1_SELECT_BY_ID (0x00) /* Select MF, DF or EF */
-#define ISO_P1_SELECT_CHILD_DF (0x01) /* Select child DF */
-#define ISO_P1_SELECT_CHILD_EF (0x02) /* Select EF under current DF */
-#define ISO_P1_SELECT_PARENT_DF (0x03) /* Select parent DF of current DF */
-/* Selection by DF name */
-#define ISO_P1_SELECT_DF_BY_NAME (0x04) /* Select by DF name */
-/* Selection by path */
-#define ISO_P1_SELECT_ABS_PATH (0x08) /* Select from the MF */
-#define ISO_P1_SELECT_REL_PATH (0x09) /* Select from the current DF */
-
-/* File occurrence */
-#define ISO_P2_SELECT_FILE_FIRST (0x00) /* First or only occurrence */
-#define ISO_P2_SELECT_FILE_LAST (0x01) /* Last occurrence */
-#define ISO_P2_SELECT_FILE_NEXT (0x02) /* Next occurrence */
-#define ISO_P2_SELECT_FILE_PREV (0x03) /* Previous occurrence */
-/* File control information */
-#define ISO_P2_RESPONSE_FCI (0x00) /* Return FCI template */
-#define ISO_P2_RESPONSE_FCP (0x04) /* Return FCP template */
-#define ISO_P2_RESPONSE_FMD (0x08) /* Return FMD template */
-#define ISO_P2_RESPONSE_NONE (0x0C) /* No response data */
-
/*==========================================================================*
* Implementation
*==========================================================================*/
-gboolean
-nfc_tag_t4_build_apdu(
- GByteArray* buf,
- guint8 cla, /* Class byte */
- guint8 ins, /* Instruction byte */
- guint8 p1, /* Parameter byte 1 */
- guint8 p2, /* Parameter byte 2 */
- guint len, /* Command data length */
- const void* data, /* Command data */
- guint exp) /* Expected length */
-{
- /*
- * Command APDU encoding options (ISO/IEC 7816-4):
- *
- * Case 1: |CLA|INS|P1|P2| n = 4
- * Case 2s: |CLA|INS|P1|P2|LE| n = 5
- * Case 3s: |CLA|INS|P1|P2|LC|...BODY...| n = 6..260
- * Case 4s: |CLA|INS|P1|P2|LC|...BODY...|LE | n = 7..261
- * Case 2e: |CLA|INS|P1|P2|00|LE1|LE2| n = 7
- * Case 3e: |CLA|INS|P1|P2|00|LC1|LC2|...BODY...| n = 8..65542
- * Case 4e: |CLA|INS|P1|P2|00|LC1|LC2|...BODY...|LE1|LE2| n = 10..65544
- *
- * LE, LE1, LE2 may be 0x00, 0x00|0x00 (means the maximum, 256 or 65536)
- * LC must not be 0x00 and LC1|LC2 must not be 0x00|0x00
- */
- if (len <= 0xffff && exp <= 0x10000) {
- g_byte_array_set_size(buf, 4);
- buf->data[0] = cla;
- buf->data[1] = ins;
- buf->data[2] = p1;
- buf->data[3] = p2;
- if (len > 0) {
- if (len <= 0xff) {
- /* Cases 3s and 4s */
- guint8 lc = (guint8)len;
-
- g_byte_array_append(buf, &lc, 1);
- } else {
- /* Cases 3e and 4e */
- guint8 lc[3];
-
- lc[0] = 0;
- lc[1] = (guint8)(len >> 8);
- lc[2] = (guint8)len;
- g_byte_array_append(buf, lc, sizeof(lc));
- }
- g_byte_array_append(buf, data, len);
- }
- if (exp > 0) {
- if (exp <= 0x100 && len <= 0xff) {
- /* Cases 2s and 4s */
- guint8 le = (exp == 0x100) ? 0 : ((guint8)exp);
-
- g_byte_array_append(buf, &le, 1);
- } else {
- /* Cases 4e and 2e */
- guint8 le[2];
-
- if (exp == 0x10000) {
- le[0] = le[1] = 0;
- } else {
- le[0] = (guint8)(exp >> 8);
- le[1] = (guint8)exp;
- }
- if (!len) {
- /* Case 2e */
- g_byte_array_set_size(buf, 5);
- buf->data[4] = 0;
- }
- g_byte_array_append(buf, le, sizeof(le));
- }
- }
- return TRUE;
- } else {
- g_byte_array_set_size(buf, 0);
- return FALSE;
- }
-}
-
static
void
nfc_tag_t4_tx_free(
@@ -285,18 +172,20 @@
{
NfcTagType4Priv* priv = self->priv;
GByteArray* buf = priv->buf;
- const void* bytes;
- guint len;
+ NfcApdu apdu;
+ apdu.cla = cla;
+ apdu.ins = ins;
+ apdu.p1 = p1;
+ apdu.p2 = p2;
+ apdu.le = le;
if (data) {
- bytes = data->bytes;
- len = data->size;
+ apdu.data = *data;
} else {
- bytes = NULL;
- len = 0;
+ memset(&apdu.data, 0, sizeof(apdu.data));
}
- if (nfc_tag_t4_build_apdu(buf, cla, ins, p1, p2, len, bytes, le)) {
+ if (nfc_apdu_encode(buf, &apdu)) {
NfcTag* tag = &self->tag;
NfcIsoDepTx* tx = g_slice_new0(NfcIsoDepTx);
guint id;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_tag_t4_p.h
^
|
@@ -1,34 +1,41 @@
/*
+ * Copyright (C) 2019-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_TAG_T4_PRIVATE_H
@@ -64,19 +71,6 @@
const NfcParamIsoDep* iso_dep)
NFCD_INTERNAL;
-/* For unit tests */
-gboolean
-nfc_tag_t4_build_apdu(
- GByteArray* buf,
- guint8 cla, /* Class byte */
- guint8 ins, /* Instruction byte */
- guint8 p1, /* Parameter byte 1 */
- guint8 p2, /* Parameter byte 2 */
- guint len, /* Command data length */
- const void* data, /* Command data */
- guint exp) /* Expected length */
- NFCD_INTERNAL;
-
#endif /* NFC_TAG_T4_PRIVATE_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_types_p.h
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_TYPES_PRIVATE_H
@@ -63,6 +70,42 @@
/* Macros */
#define NFCD_INTERNAL G_GNUC_INTERNAL
+/* ISO/IEC 7816-4 */
+
+#define ISO_MF (0x3F00)
+
+#define ISO_CLA (0x00) /* Basic channel */
+
+#define ISO_SHORT_FID_MASK (0x1f) /* Short File ID mask */
+
+/* Instruction byte */
+#define ISO_INS_SELECT (0xA4)
+#define ISO_INS_READ_BINARY (0xB0)
+
+/* Selection by file identifier */
+#define ISO_P1_SELECT_BY_ID (0x00) /* Select MF, DF or EF */
+#define ISO_P1_SELECT_CHILD_DF (0x01) /* Select child DF */
+#define ISO_P1_SELECT_CHILD_EF (0x02) /* Select EF under current DF */
+#define ISO_P1_SELECT_PARENT_DF (0x03) /* Select parent DF of current DF */
+/* Selection by DF name */
+#define ISO_P1_SELECT_DF_BY_NAME (0x04) /* Select by DF name */
+/* Selection by path */
+#define ISO_P1_SELECT_ABS_PATH (0x08) /* Select from the MF */
+#define ISO_P1_SELECT_REL_PATH (0x09) /* Select from the current DF */
+
+/* File occurrence */
+#define ISO_P2_SELECT_FILE_FIRST (0x00) /* First or only occurrence */
+#define ISO_P2_SELECT_FILE_LAST (0x01) /* Last occurrence */
+#define ISO_P2_SELECT_FILE_NEXT (0x02) /* Next occurrence */
+#define ISO_P2_SELECT_FILE_PREV (0x03) /* Previous occurrence */
+#define ISO_P2_SELECT_FILE_MASK (0x03) /* Mask of the above */
+/* File control information */
+#define ISO_P2_RESPONSE_FCI (0x00) /* Return FCI template */
+#define ISO_P2_RESPONSE_FCP (0x04) /* Return FCP template */
+#define ISO_P2_RESPONSE_FMD (0x08) /* Return FMD template */
+#define ISO_P2_RESPONSE_NONE (0x0C) /* No response data */
+#define ISO_P2_RESPONSE_MASK (0x0C) /* Mask of the above */
+
/* Internal log module */
extern GLogModule nfc_dump_log NFCD_INTERNAL;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_util.c
^
|
@@ -86,6 +86,180 @@
}
/*
+ * Command APDU encoding options (ISO/IEC 7816-4):
+ *
+ * Case 1: |CLA|INS|P1|P2| n = 4
+ * Case 2s: |CLA|INS|P1|P2|LE| n = 5
+ * Case 3s: |CLA|INS|P1|P2|LC|...BODY...| n = 6..260
+ * Case 4s: |CLA|INS|P1|P2|LC|...BODY...|LE| n = 7..261
+ * Case 2e: |CLA|INS|P1|P2|00|LE1|LE2| n = 7
+ * Case 3e: |CLA|INS|P1|P2|00|LC1|LC2|...BODY...| n = 8..65542
+ * Case 4e: |CLA|INS|P1|P2|00|LC1|LC2|...BODY...|LE1|LE2| n = 10..65544
+ *
+ * LE, LE1, LE2 may be 0x00, 0x00|0x00 (means the maximum, 256 or 65536)
+ * LC must not be 0x00 and LC1|LC2 must not be 0x00|0x00
+ */
+
+gboolean
+nfc_apdu_encode(
+ GByteArray* buf,
+ const NfcApdu* apdu)
+{
+ const GUtilData* data = &apdu->data;
+
+ if (data->size <= 0xffff && apdu->le <= 0x10000) {
+ g_byte_array_set_size(buf, 4);
+ buf->data[0] = apdu->cla;
+ buf->data[1] = apdu->ins;
+ buf->data[2] = apdu->p1;
+ buf->data[3] = apdu->p2;
+ if (data->size > 0) {
+ if (data->size <= 0xff) {
+ /* Cases 3s and 4s */
+ guint8 lc = (guint8) data->size;
+
+ g_byte_array_append(buf, &lc, 1);
+ } else {
+ /* Cases 3e and 4e */
+ guint8 lc[3];
+
+ lc[0] = 0;
+ lc[1] = (guint8) (data->size >> 8);
+ lc[2] = (guint8) data->size;
+ g_byte_array_append(buf, lc, sizeof(lc));
+ }
+ g_byte_array_append(buf, data->bytes, (guint) data->size);
+ }
+ if (apdu->le > 0) {
+ if (apdu->le <= 0x100 && data->size <= 0xff) {
+ /* Cases 2s and 4s */
+ guint8 le = (apdu->le == 0x100) ? 0 : ((guint8) apdu->le);
+
+ g_byte_array_append(buf, &le, 1);
+ } else {
+ /* Cases 4e and 2e */
+ guint8 le[2];
+
+ if (apdu->le == 0x10000) {
+ le[0] = le[1] = 0;
+ } else {
+ le[0] = (guint8) (apdu->le >> 8);
+ le[1] = (guint8) apdu->le;
+ }
+ if (!data->size) {
+ /* Case 2e */
+ g_byte_array_set_size(buf, 5);
+ buf->data[4] = 0;
+ }
+ g_byte_array_append(buf, le, sizeof(le));
+ }
+ }
+ return TRUE;
+ } else {
+ g_byte_array_set_size(buf, 0);
+ return FALSE;
+ }
+}
+
+gboolean
+nfc_apdu_decode(
+ NfcApdu* apdu,
+ const GUtilData* data)
+{
+ if (data->size < 4) {
+ /* Not enough data */
+ return FALSE;
+ } else if (data->size == 4) {
+ /* Case 1: |CLA|INS|P1|P2| */
+ apdu->cla = data->bytes[0];
+ apdu->ins = data->bytes[1];
+ apdu->p1 = data->bytes[2];
+ apdu->p2 = data->bytes[3];
+ memset(&apdu->data, 0, sizeof(apdu->data));
+ apdu->le = 0;
+ return TRUE;
+ } else if (data->size == 5) {
+ const guint le = data->bytes[4];
+
+ /* Case 2s: |CLA|INS|P1|P2|LE| */
+ apdu->cla = data->bytes[0];
+ apdu->ins = data->bytes[1];
+ apdu->p1 = data->bytes[2];
+ apdu->p2 = data->bytes[3];
+ apdu->le = le ? le : 0x100;
+ memset(&apdu->data, 0, sizeof(apdu->data));
+ return TRUE;
+ } else if (data->bytes[4] == 0) {
+ if (data->size == 7) {
+ const guint le1 = data->bytes[5];
+ const guint le2 = data->bytes[6];
+
+ /* Case 2e: |CLA|INS|P1|P2|00|LE1|LE2| */
+ apdu->cla = data->bytes[0];
+ apdu->ins = data->bytes[1];
+ apdu->p1 = data->bytes[2];
+ apdu->p2 = data->bytes[3];
+ apdu->le = (le1 || le2) ? ((le1 << 8) | le2) : 0x10000;
+ memset(&apdu->data, 0, sizeof(apdu->data));
+ return TRUE;
+ } else if (data->size <= 65544) {
+ const guint lc = ((guint) data->bytes[5] << 8) | data->bytes[6];
+
+ if (data->size == lc + 7) {
+ /* Case 3e: |CLA|INS|P1|P2|00|LC1|LC2|...BODY...| */
+ apdu->le = 0;
+ } else if (data->size == lc + 9) {
+ const guint le1 = data->bytes[data->size - 2];
+ const guint le2 = data->bytes[data->size - 1];
+
+ /* Case 4e: |CLA|INS|P1|P2|00|LC1|LC2|...BODY...|LE1|LE2| */
+ apdu->le = (le1 || le2) ? ((le1 << 8) | le2) : 0x10000;
+ } else {
+ /* Broken APDU */
+ return FALSE;
+ }
+
+ apdu->cla = data->bytes[0];
+ apdu->ins = data->bytes[1];
+ apdu->p1 = data->bytes[2];
+ apdu->p2 = data->bytes[3];
+ apdu->data.bytes = data->bytes + 7;
+ apdu->data.size = lc;
+ return TRUE;
+ } else {
+ /* Too much data */
+ return FALSE;
+ }
+ } else if (data->size <= 261) {
+ const guint lc = data->bytes[4];
+
+ if (data->size == lc + 5) {
+ /* Case 3s: |CLA|INS|P1|P2|LC|...BODY...| */
+ apdu->le = 0;
+ } else if (data->size == lc + 6) {
+ const guint le = data->bytes[data->size - 1];
+
+ /* Case 4s: |CLA|INS|P1|P2|LC|...BODY...|LE| */
+ apdu->le = le ? le : 0x100;
+ } else {
+ /* Broken APDU */
+ return FALSE;
+ }
+
+ apdu->cla = data->bytes[0];
+ apdu->ins = data->bytes[1];
+ apdu->p1 = data->bytes[2];
+ apdu->p2 = data->bytes[3];
+ apdu->data.bytes = data->bytes + 5;
+ apdu->data.size = lc;
+ return TRUE;
+ } else {
+ /* Broken APDU */
+ return FALSE;
+ }
+}
+
+/*
* Local Variables:
* mode: C
* c-basic-offset: 4
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/core/src/nfc_util.h
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef NFC_UTIL_H
@@ -51,6 +58,18 @@
void)
NFCD_INTERNAL;
+gboolean
+nfc_apdu_encode(
+ GByteArray* buf,
+ const NfcApdu* apdu)
+ NFCD_INTERNAL;
+
+gboolean
+nfc_apdu_decode(
+ NfcApdu* apdu,
+ const GUtilData* data)
+ NFCD_INTERNAL;
+
#endif /* NFC_UTIL_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/Makefile
^
|
@@ -51,8 +51,11 @@
DBUS_SERVICE_PLUGIN_SRC = \
dbus_service_adapter.c \
dbus_service_error.c \
+ dbus_service_host.c \
dbus_service_isodep.c \
dbus_service_local.c \
+ dbus_service_local_host.c \
+ dbus_service_local_app.c \
dbus_service_ndef.c \
dbus_service_peer.c \
dbus_service_plugin.c \
@@ -63,8 +66,11 @@
DBUS_SERVICE_GEN_SRC = \
org.sailfishos.nfc.Adapter.c \
org.sailfishos.nfc.Daemon.c \
+ org.sailfishos.nfc.Host.c \
org.sailfishos.nfc.IsoDep.c \
org.sailfishos.nfc.LocalService.c \
+ org.sailfishos.nfc.LocalHostService.c \
+ org.sailfishos.nfc.LocalHostApp.c \
org.sailfishos.nfc.NDEF.c \
org.sailfishos.nfc.Peer.c \
org.sailfishos.nfc.Tag.c \
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/dbus_service.h
^
|
@@ -46,6 +46,8 @@
#include <gutil_log.h>
#include <nfc_peer_service.h>
+#include <nfc_host_service.h>
+#include <nfc_host_app.h>
#include <nfcdef.h>
@@ -58,6 +60,7 @@
typedef struct dbus_service_tag_t2 DBusServiceTagType2;
typedef struct dbus_service_isodep DBusServiceIsoDep;
typedef struct dbus_service_peer DBusServicePeer;
+typedef struct dbus_service_host DBusServiceHost;
#define DBUS_SERVICE_ERROR (dbus_service_error_quark())
GQuark dbus_service_error_quark(void);
@@ -85,6 +88,11 @@
DBusServicePlugin* plugin,
NfcPeer* peer);
+DBusServiceHost*
+dbus_service_plugin_find_host(
+ DBusServicePlugin* plugin,
+ NfcHost* host);
+
/* org.sailfishos.nfc.LocalService */
typedef struct dbus_service_local {
@@ -101,6 +109,40 @@
const char* llc_name,
const char* dbus_name);
+/* org.sailfishos.nfc.LocalHostService */
+
+typedef struct dbus_service_local_host {
+ NfcHostService service;
+ DBusServicePlugin* plugin;
+ const char* dbus_name;
+ const char* obj_path;
+} DBusServiceLocalHost;
+
+DBusServiceLocalHost*
+dbus_service_local_host_new(
+ GDBusConnection* connection,
+ const char* obj_path,
+ const char* name,
+ const char* dbus_name);
+
+/* org.sailfishos.nfc.LocalHostApp */
+
+typedef struct dbus_service_local_app {
+ NfcHostApp app;
+ DBusServicePlugin* plugin;
+ const char* dbus_name;
+ const char* obj_path;
+} DBusServiceLocalApp;
+
+DBusServiceLocalApp*
+dbus_service_local_app_new(
+ GDBusConnection* connection,
+ const char* obj_path,
+ const char* name,
+ const GUtilData* aid,
+ NFC_HOST_APP_FLAGS flags,
+ const char* dbus_name);
+
/* org.sailfishos.nfc.Adapter */
DBusServiceAdapter*
@@ -117,6 +159,11 @@
DBusServiceAdapter* self,
NfcPeer* peer);
+DBusServiceHost*
+dbus_service_adapter_find_host(
+ DBusServiceAdapter* self,
+ NfcHost* host);
+
void
dbus_service_adapter_free(
DBusServiceAdapter* adapter);
@@ -200,6 +247,24 @@
dbus_service_peer_free(
DBusServicePeer* peer);
+/* org.sailfishos.nfc.Host */
+
+struct dbus_service_host {
+ GDBusConnection* connection;
+ const char* path;
+ NfcHost* host;
+};
+
+DBusServiceHost*
+dbus_service_host_new(
+ NfcHost* host,
+ const char* parent_path,
+ GDBusConnection* connection);
+
+void
+dbus_service_host_free(
+ DBusServiceHost* host);
+
#endif /* DBUS_SERVICE_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/dbus_service_adapter.c
^
|
@@ -2,38 +2,46 @@
* Copyright (C) 2018-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2018-2020 Jolla Ltd.
*
- * You may use this file under the terms of BSD license as follows:
+ * You may use this file under the terms of the 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.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
*
- * 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "dbus_service.h"
#include "dbus_service/org.sailfishos.nfc.Adapter.h"
#include <nfc_adapter.h>
+#include <nfc_host.h>
#include <nfc_peer.h>
#include <nfc_tag.h>
@@ -42,6 +50,22 @@
#include <stdlib.h>
+/* x(DBUS_CALL,dbus_call,dbus-call) */
+#define DBUS_CALLS(x) \
+ x(GET_ALL, get_all, get-all) \
+ x(GET_INTERFACE_VERSION, get_interface_version, get-interface-version) \
+ x(GET_ENABLED, get_enabled, get-enabled) \
+ x(GET_POWERED, get_powered, get-powered) \
+ x(GET_SUPPORTED_MODES, get_supported_modes, get-supported-modes) \
+ x(GET_MODE, get_mode, get-mode) \
+ x(GET_TARGET_PRESENT, get_target_present, get-target-present) \
+ x(GET_TAGS, get_tags, get-tags) \
+ x(GET_ALL2, get_all2, get-all2) \
+ x(GET_PEERS, get_peers, get-peers) \
+ x(GET_ALL3, get_all3, get-all3) \
+ x(GET_HOSTS, get_hosts, get-hosts) \
+ x(GET_SUPPORTED_TECHS, get_supported_techs, get-supported-techs)
+
enum {
EVENT_ENABLED_CHANGED,
EVENT_POWERED_CHANGED,
@@ -51,20 +75,15 @@
EVENT_TAG_REMOVED,
EVENT_PEER_ADDED,
EVENT_PEER_REMOVED,
+ EVENT_HOST_ADDED,
+ EVENT_HOST_REMOVED,
EVENT_COUNT
};
enum {
- CALL_GET_ALL,
- CALL_GET_INTERFACE_VERSION,
- CALL_GET_ENABLED,
- CALL_GET_POWERED,
- CALL_GET_SUPPORTED_MODES,
- CALL_GET_MODE,
- CALL_GET_TARGET_PRESENT,
- CALL_GET_TAGS,
- CALL_GET_ALL2,
- CALL_GET_PEERS,
+ #define DEFINE_ENUM(CALL,call,name) CALL_##CALL,
+ DBUS_CALLS(DEFINE_ENUM)
+ #undef DEFINE_ENUM
CALL_COUNT
};
@@ -75,12 +94,13 @@
GUtilIdlePool* pool;
GHashTable* tags;
GHashTable* peers;
+ GHashTable* hosts;
NfcAdapter* adapter;
gulong event_id[EVENT_COUNT];
gulong call_id[CALL_COUNT];
};
-#define NFC_DBUS_ADAPTER_INTERFACE_VERSION (2)
+#define NFC_DBUS_ADAPTER_INTERFACE_VERSION (3)
static
int
@@ -97,8 +117,8 @@
DBusServiceAdapter* self,
NfcTag* tag)
{
- DBusServiceTag* dbus =
- dbus_service_tag_new(tag, self->path, self->connection);
+ DBusServiceTag* dbus = dbus_service_tag_new(tag, self->path,
+ self->connection);
if (dbus) {
g_hash_table_replace(self->tags, g_strdup(tag->name), dbus);
@@ -114,8 +134,8 @@
DBusServiceAdapter* self,
NfcPeer* peer)
{
- DBusServicePeer* dbus =
- dbus_service_peer_new(peer, self->path, self->connection);
+ DBusServicePeer* dbus = dbus_service_peer_new(peer, self->path,
+ self->connection);
if (dbus) {
g_hash_table_replace(self->peers, g_strdup(peer->name), dbus);
@@ -126,63 +146,77 @@
}
static
-void
-dbus_service_adapter_free_tag(
- void* tag)
+gboolean
+dbus_service_adapter_create_host(
+ DBusServiceAdapter* self,
+ NfcHost* host)
+{
+ DBusServiceHost* dbus = dbus_service_host_new(host, self->path,
+ self->connection);
+
+ if (dbus) {
+ g_hash_table_replace(self->hosts, g_strdup(host->name), dbus);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+static
+const char*
+dbus_service_adapter_get_tag_name(
+ gpointer value)
{
- dbus_service_tag_free((DBusServiceTag*)tag);
+ return ((DBusServiceTag*)value)->path;
}
static
-void
-dbus_service_adapter_free_peer(
- void* peer)
+const char*
+dbus_service_adapter_get_peer_name(
+ gpointer value)
{
- dbus_service_peer_free((DBusServicePeer*)peer);
+ return ((DBusServicePeer*)value)->path;
+}
+
+static
+const char*
+dbus_service_adapter_get_host_name(
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/dbus_service_host.c
^
|
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "dbus_service.h"
+#include "dbus_service/org.sailfishos.nfc.Host.h"
+
+#include <nfc_host.h>
+#include <nfc_initiator.h>
+
+#include <gutil_macros.h>
+#include <gutil_misc.h>
+
+enum {
+ CALL_GET_ALL,
+ CALL_GET_INTERFACE_VERSION,
+ CALL_GET_PRESENT,
+ CALL_GET_TECHNOLOGY,
+ CALL_GET_INTERFACES,
+ CALL_DEACTIVATE,
+ CALL_COUNT
+};
+
+typedef struct dbus_service_host_priv {
+ DBusServiceHost pub;
+ char* path;
+ OrgSailfishosNfcHost* iface;
+ gulong call_id[CALL_COUNT];
+ gulong host_gone_id;
+} DBusServiceHostPriv;
+
+#define NFC_DBUS_HOST_INTERFACE "org.sailfishos.nfc.Host"
+#define NFC_DBUS_HOST_INTERFACE_VERSION (1)
+
+static inline DBusServiceHostPriv* dbus_service_host_cast(DBusServiceHost* pub)
+ { return G_LIKELY(pub) ? G_CAST(pub, DBusServiceHostPriv, pub) : NULL; }
+
+/*==========================================================================*
+ * D-Bus calls
+ *==========================================================================*/
+
+/* GetAll */
+
+static
+gboolean
+dbus_service_host_handle_get_all(
+ OrgSailfishosNfcHost* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceHostPriv* self)
+{
+ NfcInitiator* initiator = self->pub.host->initiator;
+
+ org_sailfishos_nfc_host_complete_get_all(self->iface, call,
+ NFC_DBUS_HOST_INTERFACE_VERSION, initiator->present,
+ initiator->technology);
+ return TRUE;
+}
+
+/* GetInterfaceVersion */
+
+static
+gboolean
+dbus_service_host_handle_get_interface_version(
+ OrgSailfishosNfcHost* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceHostPriv* self)
+{
+ org_sailfishos_nfc_host_complete_get_interface_version(iface, call,
+ NFC_DBUS_HOST_INTERFACE_VERSION);
+ return TRUE;
+}
+
+/* GetPresent */
+
+static
+gboolean
+dbus_service_host_handle_get_present(
+ OrgSailfishosNfcHost* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceHostPriv* self)
+{
+ org_sailfishos_nfc_host_complete_get_present(iface, call,
+ self->pub.host->initiator->present);
+ return TRUE;
+}
+
+/* GetTechnology */
+
+static
+gboolean
+dbus_service_host_handle_get_technology(
+ OrgSailfishosNfcHost* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceHostPriv* self)
+{
+ org_sailfishos_nfc_host_complete_get_technology(iface, call,
+ self->pub.host->initiator->technology);
+ return TRUE;
+}
+
+/* Deactivate */
+
+static
+gboolean
+dbus_service_host_handle_deactivate(
+ OrgSailfishosNfcHost* iface,
+ GDBusMethodInvocation* call,
+ DBusServiceHostPriv* self)
+{
+ nfc_host_deactivate(self->pub.host);
+ org_sailfishos_nfc_host_complete_deactivate(iface, call);
+ return TRUE;
+}
+
+/*==========================================================================*
+ * Interface
+ *==========================================================================*/
+
+static
+void
+dbus_service_host_free_unexported(
+ DBusServiceHostPriv* self)
+{
+ DBusServiceHost* pub = &self->pub;
+
+ gutil_disconnect_handlers(self->iface, self->call_id, CALL_COUNT);
+ nfc_host_remove_handler(pub->host, self->host_gone_id);
+ nfc_host_unref(pub->host);
+ g_object_unref(pub->connection);
+ g_object_unref(self->iface);
+ g_free(self->path);
+ g_free(self);
+}
+
+DBusServiceHost*
+dbus_service_host_new(
+ NfcHost* host,
+ const char* parent_path,
+ GDBusConnection* connection)
+{
+ DBusServiceHostPriv* self = g_new0(DBusServiceHostPriv, 1);
+ DBusServiceHost* pub = &self->pub;
+ GError* error = NULL;
+
+ g_object_ref(pub->connection = connection);
+ pub->path = self->path = g_strconcat(parent_path, "/", host->name, NULL);
+ pub->host = nfc_host_ref(host);
+ self->iface = org_sailfishos_nfc_host_skeleton_new();
+
+ /* D-Bus calls */
+ self->call_id[CALL_GET_ALL] =
+ g_signal_connect(self->iface, "handle-get-all",
+ G_CALLBACK(dbus_service_host_handle_get_all), self);
+ self->call_id[CALL_GET_INTERFACE_VERSION] =
+ g_signal_connect(self->iface, "handle-get-interface-version",
+ G_CALLBACK(dbus_service_host_handle_get_interface_version), self);
+ self->call_id[CALL_GET_PRESENT] =
+ g_signal_connect(self->iface, "handle-get-present",
+ G_CALLBACK(dbus_service_host_handle_get_present), self);
+ self->call_id[CALL_GET_TECHNOLOGY] =
+ g_signal_connect(self->iface, "handle-get-technology",
+ G_CALLBACK(dbus_service_host_handle_get_technology), self);
+ self->call_id[CALL_DEACTIVATE] =
+ g_signal_connect(self->iface, "handle-deactivate",
+ G_CALLBACK(dbus_service_host_handle_deactivate), self);
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/dbus_service_local_app.c
^
|
@@ -0,0 +1,683 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "dbus_service.h"
+#include "dbus_service_util.h"
+#include "dbus_service/org.sailfishos.nfc.LocalHostApp.h"
+
+#include <nfc_host.h>
+#include <nfc_host_app_impl.h>
+
+#include <gutil_macros.h>
+#include <gutil_misc.h>
+
+#include <unistd.h>
+
+typedef NfcHostAppClass DBusServiceLocalAppObjectClass;
+typedef struct dbus_service_local_app_object {
+ DBusServiceLocalApp pub;
+ OrgSailfishosNfcLocalHostApp* proxy;
+ GHashTable* calls; /* id => DBusServiceLocalAppObjectCall */
+ guint last_call_id;
+ NfcHost* host;
+ gulong host_gone_id;
+ char* host_path;
+ char* dbus_name;
+ char* obj_path;
+} DBusServiceLocalAppObject;
+
+#define PARENT_TYPE NFC_TYPE_HOST_APP
+#define PARENT_CLASS dbus_service_local_app_object_parent_class
+#define THIS_TYPE dbus_service_local_app_object_get_type()
+#define THIS_CLASS(klass) NFC_HOST_APP_CLASS(klass)
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ DBusServiceLocalAppObject)
+
+G_DEFINE_TYPE(DBusServiceLocalAppObject, dbus_service_local_app_object, \
+ PARENT_TYPE)
+
+#define LOCAL_APP_INTERFACE "org.sailfishos.nfc.LocalHostApp"
+#define STOP_CALL "Stop"
+#define DESELECT_CALL "Deselect"
+#define RESPONSE_STATUS_CALL "ResponseStatus"
+
+typedef struct dbus_service_local_app_object_call {
+ guint id;
+ gint ref_count;
+ DBusServiceLocalAppObject* obj;
+ GCancellable* cancel;
+ GCallback complete;
+ void* user_data;
+ GDestroyNotify destroy;
+} DBusServiceLocalAppObjectCall;
+
+typedef struct dbus_service_local_app_object_response {
+ DBusServiceLocalAppObject* obj;
+ guint response_id;
+} DBusServiceLocalAppObjectReponse;
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+GDBusConnection*
+dbus_service_local_app_connection(
+ DBusServiceLocalAppObject* self)
+{
+ return g_dbus_proxy_get_connection(G_DBUS_PROXY(self->proxy));
+}
+
+static
+void
+dbus_service_local_app_object_notify(
+ DBusServiceLocalAppObject* self,
+ const char* method,
+ GVariant* args)
+{
+ GDBusConnection* connection = dbus_service_local_app_connection(self);
+ GDBusMessage* message = g_dbus_message_new_method_call(self->dbus_name,
+ self->obj_path, LOCAL_APP_INTERFACE, method);
+
+ /* Generated stub doesn't allow setting "no-reply-expected" flag */
+ g_dbus_message_set_flags(message, g_dbus_message_get_flags(message) |
+ G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED);
+ g_dbus_message_set_body(message, args);
+ g_dbus_connection_send_message(connection, message,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
+ g_object_unref(message);
+}
+
+static
+void
+dbus_service_local_app_object_notify_path(
+ DBusServiceLocalAppObject* self,
+ const char* method,
+ const char* path)
+{
+ dbus_service_local_app_object_notify(self, method,
+ g_variant_new("(o)", path));
+}
+
+static
+void
+dbus_service_local_app_object_stop_notify(
+ DBusServiceLocalAppObject* self)
+{
+ if (self->host_path) {
+ dbus_service_local_app_object_notify_path(self, STOP_CALL,
+ self->host_path);
+ g_free(self->host_path);
+ self->host_path = NULL;
+ }
+}
+
+static
+void
+dbus_service_local_app_object_drop_host(
+ DBusServiceLocalAppObject* self)
+{
+ if (self->host) {
+ nfc_host_remove_handler(self->host, self->host_gone_id);
+ nfc_host_unref(self->host);
+ self->host = NULL;
+ self->host_gone_id = 0;
+ }
+}
+
+static
+void
+dbus_service_local_app_object_host_gone(
+ NfcHost* host,
+ void* user_data)
+{
+ DBusServiceLocalAppObject* self = THIS(user_data);
+
+ dbus_service_local_app_object_stop_notify(self);
+ dbus_service_local_app_object_drop_host(self);
+}
+
+static
+DBusServiceLocalAppObjectCall*
+dbus_service_local_app_object_call_ref(
+ DBusServiceLocalAppObjectCall* call)
+{
+ /* The argument is never NULL */
+ g_atomic_int_inc(&call->ref_count);
+ return call;
+}
+
+static
+void
+dbus_service_local_app_object_call_unref(
+ DBusServiceLocalAppObjectCall* call)
+{
+ /* The argument is never NULL */
+ if (g_atomic_int_dec_and_test(&call->ref_count)) {
+ DBusServiceLocalAppObject* self = call->obj;
+
+ if (call->destroy) {
+ call->destroy(call->user_data);
+ }
+ g_object_unref(self);
+ gutil_object_unref(call->cancel);
+ gutil_slice_free(call);
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/dbus_service_local_host.c
^
|
@@ -0,0 +1,588 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "dbus_service.h"
+#include "dbus_service_util.h"
+#include "dbus_service/org.sailfishos.nfc.LocalHostService.h"
+
+#include <nfc_host.h>
+#include <nfc_host_service_impl.h>
+
+#include <gutil_macros.h>
+#include <gutil_misc.h>
+
+typedef NfcHostServiceClass DBusServiceLocalHostObjectClass;
+typedef struct dbus_service_local_host_object {
+ DBusServiceLocalHost pub;
+ OrgSailfishosNfcLocalHostService* proxy;
+ GHashTable* calls; /* id => DBusServiceLocalHostObjectCall */
+ guint last_call_id;
+ NfcHost* host;
+ gulong host_gone_id;
+ char* host_path;
+ char* dbus_name;
+ char* obj_path;
+} DBusServiceLocalHostObject;
+
+#define PARENT_TYPE NFC_TYPE_HOST_SERVICE
+#define PARENT_CLASS dbus_service_local_host_object_parent_class
+#define THIS_TYPE dbus_service_local_host_object_get_type()
+#define THIS_CLASS(klass) NFC_HOST_SERVICE_CLASS(klass)
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ DBusServiceLocalHostObject)
+
+G_DEFINE_TYPE(DBusServiceLocalHostObject, dbus_service_local_host_object, \
+ PARENT_TYPE)
+
+#define LOCAL_HOST_INTERFACE "org.sailfishos.nfc.LocalHostService"
+#define STOP_CALL "Stop"
+#define RESPONSE_STATUS_CALL "ResponseStatus"
+
+typedef struct dbus_service_local_host_object_call {
+ guint id;
+ gint ref_count;
+ DBusServiceLocalHostObject* obj;
+ GCancellable* cancel;
+ GCallback complete;
+ void* user_data;
+ GDestroyNotify destroy;
+} DBusServiceLocalHostObjectCall;
+
+typedef struct dbus_service_local_host_object_response {
+ DBusServiceLocalHostObject* obj;
+ guint response_id;
+} DBusServiceLocalHostObjectReponse;
+
+/*==========================================================================*
+ * Implementation
+ *==========================================================================*/
+
+static
+GDBusConnection*
+dbus_service_local_host_connection(
+ DBusServiceLocalHostObject* self)
+{
+ return g_dbus_proxy_get_connection(G_DBUS_PROXY(self->proxy));
+}
+
+static
+void
+dbus_service_local_host_object_notify(
+ DBusServiceLocalHostObject* self,
+ const char* method,
+ GVariant* args)
+{
+ GDBusConnection* connection = dbus_service_local_host_connection(self);
+ GDBusMessage* message = g_dbus_message_new_method_call(self->dbus_name,
+ self->obj_path, LOCAL_HOST_INTERFACE, method);
+
+ /* Generated stub doesn't allow setting "no-reply-expected" flag */
+ g_dbus_message_set_flags(message, g_dbus_message_get_flags(message) |
+ G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED);
+ g_dbus_message_set_body(message, args);
+ g_dbus_connection_send_message(connection, message,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
+ g_object_unref(message);
+}
+
+static
+void
+dbus_service_local_host_object_notify_path(
+ DBusServiceLocalHostObject* self,
+ const char* method,
+ const char* path)
+{
+ dbus_service_local_host_object_notify(self, method,
+ g_variant_new("(o)", path));
+}
+
+static
+void
+dbus_service_local_host_object_stop_notify(
+ DBusServiceLocalHostObject* self)
+{
+ if (self->host_path) {
+ dbus_service_local_host_object_notify_path(self, STOP_CALL,
+ self->host_path);
+ g_free(self->host_path);
+ self->host_path = NULL;
+ }
+}
+
+static
+void
+dbus_service_local_host_object_drop_host(
+ DBusServiceLocalHostObject* self)
+{
+ if (self->host) {
+ nfc_host_remove_handler(self->host, self->host_gone_id);
+ nfc_host_unref(self->host);
+ self->host = NULL;
+ self->host_gone_id = 0;
+ }
+}
+
+static
+void
+dbus_service_local_host_object_host_gone(
+ NfcHost* host,
+ void* user_data)
+{
+ DBusServiceLocalHostObject* self = THIS(user_data);
+
+ dbus_service_local_host_object_stop_notify(self);
+ dbus_service_local_host_object_drop_host(self);
+}
+
+static
+DBusServiceLocalHostObjectCall*
+dbus_service_local_host_object_call_ref(
+ DBusServiceLocalHostObjectCall* call)
+{
+ /* The argument is never NULL */
+ g_atomic_int_inc(&call->ref_count);
+ return call;
+}
+
+static
+void
+dbus_service_local_host_object_call_unref(
+ DBusServiceLocalHostObjectCall* call)
+{
+ /* The argument is never NULL */
+ if (g_atomic_int_dec_and_test(&call->ref_count)) {
+ DBusServiceLocalHostObject* self = call->obj;
+
+ if (call->destroy) {
+ call->destroy(call->user_data);
+ }
+ g_object_unref(self);
+ gutil_object_unref(call->cancel);
+ gutil_slice_free(call);
+ }
+}
+
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/dbus_service_plugin.c
^
|
@@ -10,23 +10,27 @@
*
* 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -51,25 +55,46 @@
GLOG_MODULE_DEFINE("dbus-service");
+/* x(DBUS_CALL,dbus_call,dbus-call) */
+#define DBUS_CALLS(x) \
+ x(GET_ALL, get_all, get-all) \
+ x(GET_INTERFACE_VERSION, get_interface_version, get-interface-version) \
+ x(GET_ADAPTERS, get_adapters, get-adapters) \
+ x(GET_ALL2, get_all2, get-all2) \
+ x(GET_DAEMON_VERSION, get_daemon_version, get-daemon-version) \
+ x(GET_ALL3, get_all3, get-all3) \
+ x(GET_MODE, get_mode, get-mode) \
+ x(REQUEST_MODE, request_mode, request-mode) \
+ x(RELEASE_MODE, release_mode, release-mode) \
+ x(REGISTER_LOCAL_SERVICE, register_local_service, \
+ register-local-service) \
+ x(UNREGISTER_LOCAL_SERVICE, unregister_local_service, \
+ unregister-local-service) \
+ x(GET_ALL4, get_all4, get-all4) \
+ x(GET_TECHS, get_techs, get-techs) \
+ x(REQUEST_TECHS, request_techs, request-techs) \
+ x(RELEASE_TECHS, release_techs, release-techs) \
+ x(REGISTER_LOCAL_HOST_SERVICE, register_local_host_service, \
+ register-local-host-service) \
+ x(UNREGISTER_LOCAL_HOST_SERVICE, unregister_local_host_service, \
+ unregister-local-host-service) \
+ x(REGISTER_LOCAL_HOST_APP, register_local_host_app, \
+ register-local-host-app) \
+ x(UNREGISTER_LOCAL_HOST_APP, unregister_local_host_app, \
+ unregister-local-host-app)
+
enum {
EVENT_ADAPTER_ADDED,
EVENT_ADAPTER_REMOVED,
EVENT_MODE_CHANGED,
+ EVENT_TECHS_CHANGED,
EVENT_COUNT
};
enum {
- CALL_GET_ALL,
- CALL_GET_INTERFACE_VERSION,
- CALL_GET_ADAPTERS,
- CALL_GET_ALL2,
- CALL_GET_DAEMON_VERSION,
- CALL_GET_ALL3,
- CALL_GET_MODE,
- CALL_REQUEST_MODE,
- CALL_RELEASE_MODE,
- CALL_REGISTER_LOCAL_SERVICE,
- CALL_UNREGISTER_LOCAL_SERVICE,
+ #define DEFINE_ENUM(CALL,call,name) CALL_##CALL,
+ DBUS_CALLS(DEFINE_ENUM)
+ #undef DEFINE_ENUM
CALL_COUNT
};
@@ -78,14 +103,17 @@
guint watch_id;
DBusServicePlugin* plugin;
GHashTable* peer_services; /* objpath => DBusServiceLocal */
+ GHashTable* host_services; /* objpath => DBusServiceLocalHost */
+ GHashTable* host_apps; /* objpath => DBusServiceLocalApp */
GHashTable* mode_requests; /* id => NfcModeRequest */
+ GHashTable* tech_requests; /* id => NfcTechRequest */
} DBusServiceClient;
typedef NfcPluginClass DBusServicePluginClass;
struct dbus_service_plugin {
NfcPlugin parent;
guint own_name_id;
- guint last_mode_request_id;
+ guint last_request_id;
GUtilIdlePool* pool;
GDBusConnection* connection;
GHashTable* adapters;
@@ -107,7 +135,7 @@
#define NFC_SERVICE "org.sailfishos.nfc.daemon"
#define NFC_DAEMON_PATH "/"
-#define NFC_DBUS_PLUGIN_INTERFACE_VERSION (3)
+#define NFC_DBUS_PLUGIN_INTERFACE_VERSION (4)
static
gboolean
@@ -139,11 +167,11 @@
dbus_service_plugin_peer_service_destroy(
gpointer user_data)
{
- DBusServiceLocal* local = user_data;
- DBusServicePlugin* plugin = local->plugin;
- NfcPeerService* service = &local->service;
+ DBusServiceLocal* obj = user_data;
+ DBusServicePlugin* plugin = obj->plugin;
+ NfcPeerService* service = &obj->service;
- local->plugin = NULL;
+ obj->plugin = NULL;
nfc_manager_unregister_service(plugin->manager, service);
nfc_peer_service_disconnect_all(service);
nfc_peer_service_unref(service);
@@ -151,6 +179,34 @@
static
void
+dbus_service_plugin_host_service_destroy(
+ gpointer user_data)
+{
+ DBusServiceLocalHost* obj = user_data;
+ DBusServicePlugin* plugin = obj->plugin;
+ NfcHostService* service = &obj->service;
+
+ obj->plugin = NULL;
+ nfc_manager_unregister_host_service(plugin->manager, service);
+ nfc_host_service_unref(service);
+}
+
+static
+void
+dbus_service_plugin_host_app_destroy(
+ gpointer user_data)
+{
+ DBusServiceLocalApp* obj = user_data;
+ DBusServicePlugin* plugin = obj->plugin;
+ NfcHostApp* app = &obj->app;
+
+ obj->plugin = NULL;
+ nfc_manager_unregister_host_app(plugin->manager, app);
+ nfc_host_app_unref(app);
+}
+
+static
+void
dbus_service_plugin_client_destroy(
void* value)
{
@@ -159,9 +215,18 @@
if (client->peer_services) {
g_hash_table_destroy(client->peer_services);
}
+ if (client->host_services) {
+ g_hash_table_destroy(client->host_services);
+ }
+ if (client->host_apps) {
+ g_hash_table_destroy(client->host_apps);
+ }
if (client->mode_requests) {
g_hash_table_destroy(client->mode_requests);
}
+ if (client->tech_requests) {
+ g_hash_table_destroy(client->tech_requests);
+ }
g_bus_unwatch_name(client->watch_id);
g_free(client->dbus_name);
gutil_slice_free(client);
@@ -258,17 +323,17 @@
static
DBusServiceLocal*
-dbus_service_plugin_register_local_service(
+dbus_service_plugin_register_local_peer_service(
DBusServicePlugin* self,
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/dbus_service_util.c
^
|
@@ -1,38 +1,47 @@
/*
+ * Copyright (C) 2020-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2020 Jolla Ltd.
- * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2020 Open Mobile Platform LLC.
*
- * You may use this file under the terms of BSD license as follows:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "dbus_service_util.h"
+#include <gutil_misc.h>
+
static
void
dbus_service_dict_add_value(
@@ -40,7 +49,9 @@
const char* name,
GVariant* value)
{
- g_variant_builder_add(builder, "{sv}", name, value);
+ if (value) {
+ g_variant_builder_add(builder, "{sv}", name, value);
+ }
}
GVariant*
@@ -54,15 +65,6 @@
NULL, NULL);
}
-GVariant*
-dbus_service_dup_byte_array_data_as_variant(
- const GUtilData* data)
-{
- return data ?
- dbus_service_dup_byte_array_as_variant(data->bytes, data->size) :
- dbus_service_dup_byte_array_as_variant(NULL, 0);
-}
-
void
dbus_service_dict_add_byte(
GVariantBuilder* builder,
@@ -90,7 +92,14 @@
const GUtilData* data)
{
dbus_service_dict_add_value(builder, name,
- dbus_service_dup_byte_array_data_as_variant(data));
+ gutil_data_copy_as_variant(data));
+}
+
+gboolean
+dbus_service_valid_id(
+ guint id)
+{
+ return id != NFCD_ID_FAIL && id != NFCD_ID_SYNC;
}
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/dbus_service_util.h
^
|
@@ -1,50 +1,53 @@
/*
+ * Copyright (C) 2020-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2020 Jolla Ltd.
- * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2020 Open Mobile Platform LLC.
*
- * You may use this file under the terms of BSD license as follows:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef DBUS_SERVICE_UTIL_H
#define DBUS_SERVICE_UTIL_H
-#include <gutil_types.h>
+#include <nfc_types.h>
GVariant*
dbus_service_dup_byte_array_as_variant(
const void* data,
guint size);
-GVariant*
-dbus_service_dup_byte_array_data_as_variant(
- const GUtilData* data);
-
void
dbus_service_dict_add_byte(
GVariantBuilder* builder,
@@ -64,6 +67,10 @@
const char* name,
const GUtilData* data);
+gboolean
+dbus_service_valid_id(
+ guint id);
+
#endif /* DBUS_SERVICE_UTIL_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.Adapter.xml
^
|
@@ -76,5 +76,34 @@
<signal name="PeersChanged">
<arg name="peers" type="ao"/>
</signal>
+ <!-- Interface version 3 (since 1.2.0) -->
+ <method name="GetAll3">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="enabled" type="b" direction="out"/>
+ <arg name="powered" type="b" direction="out"/>
+ <arg name="supported_modes" type="u" direction="out"/>
+ <arg name="mode" type="u" direction="out"/>
+ <arg name="present" type="b" direction="out"/>
+ <arg name="tags" type="ao" direction="out"/>
+ <arg name="peers" type="ao" direction="out"/>
+ <arg name="hosts" type="ao" direction="out"/>
+ <arg name="supported_techs" type="u" direction="out"/>
+ </method>
+ <method name="GetHosts">
+ <arg name="hosts" type="ao" direction="out"/>
+ </method>
+ <signal name="HostsChanged">
+ <arg name="hosts" type="ao"/>
+ </signal>
+ <!--
+ Techs is a bitmask:
+
+ 0x01 - NFC-A
+ 0x02 - NFC-B
+ 0x04 - NFC-F
+ -->
+ <method name="GetSupportedTechs">
+ <arg name="techs" type="u" direction="out"/>
+ </method>
</interface>
</node>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.Daemon.xml
^
|
@@ -65,5 +65,59 @@
<method name="UnregisterLocalService">
<arg name="path" type="o" direction="in"/>
</method>
+ <!-- Interface version 4 (since 1.2.0) -->
+ <method name="GetAll4">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="adapters" type="ao" direction="out"/>
+ <arg name="daemon_version" type="i" direction="out"/>
+ <arg name="mode" type="u" direction="out"/>
+ <arg name="techs" type="u" direction="out"/>
+ </method>
+ <!--
+ Techs is a bitmask:
+
+ 0x01 - NFC-A
+ 0x02 - NFC-B
+ 0x04 - NFC-F
+ -->
+ <method name="GetTechs">
+ <arg name="techs" type="u" direction="out"/>
+ </method>
+ <signal name="TechsChanged">
+ <arg name="techs" type="u"/>
+ </signal>
+ <method name="RequestTechs">
+ <arg name="allow" type="u" direction="in"/>
+ <arg name="disallow" type="u" direction="in"/>
+ <arg name="id" type="u" direction="out"/>
+ </method>
+ <method name="ReleaseTechs">
+ <arg name="id" type="u" direction="in"/>
+ </method>
+ <method name="RegisterLocalHostService">
+ <!-- Registers instance of org.sailfishos.nfc.LocalHostService -->
+ <arg name="path" type="o" direction="in"/>
+ <arg name="name" type="s" direction="in"/>
+ </method>
+ <method name="UnregisterLocalHostService">
+ <arg name="path" type="o" direction="in"/>
+ </method>
+ <method name="RegisterLocalHostApp">
+ <!-- Registers instance of org.sailfishos.nfc.LocalHostApp -->
+ <arg name="path" type="o" direction="in"/>
+ <arg name="name" type="s" direction="in"/>
+ <arg name="aid" type="ay" direction="in">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <!--
+ Flags is a bitmask.
+
+ 0x01 - Allow implicit selection
+ -->
+ <arg name="flags" type="u" direction="in"/>
+ </method>
+ <method name="UnregisterLocalHostApp">
+ <arg name="path" type="o" direction="in"/>
+ </method>
</interface>
</node>
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.Host.xml
^
|
@@ -0,0 +1,30 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.sailfishos.nfc.Host">
+ <!--
+ Technologies:
+
+ 0 - Unknown
+ 1 - NFC-A
+ 2 - NFC-B
+ -->
+ <method name="GetAll">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="present" type="b" direction="out"/>
+ <arg name="technology" type="u" direction="out"/>
+ </method>
+ <method name="GetInterfaceVersion">
+ <arg name="version" type="i" direction="out"/>
+ </method>
+ <method name="GetPresent">
+ <arg name="present" type="b" direction="out"/>
+ </method>
+ <method name="GetTechnology">
+ <arg name="technology" type="u" direction="out"/>
+ </method>
+ <method name="Deactivate"/>
+ <!-- Signals -->
+ <signal name="Removed"/>
+ </interface>
+</node>
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.LocalHostApp.xml
^
|
@@ -0,0 +1,58 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.sailfishos.nfc.LocalHostApp">
+ <!-- Interface version 1 -->
+ <method name="GetInterfaceVersion">
+ <arg name="version" type="i" direction="out"/>
+ </method>
+ <method name="Start">
+ <arg name="host" type="o" direction="in"/>
+ <!-- Failure is indicated with a D-Bus error -->
+ </method>
+ <method name="Restart">
+ <arg name="host" type="o" direction="in"/>
+ <!-- Failure is indicated with a D-Bus error -->
+ </method>
+ <method name="Stop">
+ <arg name="path" type="o" direction="in"/>
+ <!-- No reply expected -->
+ </method>
+ <method name="ImplicitSelect">
+ <arg name="host" type="o" direction="in"/>
+ <!-- Failure is indicated with a D-Bus error -->
+ </method>
+ <method name="Select">
+ <arg name="host" type="o" direction="in"/>
+ <!-- Failure is indicated with a D-Bus error -->
+ </method>
+ <method name="Deselect">
+ <arg name="path" type="o" direction="in"/>
+ <!-- No reply expected -->
+ </method>
+ <method name="Process">
+ <arg name="host" type="o" direction="in"/>
+ <arg name="CLA" type="y" direction="in"/>
+ <arg name="INS" type="y" direction="in"/>
+ <arg name="P1" type="y" direction="in"/>
+ <arg name="P2" type="y" direction="in"/>
+ <arg name="data" type="ay" direction="in">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg name="Le" type="u" direction="in"/>
+ <!-- Failure is indicated with a D-Bus error -->
+ <arg name="response" type="ay" direction="out">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg name="SW1" type="y" direction="out"/>
+ <arg name="SW2" type="y" direction="out"/>
+ <!-- Non-zero response_id will result in ResponseStatus call later -->
+ <arg name="response_id" type="u" direction="out"/>
+ </method>
+ <method name="ResponseStatus">
+ <arg name="response_id" type="u" direction="in"/>
+ <arg name="ok" type="b" direction="in"/>
+ <!-- No reply expected -->
+ </method>
+ </interface>
+</node>
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.LocalHostService.xml
^
|
@@ -0,0 +1,46 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.sailfishos.nfc.LocalHostService">
+ <!-- Interface version 1 -->
+ <method name="GetInterfaceVersion">
+ <arg name="version" type="i" direction="out"/>
+ </method>
+ <method name="Start">
+ <arg name="host" type="o" direction="in"/>
+ <!-- Failure is indicated with a D-Bus error -->
+ </method>
+ <method name="Restart">
+ <arg name="host" type="o" direction="in"/>
+ <!-- Failure is indicated with a D-Bus error -->
+ </method>
+ <method name="Stop">
+ <arg name="path" type="o" direction="in"/>
+ <!-- No reply expected -->
+ </method>
+ <method name="Process">
+ <arg name="host" type="o" direction="in"/>
+ <arg name="CLA" type="y" direction="in"/>
+ <arg name="INS" type="y" direction="in"/>
+ <arg name="P1" type="y" direction="in"/>
+ <arg name="P2" type="y" direction="in"/>
+ <arg name="data" type="ay" direction="in">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg name="Le" type="u" direction="in"/>
+ <!-- Failure is indicated with a D-Bus error -->
+ <arg name="response" type="ay" direction="out">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg name="SW1" type="y" direction="out"/>
+ <arg name="SW2" type="y" direction="out"/>
+ <!-- Non-zero response_id will result in ResponseStatus call later -->
+ <arg name="response_id" type="u" direction="out"/>
+ </method>
+ <method name="ResponseStatus">
+ <arg name="response_id" type="u" direction="in"/>
+ <arg name="ok" type="b" direction="in"/>
+ <!-- No reply expected -->
+ </method>
+ </interface>
+</node>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/plugins/dbus_service/org.sailfishos.nfc.daemon.conf
^
|
@@ -4,10 +4,14 @@
<policy user="root">
<allow own="org.sailfishos.nfc.daemon"/>
<allow send_interface="org.sailfishos.nfc.LocalService"/>
+ <allow send_interface="org.sailfishos.nfc.LocalHostService"/>
+ <allow send_interface="org.sailfishos.nfc.LocalHostApp"/>
</policy>
<policy user="nfc">
<allow own="org.sailfishos.nfc.daemon"/>
<allow send_interface="org.sailfishos.nfc.LocalService"/>
+ <allow send_interface="org.sailfishos.nfc.LocalHostService"/>
+ <allow send_interface="org.sailfishos.nfc.LocalHostApp"/>
</policy>
<policy context="default">
<allow send_destination="org.sailfishos.nfc.daemon"
@@ -17,6 +21,8 @@
<allow send_destination="org.sailfishos.nfc.daemon"
send_interface="org.sailfishos.nfc.Adapter"/>
<allow send_destination="org.sailfishos.nfc.daemon"
+ send_interface="org.sailfishos.nfc.Host"/>
+ <allow send_destination="org.sailfishos.nfc.daemon"
send_interface="org.sailfishos.nfc.Peer"/>
<allow send_destination="org.sailfishos.nfc.daemon"
send_interface="org.sailfishos.nfc.Tag"/>
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/tools/README
^
|
@@ -25,3 +25,9 @@
Writes an NDEF record to a writeable Type 2 tag. The tool can
either format a URI, Text or SmartPoster record by itself, or
read a pre-formatted one from the file.
+
+ndef-share
+==========
+
+Shares some content over NFC as an NDEF record by emulating a
+Type 4 tag.
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/tools/ndef-share/Makefile
^
|
@@ -0,0 +1,162 @@
+# -*- Mode: makefile-gmake -*-
+
+.PHONY: all debug release clean install
+
+#
+# Required packages
+#
+
+PKGS = gio-unix-2.0 gio-2.0 libnfcdef libglibutil
+LIB_PKGS = $(PKGS)
+
+#
+# Default target
+#
+
+all: debug release
+
+#
+# The executable
+#
+
+EXE = ndef-share
+
+#
+# Sources
+#
+
+SRC = $(EXE).c
+
+GEN_SRC = \
+ org.sailfishos.nfc.Daemon.c \
+ org.sailfishos.nfc.LocalHostApp.c
+
+ALL_SRC = $(GEN_SRC) $(SRC)
+
+#
+# Directories
+#
+
+SRC_DIR = .
+BUILD_DIR = build
+SPEC_DIR = ../../plugins/dbus_service
+NFC_INCLUDE_DIR = ../../core/include
+GEN_DIR = $(BUILD_DIR)
+DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
+RELEASE_BUILD_DIR = $(BUILD_DIR)/release
+
+#
+# Tools and flags
+#
+
+CC = $(CROSS_COMPILE)gcc
+LD = $(CC)
+DEBUG_FLAGS = -g
+RELEASE_FLAGS =
+DEBUG_DEFS = -DDEBUG
+RELEASE_DEFS =
+WARNINGS = -Wall -Wstrict-aliasing -Wunused-result
+INCLUDES = -I. -I$(NFC_INCLUDE_DIR) -I$(GEN_DIR)
+FULL_CFLAGS = -fPIC $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
+ -MMD -MP $(shell pkg-config --cflags $(PKGS))
+FULL_LDFLAGS = $(LDFLAGS) -pie
+
+KEEP_SYMBOLS ?= 0
+ifneq ($(KEEP_SYMBOLS),0)
+RELEASE_FLAGS += -g
+SUBMAKE_OPTS += KEEP_SYMBOLS=1
+endif
+
+DEBUG_CFLAGS = $(DEBUG_FLAGS) -DDEBUG $(FULL_CFLAGS)
+RELEASE_CFLAGS = $(RELEASE_FLAGS) -O2 $(FULL_CFLAGS)
+DEBUG_LDFLAGS = $(DEBUG_FLAGS) $(FULL_LDFLAGS)
+RELEASE_LDFLAGS = $(RELEASE_FLAGS) $(FULL_LDFLAGS)
+
+LIBS = $(shell pkg-config --libs $(LIB_PKGS)) -lmagic -ldl
+DEBUG_LIBS = $(LIBS)
+RELEASE_LIBS = $(LIBS)
+
+#
+# Files
+#
+
+DEBUG_OBJS = $(ALL_SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
+RELEASE_OBJS = $(ALL_SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
+
+#
+# Dependencies
+#
+
+DEPS = \
+ $(DEBUG_OBJS:%.o=%.d) \
+ $(RELEASE_OBJS:%.o=%.d)
+ifneq ($(MAKECMDGOALS),clean)
+ifneq ($(strip $(DEPS)),)
+-include $(DEPS)
+endif
+endif
+
+$(GEN_SRC:%=$(GEN_DIR)/%): | $(GEN_DIR)
+$(SRC): | $(GEN_SRC:%=$(GEN_DIR)/%)
+$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
+$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
+
+#
+# Rules
+#
+
+DEBUG_EXE = $(DEBUG_BUILD_DIR)/$(EXE)
+RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
+
+debug: $(DEBUG_DEPS) $(DEBUG_EXE)
+
+release: $(RELEASE_DEPS) $(RELEASE_EXE)
+
+clean:
+ rm -fr $(BUILD_DIR) $(SRC_DIR)/*~
+
+$(GEN_DIR)/%.c: $(SPEC_DIR)/%.xml
+ gdbus-codegen --generate-c-code $(@:%.c=%) $<
+
+$(GEN_DIR):
+ mkdir -p $@
+
+$(DEBUG_BUILD_DIR):
+ mkdir -p $@
+
+$(RELEASE_BUILD_DIR):
+ mkdir -p $@
+
+$(DEBUG_BUILD_DIR)/%.o: $(GEN_DIR)/%.c
+ $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/%.o: $(GEN_DIR)/%.c
+ $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_BUILD_DIR)/%.o: $(SRC_DIR)/%.c
+ $(CC) -c $(WARN) $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/%.o: $(SRC_DIR)/%.c
+ $(CC) -c $(WARN) $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_EXE): $(DEBUG_EXE_DEPS) $(DEBUG_OBJS)
+ $(LD) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) $(DEBUG_LIBS) -o $@
+
+$(RELEASE_EXE): $(RELEASE_EXE_DEPS) $(RELEASE_OBJS)
+ $(LD) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) $(RELEASE_LIBS) -o $@
+ifeq ($(KEEP_SYMBOLS),0)
+ strip $@
+endif
+
+#
+# Install
+#
+
+INSTALL = install
+INSTALL_BIN_DIR = $(DESTDIR)/usr/bin
+
+install: $(INSTALL_BIN_DIR)
+ $(INSTALL) -m 755 $(RELEASE_EXE) $(INSTALL_BIN_DIR)
+
+$(INSTALL_BIN_DIR):
+ $(INSTALL) -d $@
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/tools/ndef-share/ndef-share.c
^
|
@@ -0,0 +1,914 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_host_app.h"
+#include "org.sailfishos.nfc.Daemon.h"
+#include "org.sailfishos.nfc.LocalHostApp.h"
+
+#include <nfcdef.h>
+
+#include <gutil_misc.h>
+#include <gutil_strv.h>
+#include <gutil_log.h>
+
+#include <glib-unix.h>
+
+#include <locale.h>
+#include <magic.h>
+
+#define NFC_BUS G_BUS_TYPE_SYSTEM
+#define NFC_SERVICE "org.sailfishos.nfc.daemon"
+#define NFC_DAEMON_PATH "/"
+#define NFC_DAEMON_MIN_INTERFACE_VERSION 4
+#define LAST_RESPONSE_ID (1)
+
+static const guchar ndef_aid[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 };
+
+/*
+ * [NFCForum-TS-Type-4-Tag_2.0]
+ *
+ * Data Structure of the Capability Container File
+ *
+ * +======================================================================+
+ * | Offset | Size | Description |
+ * +======================================================================+
+ * | 0 | 2 | CCLEN (total length, 0x000F-0xFFFE bytes) |
+ * | 2 | 1 | Mapping Version (major/minor 4 bits each) |
+ * | 3 | 2 | MLe (Maximum R-APDU data size, 0x000F..0xFFFF bytes) |
+ * | 5 | 2 | MLc (Maximum C-APDU data size, 0x0001..0xFFFF bytes) |
+ * | 7 | 8 | NDEF File Control TLV (see below) |
+ * | 15 |- | Zero, one, or more TLV blocks |
+ * +======================================================================+
+ *
+ * NDEF File Control TLV:
+ *
+ * +==============================================================+
+ * | Offset | Size | Description |
+ * +==============================================================+
+ * | 0 | 1 | T = 4 |
+ * | 1 | 1 | L = 6 |
+ * | 2 | 2 | File Identifier |
+ * | 4 | 2 | Maximum NDEF file size, 0x0005..0xFFFE |
+ * | 6 | 1 | NDEF file read access condition (0x00) |
+ * | 7 | 1 | NDEF file write access condition (0x00|0xFF) |
+ * +==============================================================+
+ */
+
+static const guchar cc_ef[] = { 0xe1, 0x03 };
+static const guchar cc_data_template[] = {
+ 0x00, 0x0f, 0x20, 0xff, 0xff, 0xff, 0xff, /* CC header 7 bytes */
+ 0x04, 0x06, 0xe1, 0x04, 0xff, 0xfe, 0x00, 0xff /* NDEF File Control TLV */
+ /* fid */ /* size */
+};
+#define CC_NDEF_TLV_OFFSET (7)
+#define CC_NDEF_FID_OFFSET (CC_NDEF_TLV_OFFSET + 2)
+#define CC_NDEF_SIZE_OFFSET (CC_NDEF_TLV_OFFSET + 4)
+
+#define ISO_CLA (0x00)
+#define ISO_INS_SELECT (0xa4)
+#define ISO_INS_READ_BINARY (0xb0)
+#define ISO_P1_SELECT_BY_ID (0x00)
+#define ISO_P2_SELECT_FILE_FIRST (0x00)
+#define ISO_P2_RESPONSE_NONE (0x0c)
+
+/* x(DBUS_CALL,dbus_call,dbus-call) */
+#define APP_DBUS_CALLS(x) \
+ x(START,start,start) \
+ x(RESTART,restart,restart) \
+ x(STOP,stop,stop) \
+ x(IMPLICIT_SELECT,implicit_select,implicit-select) \
+ x(SELECT,select,select) \
+ x(DESELECT,deselect,deselect) \
+ x(PROCESS,process,process) \
+ x(RESPONSE_STATUS,response_status,response-status)
+
+enum {
+ #define DEFINE_ENUM(CALL,call,name) APP_CALL_##CALL,
+ APP_DBUS_CALLS(DEFINE_ENUM)
+ #undef DEFINE_ENUM
+ APP_CALL_COUNT
+};
+
+#define RET_OK (0)
+#define RET_CMDLINE (1)
+#define RET_ERR (2)
+
+typedef enum ndef_share_flags {
+ NDEF_SHARE_FLAGS_NONE = 0,
+ NDEF_SHARE_FLAG_NFC_A = 0x01,
+ NDEF_SHARE_FLAG_READER_OFF = 0x02,
+ NDEF_SHARE_FLAG_KEEP_SHARING = 0x04
+} NDEF_SHARE_FLAGS;
+
+typedef struct elem_file {
+ const char* name;
+ GUtilData fid;
+ GBytes* data;
+ gboolean last;
+} ElemFile;
+
+typedef struct ndef_share {
+ const char* path;
+ const char* name;
+ ElemFile ef[2];
+ const ElemFile* selected_file;
+ GMainLoop* loop;
+ NDEF_SHARE_FLAGS flags;
+ gboolean stopped;
+ int ret;
+} NdefShare;
+
+typedef struct ndef_share_opts {
+ char* media_type;
+ gboolean media_type_rec;
+} NdefShareOpts;
+
+#define g_variant_new_empty_bytestring() g_variant_new_from_data\
+ (G_VARIANT_TYPE_BYTESTRING, NULL, 0, TRUE, NULL, NULL)
+
+static
+gboolean
+ndef_share_signal(
+ gpointer user_data)
+{
+ NdefShare* app = user_data;
+
+ if (!app->stopped) {
+ GDEBUG("\nSignal caught, exiting...");
+ g_main_loop_quit(app->loop);
+ }
+ return G_SOURCE_CONTINUE;
+}
+
+static
+void
+ndef_share_init_cc_file(
+ ElemFile* ef,
+ gsize ndef_size)
+{
+ const gsize size = sizeof(cc_data_template);
+ guchar* file = gutil_memdup(cc_data_template, size);
+
+ file[CC_NDEF_SIZE_OFFSET] = (guchar)((ndef_size >> 8) & 0x7f);
+ file[CC_NDEF_SIZE_OFFSET + 1] = (guchar)ndef_size;
+
+ ef->data = g_bytes_new_take(file, size);
+ ef->fid.bytes = cc_ef;
+ ef->fid.size = sizeof(cc_ef);
+ ef->name = "NDEF Capability Container";
+ ef->last = FALSE;
+}
+
+static
+const ElemFile*
+ndef_share_init_ndef_file(
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/tools/ndef-write/ndef-write.c
^
|
@@ -708,6 +708,10 @@
app.ndef = mapdata;
ret = write_ndef(&app);
}
+
+ if (map) {
+ g_mapped_file_unref(map);
+ }
g_strfreev(app.tags);
} else if (error) {
fprintf(stderr, "%s\n", GERRMSG(error));
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/Makefile
^
|
@@ -5,6 +5,7 @@
@$(MAKE) -C core_adapter $*
@$(MAKE) -C core_config $*
@$(MAKE) -C core_crc $*
+ @$(MAKE) -C core_host $*
@$(MAKE) -C core_initiator $*
@$(MAKE) -C core_llc $*
@$(MAKE) -C core_llc_param $*
@@ -33,7 +34,10 @@
@$(MAKE) -C plugins_dbus_handlers_type_text $*
@$(MAKE) -C plugins_dbus_handlers_type_uri $*
@$(MAKE) -C plugins_dbus_service_adapter $*
+ @$(MAKE) -C plugins_dbus_service_host $*
@$(MAKE) -C plugins_dbus_service_isodep $*
+ @$(MAKE) -C plugins_dbus_service_local_app $*
+ @$(MAKE) -C plugins_dbus_service_local_host $*
@$(MAKE) -C plugins_dbus_service_ndef $*
@$(MAKE) -C plugins_dbus_service_peer $*
@$(MAKE) -C plugins_dbus_service_plugin $*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/Makefile.plugins
^
|
@@ -29,12 +29,6 @@
CLEAN_DIRS += $(PLUGINS_DIR)
#
-# Tools and flags
-#
-
-INCLUDES += -I$(PLUGINS_DIR)
-
-#
# libnfc-plugins.a
#
@@ -49,6 +43,12 @@
COVERAGE_LIBS += $(COVERAGE_PLUGINS_LIB)
#
+# Tools and flags
+#
+
+INCLUDES += -I$(PLUGINS_DIR) -I$(PLUGINS_BUILD_DIR)/gen
+
+#
# Dependencies
#
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_adapter.c
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2019-2023 Slava Monich <slava@monich.com>
* 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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "nfc_adapter_impl.h"
@@ -37,17 +44,40 @@
* Test adapter
*==========================================================================*/
+typedef enum test_adapter_flags {
+ TEST_ADAPTER_FLAGS_NONE = 0,
+ TEST_ADAPTER_FLAG_OVERRIDE_TECHS = 0x01
+} TEST_ADAPTER_FLAGS;
+
typedef NfcAdapterClass TestAdapterClass;
-typedef NfcAdapter TestAdapter;
+typedef struct test_adapter {
+ NfcAdapter adapter;
+ TEST_ADAPTER_FLAGS flags;
+ NFC_TECHNOLOGY supported_techs;
+} TestAdapter;
+
+#define THIS_TYPE test_adapter_get_type()
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, TestAdapter)
+#define PARENT_CLASS test_adapter_parent_class
G_DEFINE_TYPE(TestAdapter, test_adapter, NFC_TYPE_ADAPTER)
-#define TEST_TYPE_ADAPTER (test_adapter_get_type())
NfcAdapter*
test_adapter_new(
void)
{
- return g_object_new(TEST_TYPE_ADAPTER, NULL);
+ return g_object_new(THIS_TYPE, NULL);
+}
+
+NfcAdapter*
+test_adapter_new_with_techs(
+ NFC_TECHNOLOGY techs)
+{
+ TestAdapter* self = g_object_new(THIS_TYPE, NULL);
+
+ self->supported_techs = techs;
+ self->flags |= TEST_ADAPTER_FLAG_OVERRIDE_TECHS;
+ return NFC_ADAPTER(self);
}
static
@@ -71,6 +101,18 @@
}
static
+NFC_TECHNOLOGY
+test_adapter_get_supported_techs(
+ NfcAdapter* adapter)
+{
+ TestAdapter* self = THIS(adapter);
+
+ return (self->flags & TEST_ADAPTER_FLAG_OVERRIDE_TECHS) ?
+ self->supported_techs : NFC_ADAPTER_CLASS(PARENT_CLASS)->
+ get_supported_techs(adapter);
+}
+
+static
void
test_adapter_init(
TestAdapter* self)
@@ -84,6 +126,7 @@
{
klass->submit_power_request = test_adapter_submit_power_request;
klass->submit_mode_request = test_adapter_submit_mode_request;
+ klass->get_supported_techs = test_adapter_get_supported_techs;
}
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_adapter.h
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2019-2023 Slava Monich <slava@monich.com>
* 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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef TEST_ADAPTER_H
@@ -39,6 +46,10 @@
test_adapter_new(
void);
+NfcAdapter*
+test_adapter_new_with_techs(
+ NFC_TECHNOLOGY techs);
+
#endif /* TEST_ADAPTER_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_common.h
^
|
@@ -10,23 +10,27 @@
*
* 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -36,26 +40,7 @@
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
-#include <gutil_types.h>
-
-/*
- * For whatever reason, g_assert() is a special case and can be disabled
- * with G_DISABLE_ASSERT macro, unlike all other g_assert_* macros. Make
- * sure that it actually works.
- */
-#ifdef G_DISABLE_ASSERT
-# error "g_assert is required by unit tests"
-#endif
-
-#define TEST_FLAG_DEBUG (0x01)
-typedef struct test_opt {
- int flags;
-} TestOpt;
-
-typedef struct test_tx {
- GUtilData in;
- GUtilData out;
-} TestTx;
+#include "test_types.h"
/* Should be invoked after g_test_init */
void
@@ -88,51 +73,17 @@
#define TEST_TIMEOUT_MS (TEST_TIMEOUT_SEC * 1000)
/* Utilities */
-GUtilData*
-test_alloc_data(
- const void* bytes,
- guint len);
-
-GUtilData*
-test_clone_data(
- const GUtilData* data);
+
+guint
+test_idle_add_full(
+ GSourceFunc func,
+ gpointer user_data,
+ GDestroyNotify destroy);
int
test_rmdir(
const char* path);
-/* Helper macros */
-
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-# define TEST_INT16_BYTES(v) \
- (guint8)(v), (guint8)((v) >> 8)
-# define TEST_INT32_BYTES(v) \
- (guint8)(v), (guint8)((v) >> 8), \
- (guint8)((v) >> 16), (guint8)((v) >> 24)
-# define TEST_INT64_BYTES(v) \
- (guint8)(v), (guint8)((v) >> 8), \
- (guint8)((v) >> 16), (guint8)((v) >> 24), \
- (guint8)(((guint64)(v)) >> 32), (guint8)(((guint64)(v)) >> 40), \
- (guint8)(((guint64)(v)) >> 48), (guint8)(((guint64)(v)) >> 56)
-#elif G_BYTE_ORDER == G_BIG_ENDIAN
-# define TEST_INT16_BYTES(v) \
- (guint8)((v) >> 8), (guint8)(v)
-# define TEST_INT32_BYTES(v) \
- (guint8)((v) >> 24), (guint8)((v) >> 16), \
- (guint8)((v) >> 8), (guint8)(v)
-# define TEST_INT64_BYTES(v) \
- (guint8)(((guint64)(v)) >> 56), (guint8)(((guint64)(v)) >> 48), \
- (guint8)(((guint64)(v)) >> 40), (guint8)(((guint64)(v)) >> 32), \
- (guint8)((v) >> 24), (guint8)((v) >> 16), \
- (guint8)((v) >> 8), (guint8)(v)
-#else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
-#error unknown ENDIAN type
-#endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
-
-#define TEST_ARRAY_AND_COUNT(a) a, G_N_ELEMENTS(a)
-#define TEST_ARRAY_AND_SIZE(a) a, sizeof(a)
-#define TEST_BYTES_SET(b,d) ((b).bytes = (void*)(d), (b).size = sizeof(d))
-
#endif /* TEST_COMMON_H */
/*
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_host_app.c
^
|
@@ -0,0 +1,451 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_util.h"
+
+#include "test_host_app.h"
+#include "test_common.h"
+
+#include <gutil_macros.h>
+#include <gutil_misc.h>
+
+#define THIS_TYPE TEST_TYPE_HOST_APP
+#define THIS(obj) TEST_HOST_APP(obj)
+#define PARENT_CLASS test_host_app_parent_class
+
+typedef NfcHostAppClass TestHostAppClass;
+G_DEFINE_TYPE(TestHostApp, test_host_app, NFC_TYPE_HOST_APP)
+
+enum test_host_app_signal {
+ SIGNAL_START,
+ SIGNAL_COUNT
+};
+
+#define SIGNAL_START_NAME "test-host-app-start"
+
+static guint test_host_app_signals[SIGNAL_COUNT] = { 0 };
+
+typedef struct test_host_app_bool_data {
+ NfcHostApp* app;
+ NfcHostAppBoolFunc complete;
+ void* user_data;
+ GDestroyNotify destroy;
+ gboolean ok;
+} TestHostAppBoolData;
+
+typedef struct test_host_app_resp_data {
+ NfcHostApp* app;
+ NfcHostAppResponse resp;
+ NfcHostAppResponseFunc complete;
+ void* user_data;
+ GDestroyNotify destroy;
+} TestHostAppRespData;
+
+static
+TestHostAppBoolData*
+test_host_app_bool_data_new(
+ NfcHostApp* app,
+ NfcHostAppBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy,
+ gboolean ok)
+{
+ TestHostAppBoolData* data = g_slice_new0(TestHostAppBoolData);
+
+ data->app = nfc_host_app_ref(app);
+ data->complete = complete;
+ data->user_data = user_data;
+ data->destroy = destroy;
+ data->ok = ok;
+ return data;
+}
+
+static
+gboolean
+test_host_app_start_complete(
+ void* user_data)
+{
+ TestHostAppBoolData* data = user_data;
+ TestHostApp* self = THIS(data->app);
+
+ /* start is always incremented, regardless of the status */
+ self->start++;
+ if (data->complete) {
+ data->complete(data->app, data->ok, data->user_data);
+ }
+
+ g_signal_emit(self, test_host_app_signals[SIGNAL_START], 0, data->ok);
+ return G_SOURCE_REMOVE;
+}
+
+static
+gboolean
+test_host_app_bool_data_complete(
+ void* user_data)
+{
+ TestHostAppBoolData* data = user_data;
+
+ if (data->complete) {
+ data->complete(data->app, data->ok, data->user_data);
+ }
+ return G_SOURCE_REMOVE;
+}
+
+static
+void
+test_host_app_bool_data_destroy(
+ void* user_data)
+{
+ TestHostAppBoolData* data = user_data;
+
+ if (data->destroy) {
+ data->destroy(data->user_data);
+ }
+ nfc_host_app_unref(data->app);
+ gutil_slice_free(data);
+}
+
+static
+TestHostAppRespData*
+test_host_app_resp_data_new(
+ NfcHostApp* app,
+ NfcHostAppResponseFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ TestHostAppRespData* data = g_slice_new0(TestHostAppRespData);
+
+ data->app = nfc_host_app_ref(app);
+ data->complete = complete;
+ data->user_data = user_data;
+ data->destroy = destroy;
+ return data;
+}
+
+static
+gboolean
+test_host_app_resp_data_complete(
+ void* user_data)
+{
+ TestHostAppRespData* data = user_data;
+
+ if (data->complete) {
+ TestHostApp* self = THIS(data->app);
+
+ data->complete(data->app, (self->flags &
+ TEST_HOST_APP_FLAG_PROCESS_FAIL) ? NULL : &data->resp,
+ data->user_data);
+ }
+ return G_SOURCE_REMOVE;
+}
+
+static
+void
+test_host_app_resp_data_destroy(
+ void* user_data)
+{
+ TestHostAppRespData* data = user_data;
+
+ if (data->destroy) {
+ data->destroy(data->user_data);
+ }
+ nfc_host_app_unref(data->app);
+ gutil_slice_free(data);
+}
+
+TestHostApp*
+test_host_app_new(
+ const GUtilData* aid,
+ const char* name,
+ NFC_HOST_APP_FLAGS flags)
+{
+ TestHostApp* test = g_object_new(THIS_TYPE, NULL);
+
+ nfc_host_app_init_base(NFC_HOST_APP(test), aid, name, flags);
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_host_app.h
^
|
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef TEST_CARD_APP_H
+#define TEST_CARD_APP_H
+
+#include "test_types.h"
+
+#include "nfc_host_app_impl.h"
+
+typedef enum test_host_app_flags {
+ TEST_HOST_APP_NO_FLAGS = 0,
+ TEST_HOST_APP_FLAG_START_SYNC_OK = 0x0001,
+ TEST_HOST_APP_FLAG_START_SYNC_ERR = 0x0002,
+ TEST_HOST_APP_FLAG_FAIL_START = 0x0004,
+ TEST_HOST_APP_FLAG_FAIL_START_ASYNC = 0x0008,
+ TEST_HOST_APP_FLAG_FAIL_IMPLICIT_SELECT = 0x0010,
+ TEST_HOST_APP_FLAG_FAIL_IMPLICIT_SELECT_ASYNC = 0x0020,
+ TEST_HOST_APP_FLAG_FAIL_SELECT = 0x0040,
+ TEST_HOST_APP_FLAG_FAIL_SELECT_ASYNC = 0x0080,
+ TEST_HOST_APP_FLAG_PROCESS_ERR = 0x0100,
+ TEST_HOST_APP_FLAG_PROCESS_SYNC = 0x0200,
+ TEST_HOST_APP_FLAG_PROCESS_FAIL = 0x0400,
+ TEST_HOST_APP_FLAG_PROCESS_SENT_ONCE = 0x0800
+} TEST_HOST_APP_FLAGS;
+
+typedef struct test_host_app {
+ NfcHostApp app;
+ TEST_HOST_APP_FLAGS flags;
+ const TestTx* tx_list; /* Assumed to point to static data */
+ gsize tx_count;
+ gsize tx_done;
+ int start;
+ int select;
+ int deselect;
+ int process;
+ NfcHostAppBoolFunc sent_cb;
+ void* sent_data;
+} TestHostApp;
+
+GType test_host_app_get_type(void);
+#define TEST_TYPE_HOST_APP test_host_app_get_type()
+#define TEST_HOST_APP(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_HOST_APP, TestHostApp)
+
+gulong
+test_host_app_add_start_handler(
+ TestHostApp* app,
+ NfcHostAppBoolFunc func,
+ void* user_data);
+
+TestHostApp*
+test_host_app_new(
+ const GUtilData* aid,
+ const char* name,
+ NFC_HOST_APP_FLAGS flags);
+
+#endif /* TEST_HOST_APP_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_host_service.c
^
|
@@ -0,0 +1,408 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_util.h"
+
+#include "test_host_service.h"
+#include "test_common.h"
+
+#include <gutil_macros.h>
+#include <gutil_misc.h>
+
+#define THIS_TYPE TEST_TYPE_HOST_SERVICE
+#define THIS(obj) TEST_HOST_SERVICE(obj)
+#define PARENT_CLASS test_host_service_parent_class
+
+typedef NfcHostServiceClass TestHostServiceClass;
+G_DEFINE_TYPE(TestHostService, test_host_service, NFC_TYPE_HOST_SERVICE)
+
+enum test_host_service_signal {
+ SIGNAL_START,
+ SIGNAL_RESTART,
+ SIGNAL_COUNT
+};
+
+#define SIGNAL_START_NAME "test-host-service-start"
+#define SIGNAL_RESTART_NAME "test-host-service-restart"
+
+static guint test_host_service_signals[SIGNAL_COUNT] = { 0 };
+
+typedef struct test_host_service_start_data {
+ NfcHostService* service;
+ NfcHostServiceBoolFunc complete;
+ void* user_data;
+ GDestroyNotify destroy;
+} TestHostServiceStartData;
+
+typedef struct test_host_service_resp_data {
+ NfcHostService* service;
+ NfcHostServiceResponse resp;
+ NfcHostServiceResponseFunc complete;
+ void* user_data;
+ GDestroyNotify destroy;
+} TestHostServiceRespData;
+
+static
+TestHostServiceStartData*
+test_host_service_start_data_new(
+ NfcHostService* service,
+ NfcHostServiceBoolFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ TestHostServiceStartData* data = g_slice_new0(TestHostServiceStartData);
+
+ data->service = nfc_host_service_ref(service);
+ data->complete = complete;
+ data->user_data = user_data;
+ data->destroy = destroy;
+ return data;
+}
+
+static
+gboolean
+test_host_service_start_data_complete(
+ void* user_data)
+{
+ TestHostServiceStartData* data = user_data;
+ TestHostService* self = THIS(data->service);
+ gboolean ok = !(self->flags & TEST_HOST_SERVICE_FLAG_FAIL_START);
+
+ /* start is always incremented, regardless of the status */
+ self->start++;
+ if (data->complete) {
+ data->complete(data->service, ok, data->user_data);
+ }
+
+ g_signal_emit(data->service, test_host_service_signals
+ [SIGNAL_START], 0, ok);
+ return G_SOURCE_REMOVE;
+}
+
+static
+void
+test_host_service_start_data_destroy(
+ void* user_data)
+{
+ TestHostServiceStartData* data = user_data;
+
+ if (data->destroy) {
+ data->destroy(data->user_data);
+ }
+ nfc_host_service_unref(data->service);
+ gutil_slice_free(data);
+}
+
+static
+TestHostServiceRespData*
+test_host_service_resp_data_new(
+ NfcHostService* service,
+ NfcHostServiceResponseFunc complete,
+ void* user_data,
+ GDestroyNotify destroy)
+{
+ TestHostServiceRespData* data = g_slice_new0(TestHostServiceRespData);
+
+ data->service = nfc_host_service_ref(service);
+ data->complete = complete;
+ data->user_data = user_data;
+ data->destroy = destroy;
+ return data;
+}
+
+static
+gboolean
+test_host_service_resp_data_complete(
+ void* user_data)
+{
+ TestHostServiceRespData* data = user_data;
+
+ if (data->complete) {
+ TestHostService* self = THIS(data->service);
+
+ data->complete(data->service, (self->flags &
+ TEST_HOST_SERVICE_FLAG_PROCESS_FAIL) ? NULL : &data->resp,
+ data->user_data);
+ }
+ return G_SOURCE_REMOVE;
+}
+
+static
+void
+test_host_service_resp_data_destroy(
+ void* user_data)
+{
+ TestHostServiceRespData* data = user_data;
+
+ if (data->destroy) {
+ data->destroy(data->user_data);
+ }
+ nfc_host_service_unref(data->service);
+ gutil_slice_free(data);
+}
+
+TestHostService*
+test_host_service_new(
+ const char* name)
+{
+ TestHostService* test = g_object_new(THIS_TYPE, NULL);
+
+ nfc_host_service_init_base(NFC_HOST_SERVICE(test), name);
+ return test;
+}
+
+gulong
+test_host_service_add_start_handler(
+ TestHostService* service,
+ NfcHostServiceBoolFunc func,
+ void* user_data)
+{
+ return g_signal_connect(service, SIGNAL_START_NAME,
+ G_CALLBACK(func), user_data);
+}
+
+gulong
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_host_service.h
^
|
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef TEST_HOST_SERVICE_H
+#define TEST_HOST_SERVICE_H
+
+#include "test_types.h"
+
+#include "nfc_host_service_impl.h"
+
+typedef enum test_host_service_flags {
+ TEST_HOST_SERVICE_NO_FLAGS = 0,
+ TEST_HOST_SERVICE_FLAG_START_SYNC_OK = 0x01,
+ TEST_HOST_SERVICE_FLAG_START_SYNC_ERR = 0x02,
+ TEST_HOST_SERVICE_FLAG_FAIL_START = 0x04,
+ TEST_HOST_SERVICE_FLAG_FAIL_START_ASYNC = 0x08,
+ TEST_HOST_SERVICE_FLAG_PROCESS_ERR = 0x10,
+ TEST_HOST_SERVICE_FLAG_PROCESS_SYNC = 0x20,
+ TEST_HOST_SERVICE_FLAG_PROCESS_FAIL = 0x40,
+ TEST_HOST_SERVICE_FLAG_PROCESS_SENT_ONCE = 0x80
+} TEST_HOST_SERVICE_FLAGS;
+
+typedef struct test_host_service {
+ NfcHostService service;
+ TEST_HOST_SERVICE_FLAGS flags;
+ const TestTx* tx_list; /* Assumed to point to static data */
+ gsize tx_count;
+ gsize tx_done;
+ int start; /* Counter of start() calls */
+ int restart; /* Counter of restart() calls */
+ int process; /* Counter or process() calls */
+ NfcHostServiceBoolFunc sent_cb;
+ void* sent_data;
+} TestHostService;
+
+GType test_host_service_get_type(void);
+#define TEST_TYPE_HOST_SERVICE test_host_service_get_type()
+#define TEST_HOST_SERVICE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_HOST_SERVICE, TestHostService)
+
+gulong
+test_host_service_add_start_handler(
+ TestHostService* service,
+ NfcHostServiceBoolFunc func,
+ void* user_data);
+
+gulong
+test_host_service_add_restart_handler(
+ TestHostService* service,
+ NfcHostServiceBoolFunc func,
+ void* user_data);
+
+TestHostService*
+test_host_service_new(
+ const char* name);
+
+#endif /* TEST_HOST_SERVICE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_initiator.c
^
|
@@ -1,39 +1,47 @@
/*
+ * Copyright (C) 2020-2023 Slava Monich <slava@monich.com>
* 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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "test_initiator.h"
#include "nfc_initiator_impl.h"
#include <gutil_log.h>
+#include <gutil_misc.h>
typedef NfcInitiatorClass TestInitiatorClass;
typedef struct test_initiator {
@@ -44,8 +52,8 @@
gboolean stay_alive;
} TestInitiator;
-#define THIS_TYPE (test_initiator_get_type())
-#define THIS(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, TestInitiator))
+#define THIS_TYPE test_initiator_get_type()
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, TestInitiator)
#define PARENT_CLASS test_initiator_parent_class
G_DEFINE_TYPE(TestInitiator, test_initiator, NFC_TYPE_INITIATOR)
@@ -143,6 +151,9 @@
test_initiator_init(
TestInitiator* self)
{
+ NfcInitiator* initiator = &self->initiator;
+
+ initiator->technology = NFC_TECHNOLOGY_A;
}
static
@@ -186,9 +197,9 @@
const GUtilData* out = &tx->out;
if (in->bytes) {
- self->list = g_slist_append(self->list, test_clone_data(in));
+ self->list = g_slist_append(self->list, gutil_data_copy(in));
if (out->bytes) {
- self->list = g_slist_append(self->list, test_clone_data(out));
+ self->list = g_slist_append(self->list, gutil_data_copy(out));
}
}
}
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_initiator.h
^
|
@@ -1,40 +1,48 @@
/*
+ * Copyright (C) 2021-2023 Slava Monich <slava@monich.com>
* 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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef TEST_INITIATOR_H
#define TEST_INITIATOR_H
-#include "nfc_types_p.h"
-#include "test_common.h"
+#include "test_types.h"
+
+#include "nfc_initiator.h"
NfcInitiator*
test_initiator_new(
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_main.c
^
|
@@ -1,37 +1,46 @@
/*
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2018-2022 Jolla Ltd.
- * Copyright (C) 2018-2022 Slava Monich <slava.monich@jolla.com>
*
- * You may use this file under the terms of BSD license as follows:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "test_common.h"
+#include "nfc_types.h"
+
#include <gutil_log.h>
#include <unistd.h>
@@ -40,36 +49,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-GUtilData*
-test_alloc_data(
- const void* bytes,
- guint len)
-{
- if (bytes) {
- const gsize total = len + sizeof(GUtilData);
- GUtilData* data = g_malloc(total);
-
- if (len) {
- void* contents = (void*)(data + 1);
-
- data->bytes = contents;
- data->size = len;
- memcpy(contents, bytes, len);
- } else {
- memset(data, 0, sizeof(*data));
- }
- return data;
- }
- return NULL;
-}
-
-GUtilData*
-test_clone_data(
- const GUtilData* data)
-{
- return data ? test_alloc_data(data->bytes, data->size) : NULL;
-}
-
/* Recursive rmdir */
int
test_rmdir(
@@ -174,6 +153,25 @@
}
}
+guint
+test_idle_add_full(
+ GSourceFunc func,
+ gpointer user_data,
+ GDestroyNotify destroy)
+{
+ const gint priority = G_PRIORITY_DEFAULT_IDLE;
+ guint id = g_idle_add_full(priority, func, user_data, destroy);
+
+ if (id == NFCD_ID_SYNC) {
+ guint id2 = g_idle_add_full(priority, func, user_data, destroy);
+
+ g_source_remove(id);
+ return id2;
+ } else {
+ return id;
+ }
+}
+
void
test_init(
TestOpt* opt,
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_target.c
^
|
@@ -1,39 +1,46 @@
/*
+ * Copyright (C) 2019-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
-#include "test_common.h"
#include "test_target.h"
#include <gutil_log.h>
+#include <gutil_misc.h>
#define THIS_TYPE TEST_TYPE_TARGET
#define THIS(obj) TEST_TARGET(obj)
@@ -127,7 +134,7 @@
{
nfc_target_gone(target);
}
-
+
static
void
test_target_init(
@@ -197,8 +204,8 @@
self->target.technology = tech;
self->fail_transmit = TEST_TARGET_FAIL_NONE;
- g_ptr_array_add(self->cmd_resp, test_alloc_data(cmd_bytes, cmd_len));
- g_ptr_array_add(self->cmd_resp, test_alloc_data(resp_bytes, resp_len));
+ g_ptr_array_add(self->cmd_resp, gutil_data_new(cmd_bytes, cmd_len));
+ g_ptr_array_add(self->cmd_resp, gutil_data_new(resp_bytes, resp_len));
return &self->target;
}
@@ -213,8 +220,10 @@
TestTarget* self = TEST_TARGET(target);
self->fail_transmit = TEST_TARGET_FAIL_NONE;
- g_ptr_array_add(self->cmd_resp, test_alloc_data(cmd_bytes, cmd_len));
- g_ptr_array_add(self->cmd_resp, test_alloc_data(resp_bytes, resp_len));
+ g_ptr_array_add(self->cmd_resp, gutil_data_new(cmd_bytes, cmd_len));
+ if (resp_bytes) {
+ g_ptr_array_add(self->cmd_resp, gutil_data_new(resp_bytes, resp_len));
+ }
}
NfcTarget*
@@ -232,9 +241,9 @@
const GUtilData* out = &tx->out;
if (in->bytes) {
- g_ptr_array_add(self->cmd_resp, test_clone_data(in));
+ g_ptr_array_add(self->cmd_resp, gutil_data_copy(in));
if (out->bytes) {
- g_ptr_array_add(self->cmd_resp, test_clone_data(out));
+ g_ptr_array_add(self->cmd_resp, gutil_data_copy(out));
}
}
}
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_target.h
^
|
@@ -1,38 +1,47 @@
/*
+ * Copyright (C) 2019-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#ifndef TEST_TARGET_H
#define TEST_TARGET_H
+#include "test_types.h"
+
#include "nfc_target_impl.h"
typedef NfcTargetClass TestTargetClass;
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/common/test_types.h
^
|
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef TEST_TYPES_H
+#define TEST_TYPES_H
+
+#include <gutil_types.h>
+
+/*
+ * For whatever reason, g_assert() is a special case and can be disabled
+ * with G_DISABLE_ASSERT macro, unlike all other g_assert_* macros. Make
+ * sure that it actually works.
+ */
+#ifdef G_DISABLE_ASSERT
+# error "g_assert is required by unit tests"
+#endif
+
+#define TEST_FLAG_DEBUG (0x01)
+typedef struct test_opt {
+ int flags;
+} TestOpt;
+
+typedef struct test_tx {
+ GUtilData in;
+ GUtilData out;
+} TestTx;
+
+/* Helper macros */
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+# define TEST_INT16_BYTES(v) \
+ (guint8)(v), (guint8)((v) >> 8)
+# define TEST_INT32_BYTES(v) \
+ (guint8)(v), (guint8)((v) >> 8), \
+ (guint8)((v) >> 16), (guint8)((v) >> 24)
+# define TEST_INT64_BYTES(v) \
+ (guint8)(v), (guint8)((v) >> 8), \
+ (guint8)((v) >> 16), (guint8)((v) >> 24), \
+ (guint8)(((guint64)(v)) >> 32), (guint8)(((guint64)(v)) >> 40), \
+ (guint8)(((guint64)(v)) >> 48), (guint8)(((guint64)(v)) >> 56)
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+# define TEST_INT16_BYTES(v) \
+ (guint8)((v) >> 8), (guint8)(v)
+# define TEST_INT32_BYTES(v) \
+ (guint8)((v) >> 24), (guint8)((v) >> 16), \
+ (guint8)((v) >> 8), (guint8)(v)
+# define TEST_INT64_BYTES(v) \
+ (guint8)(((guint64)(v)) >> 56), (guint8)(((guint64)(v)) >> 48), \
+ (guint8)(((guint64)(v)) >> 40), (guint8)(((guint64)(v)) >> 32), \
+ (guint8)((v) >> 24), (guint8)((v) >> 16), \
+ (guint8)((v) >> 8), (guint8)(v)
+#else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
+#error unknown ENDIAN type
+#endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
+
+#define TEST_ARRAY_AND_COUNT(a) a, G_N_ELEMENTS(a)
+#define TEST_ARRAY_AND_SIZE(a) a, sizeof(a)
+#define TEST_BYTES_SET(b,d) ((b).bytes = (void*)(d), (b).size = sizeof(d))
+
+#endif /* TEST_TYPES_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_adapter/test_core_adapter.c
^
|
@@ -10,23 +10,27 @@
*
* 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -34,19 +38,22 @@
*/
#include "nfc_adapter_p.h"
+#include "nfc_initiator_p.h"
+
#include "nfc_adapter_impl.h"
-#include "nfc_peer_services.h"
+#include "nfc_host.h"
#include "nfc_initiator_impl.h"
-#include "nfc_initiator_p.h"
+#include "nfc_peer_services.h"
+#include "nfc_peer.h"
#include "nfc_target_impl.h"
#include "nfc_tag_t2.h"
-#include "nfc_peer.h"
#include "test_common.h"
#include "test_target.h"
#include "test_initiator.h"
#include <gutil_log.h>
+#include <gutil_misc.h>
static TestOpt test_opt;
@@ -81,6 +88,16 @@
(*(int*)user_data)++;
}
+static
+void
+test_adapter_host_inc(
+ NfcAdapter* adapter,
+ NfcHost* host,
+ void* user_data)
+{
+ (*(int*)user_data)++;
+}
+
/*==========================================================================*
* Test adapter
*==========================================================================*/
@@ -240,8 +257,10 @@
{
/* Public interfaces are NULL tolerant */
g_assert(!nfc_adapter_ref(NULL));
+ g_assert(!nfc_adapter_hosts(NULL));
g_assert(!nfc_adapter_peers(NULL));
g_assert(!nfc_adapter_request_mode(NULL, 0));
+ g_assert(!nfc_adapter_add_host(NULL, NULL));
g_assert(!nfc_adapter_add_tag_t2(NULL, NULL, NULL));
g_assert(!nfc_adapter_add_tag_t4a(NULL, NULL, NULL, NULL));
g_assert(!nfc_adapter_add_tag_t4b(NULL, NULL, NULL, NULL));
@@ -264,7 +283,6 @@
G_GNUC_END_IGNORE_DEPRECATIONS
nfc_adapter_set_name(NULL, NULL);
- nfc_adapter_set_services(NULL, NULL);
nfc_adapter_mode_notify(NULL, 0, FALSE);
nfc_adapter_target_notify(NULL, FALSE);
nfc_adapter_power_notify(NULL, FALSE, FALSE);
@@ -315,7 +333,6 @@
nfc_adapter_remove_handler(adapter, 0);
nfc_adapter_set_name(adapter, name);
- nfc_adapter_set_services(adapter, services);
g_assert(!g_strcmp0(adapter->name, name));
g_assert(nfc_adapter_ref(adapter) == adapter);
@@ -371,10 +388,10 @@
nfc_adapter_set_name(adapter, "test");
- id[0] = nfc_adapter_add_power_requested_handler(adapter,
- test_adapter_inc, &power_requested_count);
- id[1] = nfc_adapter_add_powered_changed_handler(adapter,
- test_adapter_inc, &powered_changed_count);
+ g_assert((id[0] = nfc_adapter_add_power_requested_handler(adapter,
+ test_adapter_inc, &power_requested_count)));
+ g_assert((id[1] = nfc_adapter_add_powered_changed_handler(adapter,
+ test_adapter_inc, &powered_changed_count)));
test->fail_power_request = TRUE;
g_assert(!adapter->power_requested);
@@ -497,10 +514,10 @@
nfc_adapter_set_name(adapter, "test");
- id[0] = nfc_adapter_add_mode_requested_handler(adapter,
- test_adapter_inc, &mode_requested_count);
- id[1] = nfc_adapter_add_mode_changed_handler(adapter,
- test_adapter_inc, &mode_changed_count);
+ g_assert((id[0] = nfc_adapter_add_mode_requested_handler(adapter,
+ test_adapter_inc, &mode_requested_count)));
+ g_assert((id[1] = nfc_adapter_add_mode_changed_handler(adapter,
+ test_adapter_inc, &mode_changed_count)));
/* Unsupported mode */
g_assert(!nfc_adapter_request_mode(adapter, NFC_MODE_READER_WRITER));
@@ -628,15 +645,12 @@
int tag_added = 0, tag_removed = 0, presence_changed_count = 0;
NfcParamPoll poll;
- id[0] = nfc_adapter_add_tag_added_handler(adapter,
- test_adapter_tag_inc, &tag_added);
- id[1] = nfc_adapter_add_tag_removed_handler(adapter,
- test_adapter_tag_inc, &tag_removed);
- id[2] = nfc_adapter_add_target_presence_handler(adapter,
- test_adapter_inc, &presence_changed_count);
- g_assert(id[0]);
- g_assert(id[1]);
- g_assert(id[2]);
+ g_assert((id[0] = nfc_adapter_add_tag_added_handler(adapter,
+ test_adapter_tag_inc, &tag_added)));
+ g_assert((id[1] = nfc_adapter_add_tag_removed_handler(adapter,
+ test_adapter_tag_inc, &tag_removed)));
+ g_assert((id[2] = nfc_adapter_add_target_presence_handler(adapter,
+ test_adapter_inc, &presence_changed_count)));
/* Set up the adapter */
nfc_adapter_set_name(adapter, "test");
@@ -736,15 +750,12 @@
nfc_adapter_mode_notify(adapter, NFC_MODE_P2P_TARGET, FALSE);
g_assert(!adapter->target_present);
- id[0] = nfc_adapter_add_peer_added_handler(adapter,
- test_adapter_peer_inc, &peer_added);
- id[1] = nfc_adapter_add_peer_removed_handler(adapter,
- test_adapter_peer_inc, &peer_removed);
- id[2] = nfc_adapter_add_target_presence_handler(adapter,
- test_adapter_inc, &presence_changed_count);
- g_assert(id[0]);
- g_assert(id[1]);
- g_assert(id[2]);
+ g_assert((id[0] = nfc_adapter_add_peer_added_handler(adapter,
+ test_adapter_peer_inc, &peer_added)));
+ g_assert((id[1] = nfc_adapter_add_peer_removed_handler(adapter,
+ test_adapter_peer_inc, &peer_removed)));
+ g_assert((id[2] = nfc_adapter_add_target_presence_handler(adapter,
+ test_adapter_inc, &presence_changed_count)));
/* Two peers are unlikely in real life but API allows it */
peer0 = nfc_adapter_add_peer_initiator_a(adapter, target0, NULL,
@@ -820,15 +831,12 @@
nfc_adapter_mode_notify(adapter, NFC_MODE_P2P_TARGET, FALSE);
g_assert(!adapter->target_present);
- id[0] = nfc_adapter_add_peer_added_handler(adapter,
- test_adapter_peer_inc, &peer_added);
- id[1] = nfc_adapter_add_peer_removed_handler(adapter,
- test_adapter_peer_inc, &peer_removed);
- id[2] = nfc_adapter_add_target_presence_handler(adapter,
- test_adapter_inc, &presence_changed_count);
- g_assert(id[0]);
- g_assert(id[1]);
- g_assert(id[2]);
+ g_assert((id[0] = nfc_adapter_add_peer_added_handler(adapter,
+ test_adapter_peer_inc, &peer_added)));
+ g_assert((id[1] = nfc_adapter_add_peer_removed_handler(adapter,
+ test_adapter_peer_inc, &peer_removed)));
+ g_assert((id[2] = nfc_adapter_add_target_presence_handler(adapter,
+ test_adapter_inc, &presence_changed_count)));
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_host/Makefile
^
|
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_core_host
+
+COMMON_SRC = test_main.c test_host_app.c test_host_service.c test_initiator.c
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_host/test_core_host.c
^
|
@@ -0,0 +1,1607 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_host_p.h"
+#include "nfc_host_app_p.h"
+#include "nfc_host_service_p.h"
+#include "nfc_initiator_impl.h"
+#include "nfc_initiator_p.h"
+
+#include "test_common.h"
+#include "test_host_app.h"
+#include "test_host_service.h"
+#include "test_initiator.h"
+
+#include <gutil_log.h>
+#include <gutil_misc.h>
+
+static TestOpt test_opt;
+
+static
+void
+test_host_inc(
+ NfcHost* host,
+ void* user_data)
+{
+ int* counter = user_data;
+
+ (*counter)++;
+}
+
+static
+void
+test_host_not_reached(
+ NfcHost* host,
+ void* loop)
+{
+ g_assert_not_reached();
+}
+
+static
+void
+test_host_done_quit(
+ NfcHost* host,
+ void* loop)
+{
+ g_assert(!host->initiator->present);
+ GDEBUG("%s is gone", host->name);
+ g_main_loop_quit((GMainLoop*)loop);
+}
+
+static
+void
+test_app_selected_once(
+ NfcHost* host,
+ void* user_data)
+{
+ NfcHostApp** selected = user_data;
+
+ g_assert(host->app);
+ GDEBUG("%s selected", host->app->name);
+ g_assert(!*selected);
+ *selected = nfc_host_app_ref(host->app);
+}
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null(
+ void)
+{
+ /* Public interfaces are NULL tolerant */
+ g_assert(!nfc_host_ref(NULL));
+ g_assert(!nfc_host_add_gone_handler(NULL, NULL, NULL));
+ g_assert(!nfc_host_add_app_changed_handler(NULL, NULL, NULL));
+ g_assert(!nfc_host_app_ref(NULL));
+ g_assert(!nfc_host_service_ref(NULL));
+
+ nfc_host_app_unref(NULL);
+ nfc_host_service_unref(NULL);
+ nfc_host_remove_handler(NULL, 0);
+ nfc_host_remove_handlers(NULL, NULL, 0);
+ nfc_host_deactivate(NULL);
+ nfc_host_unref(NULL);
+}
+
+/*==========================================================================*
+ * basic
+ *==========================================================================*/
+
+static
+void
+test_basic(
+ void)
+{
+ static const guchar cmd_select1[] = {
+ /* Non-existent app */
+ 0x00, 0xA4, 0x04, 0x00, 0x07, 0xd2, 0x76, 0x00,
+ 0x00, 0x85, 0x01, 0x01, 0x00
+ };
+ static const guchar resp_not_found[] = { 0x6a, 0x82 };
+ static const TestTx tx[] = {
+ {
+ { TEST_ARRAY_AND_SIZE(cmd_select1) },
+ { TEST_ARRAY_AND_SIZE(resp_not_found) }
+ }
+ };
+ const char* name = "TestHost";
+ NfcInitiator* init = test_initiator_new_with_tx(TEST_ARRAY_AND_COUNT(tx));
+ NfcHost* host = nfc_host_new(name, init, NULL, NULL);
+ GMainLoop* loop = g_main_loop_new(NULL, TRUE);
+ gulong id = nfc_host_add_gone_handler(host, test_host_done_quit, loop);
+
+ g_assert(host);
+ g_assert(nfc_host_ref(host) == host);
+ g_assert_cmpstr(host->name, == ,name);
+ nfc_host_unref(host);
+
+ /* Callback is required */
+ g_assert(!nfc_host_add_gone_handler(host, NULL, NULL));
+ g_assert(!nfc_host_add_app_changed_handler(host, NULL, NULL));
+
+ test_run(&test_opt, loop);
+
+ g_main_loop_unref(loop);
+ nfc_initiator_unref(init);
+ nfc_host_remove_handler(host, id);
+ nfc_host_remove_handler(host, 0); /* Zero id is ignored */
+ nfc_host_unref(host);
+}
+
+/*==========================================================================*
+ * service
+ *==========================================================================*/
+
+static
+void
+test_service(
+ void)
+{
+ NfcInitiator* initiator = test_initiator_new();
+ TestHostService* test = test_host_service_new("TestService");
+ NfcHostService* service = NFC_HOST_SERVICE(test);
+ NfcHostService* services[2];
+ NfcHostApp* apps[1];
+ NfcHost* host;
+
+ services[0] = service;
+ services[1] = NULL;
+ apps[0] = NULL;
+ host = nfc_host_new("TestHost", initiator, services, apps);
+
+ nfc_host_start(host);
+ nfc_host_deactivate(host);
+
+ /* We don't actually let the service to get started */
+ g_assert_cmpint(test->start, == ,0);
+
+ /* These ids get ignored */
+ nfc_host_service_cancel(service, NFCD_ID_FAIL);
+ nfc_host_service_cancel(service, NFCD_ID_SYNC);
+
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_initiator/test_core_initiator.c
^
|
@@ -10,23 +10,27 @@
*
* 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -39,6 +43,7 @@
#include "nfc_initiator_impl.h"
#include <gutil_log.h>
+#include <gutil_misc.h>
static TestOpt test_opt;
@@ -101,9 +106,9 @@
} TestInitiator1;
-#define TEST_TYPE_INITIATOR1 (test_initiator1_get_type())
-#define TEST_INITIATOR1(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
- TEST_TYPE_INITIATOR1, TestInitiator1))
+#define TEST_TYPE_INITIATOR1 test_initiator1_get_type()
+#define TEST_INITIATOR1(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \
+ TEST_TYPE_INITIATOR1, TestInitiator1)
#define PARENT_CLASS test_initiator1_parent_class
G_DEFINE_TYPE(TestInitiator1, test_initiator1, NFC_TYPE_INITIATOR)
@@ -116,7 +121,7 @@
{
TestInitiator1* self = TEST_INITIATOR1(initiator);
- g_ptr_array_add(self->resp, test_alloc_data(data, len));
+ g_ptr_array_add(self->resp, gutil_data_new(data, len));
if (self->flags & TEST_INITIATOR_FAIL_RESPONSE) {
/* Default callback return FALSE */
return NFC_INITIATOR_CLASS(test_initiator1_parent_class)->respond
@@ -198,6 +203,8 @@
g_assert(!nfc_initiator_ref(NULL));
g_assert(!nfc_initiator_add_transmission_handler(NULL, NULL, NULL));
g_assert(!nfc_initiator_add_transmission_handler(init, NULL, NULL));
+ g_assert(!nfc_initiator_add_reactivated_handler(init, NULL, NULL));
+ g_assert(!nfc_initiator_add_reactivated_handler(NULL, NULL, NULL));
g_assert(!nfc_initiator_add_gone_handler(init, NULL, NULL));
g_assert(!nfc_initiator_add_gone_handler(NULL, NULL, NULL));
nfc_initiator_deactivate(NULL);
@@ -208,6 +215,7 @@
nfc_initiator_transmit(NULL, NULL, 0);
nfc_initiator_response_sent(NULL, NFC_TRANSMIT_STATUS_ERROR);
nfc_initiator_gone(NULL);
+ nfc_initiator_reactivated(NULL);
nfc_initiator_unref(NULL);
g_assert(!nfc_transmission_respond_bytes(NULL, NULL, NULL, NULL));
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_manager/Makefile
^
|
@@ -2,6 +2,6 @@
EXE = test_core_manager
-COMMON_SRC = test_main.c test_service.c
+COMMON_SRC = test_main.c test_host_app.c test_host_service.c test_service.c
include ../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_manager/test_core_manager.c
^
|
@@ -10,31 +10,37 @@
*
* 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
* any official policies, either expressed or implied.
*/
-#include "test_service.h"
#include "test_common.h"
+#include "test_service.h"
+#include "test_host_app.h"
+#include "test_host_service.h"
#include "nfc_manager_p.h"
#include "internal/nfc_manager_i.h"
@@ -74,6 +80,8 @@
gboolean power_requested;
gboolean mode_request_pending;
NFC_MODE mode_requested;
+ NFC_TECHNOLOGY supported_techs;
+ NFC_TECHNOLOGY allowed_techs;
} TestAdapter;
G_DEFINE_TYPE(TestAdapter, test_adapter, NFC_TYPE_ADAPTER)
@@ -151,11 +159,30 @@
}
static
+NFC_TECHNOLOGY
+test_adapter_get_supported_techs(
+ NfcAdapter* adapter)
+{
+ return TEST_ADAPTER(adapter)->supported_techs;
+}
+
+static
+void
+test_adapter_set_allowed_techs(
+ NfcAdapter* adapter,
+ NFC_TECHNOLOGY techs)
+{
+ TEST_ADAPTER(adapter)->allowed_techs = techs;
+}
+
+static
void
test_adapter_init(
TestAdapter* self)
{
self->adapter.supported_modes = NFC_MODE_READER_WRITER;
+ self->allowed_techs = self->supported_techs =
+ NFC_TECHNOLOGY_A | NFC_TECHNOLOGY_B;
}
static
@@ -167,6 +194,8 @@
klass->cancel_power_request = test_adapter_cancel_power_request;
klass->submit_mode_request = test_adapter_submit_mode_request;
klass->cancel_mode_request = test_adapter_cancel_mode_request;
+ klass->get_supported_techs = test_adapter_get_supported_techs;
+ klass->set_allowed_techs = test_adapter_set_allowed_techs;
}
/*==========================================================================*
@@ -180,7 +209,6 @@
{
/* Public interfaces are NULL tolerant */
g_assert(!nfc_manager_ref(NULL));
- g_assert(!nfc_manager_start(NULL));
g_assert(!nfc_manager_plugins(NULL));
g_assert(!nfc_manager_get_adapter(NULL, NULL));
g_assert(!nfc_manager_add_adapter(NULL, NULL));
@@ -190,20 +218,33 @@
g_assert(!nfc_manager_add_service_unregistered_handler(NULL, NULL, NULL));
g_assert(!nfc_manager_add_enabled_changed_handler(NULL, NULL, NULL));
g_assert(!nfc_manager_add_mode_changed_handler(NULL, NULL, NULL));
+ g_assert(!nfc_manager_add_techs_changed_handler(NULL, NULL, NULL));
g_assert(!nfc_manager_add_stopped_handler(NULL, NULL, NULL));
g_assert(!nfc_manager_mode_request_new(NULL, 0, 0));
+ g_assert(!nfc_manager_tech_request_new(NULL, 0, 0));
nfc_manager_mode_request_free(NULL);
+ nfc_manager_tech_request_free(NULL);
nfc_manager_stop(NULL, 0);
nfc_manager_set_enabled(NULL, FALSE);
nfc_manager_request_power(NULL, FALSE);
nfc_manager_request_mode(NULL, NFC_MODE_NONE);
+ nfc_manager_register_host_app(NULL, NULL);
+ nfc_manager_register_host_service(NULL, NULL);
nfc_manager_register_service(NULL, NULL);
+ nfc_manager_unregister_host_app(NULL, NULL);
+ nfc_manager_unregister_host_service(NULL, NULL);
nfc_manager_unregister_service(NULL, NULL);
nfc_manager_remove_adapter(NULL, NULL);
nfc_manager_remove_handler(NULL, 0);
nfc_manager_remove_handlers(NULL, NULL, 0);
nfc_manager_unref(NULL);
+
+ /* The internal APIs are NULL tolerant too */
+ g_assert(!nfc_manager_start(NULL));
+ g_assert(!nfc_manager_peer_services(NULL));
+ g_assert(!nfc_manager_host_services(NULL));
+ g_assert(!nfc_manager_host_apps(NULL));
}
/*==========================================================================*
@@ -402,10 +443,11 @@
g_assert_cmpint(count, == ,1);
count = 0;
- /* Try to disable those but they stay enabled */
+ /* Disable P2P (last submitted request takes precedence) */
disable_p2p = nfc_manager_mode_request_new(manager, 0, NFC_MODES_P2P);
- g_assert_cmpint(manager->mode, == ,NFC_MODES_P2P | NFC_MODE_READER_WRITER);
- g_assert_cmpint(count, == ,0);
+ g_assert_cmpint(manager->mode, == ,NFC_MODE_READER_WRITER);
+ g_assert_cmpint(count, == ,1);
+ count = 0;
/* Add another enable request on top of that */
enable_all = nfc_manager_mode_request_new(manager, NFC_MODES_ALL, 0);
@@ -418,8 +460,13 @@
g_assert_cmpint(manager->mode, == , NFC_MODES_ALL);
g_assert_cmpint(count, == ,0);
- /* P2P modes get disabled when we release enable_p2p request */
- nfc_manager_mode_request_free(enable_p2p);
+ /* Removing disable_p2p request makes no difference */
+ nfc_manager_mode_request_free(disable_p2p);
+ g_assert_cmpint(manager->mode, == , NFC_MODES_ALL);
+ g_assert_cmpint(count, == ,0);
+
+ /* But submitting a new one does */
+ disable_p2p = nfc_manager_mode_request_new(manager, 0, NFC_MODES_P2P);
g_assert_cmpint(manager->mode, == ,NFC_MODE_READER_WRITER |
NFC_MODE_CARD_EMULATION);
g_assert_cmpint(count, == ,1);
@@ -437,6 +484,8 @@
g_assert_cmpint(count, == ,0);
/* We are back to the default when all requests are released */
+ nfc_manager_mode_request_free(enable_p2p);
+ g_assert_cmpint(count, == ,0);
nfc_manager_mode_request_free(enable_all2);
g_assert_cmpint(manager->mode, == , NFC_MODE_READER_WRITER);
g_assert_cmpint(count, == ,1);
@@ -447,6 +496,100 @@
}
/*==========================================================================*
+ * tech
+ *==========================================================================*/
+
+static
+void
+test_tech(
+ void)
+{
+ NfcPluginsInfo pi;
+ NfcManager* manager;
+ TestAdapter* adapter = test_adapter_new();
+ const char* adapter_name;
+ NfcTechRequest* disable_b;
+ NfcTechRequest* disable_a;
+ NfcTechRequest* enable_b1;
+ NfcTechRequest* enable_b2;
+ int count = 0;
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_peer_socket/test_core_peer_socket.c
^
|
@@ -1,33 +1,36 @@
/*
+ * Copyright (C) 2020-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
+ * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "nfc_types_p.h"
@@ -45,6 +48,7 @@
#include "test_common.h"
#include <gutil_log.h>
+#include <gutil_misc.h>
#include <sys/socket.h>
#include <unistd.h>
@@ -312,7 +316,7 @@
const void* bytes,
guint len)
{
- g_ptr_array_add(self->cmd_resp, test_alloc_data(bytes, len));
+ g_ptr_array_add(self->cmd_resp, gutil_data_new(bytes, len));
}
/*==========================================================================*
@@ -808,7 +812,7 @@
nfc_peer_connection_ref(pc);
test->connection_state_id = nfc_peer_connection_add_state_changed_handler
(pc, test_connection_dead_quit_loop_cb, test->loop);
-
+
fd = nfc_peer_socket_fd(socket);
g_assert(fd >= 0);
g_assert(fcntl(fd, F_SETFL, O_NONBLOCK) >= 0);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_snep/test_core_snep.c
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2020-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "nfc_types_p.h"
@@ -42,6 +49,7 @@
#include "test_common.h"
#include <gutil_log.h>
+#include <gutil_misc.h>
static TestOpt test_opt;
@@ -191,7 +199,7 @@
TestTarget* self,
const GUtilData* data)
{
- g_ptr_array_add(self->cmd_resp, test_clone_data(data));
+ g_ptr_array_add(self->cmd_resp, gutil_data_copy(data));
}
static
@@ -201,7 +209,7 @@
const void* bytes,
guint len)
{
- g_ptr_array_add(self->cmd_resp, test_alloc_data(bytes, len));
+ g_ptr_array_add(self->cmd_resp, gutil_data_new(bytes, len));
}
/*==========================================================================*
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_tag_t4/test_core_tag_t4.c
^
|
@@ -1,34 +1,41 @@
/*
+ * Copyright (C) 2019-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
*
- * 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "nfc_tag_p.h"
@@ -40,6 +47,7 @@
#include "test_target.h"
#include <gutil_log.h>
+#include <gutil_misc.h>
static TestOpt test_opt;
@@ -857,7 +865,7 @@
for (i = 0; i < test->count; i++) {
g_ptr_array_add(test_target->cmd_resp,
- test_clone_data(test->cmd_resp + i));
+ gutil_data_copy(test->cmd_resp + i));
}
test_target->fail_transmit = test->fail_transmit;
@@ -1093,360 +1101,6 @@
}
/*==========================================================================*
- * Encode
- *==========================================================================*/
-
-static
-void
-test_encode_fail(
- void)
-{
- GByteArray* a = g_byte_array_new();
-
- /* Invalid Lc (pointer is ignored) */
- g_assert(!nfc_tag_t4_build_apdu(a, 0, 0, 0, 0, 65536, NULL, 0));
-
- /* Invalid Le */
- g_assert(!nfc_tag_t4_build_apdu(a, 0, 0, 0, 0, 0, NULL, 65537));
-
- g_byte_array_free(a, TRUE);
-}
-
-/* Case 1: |CLA|INS|P1|P2|
- * Lc = 0, Le = 0, n = 4 */
-static
-void
-test_encode_case1(
- void)
-{ /* CLA INS P1 P2 */
- static const guint8 expect[] = { 0x01, 0x02, 0x03, 0x04 };
- GByteArray* a = g_byte_array_new();
-
- g_assert(nfc_tag_t4_build_apdu(a, 0x01, 0x02, 0x03, 0x04, 0, NULL, 0));
- g_assert_cmpuint(a->len, == ,sizeof(expect));
- g_assert(!memcmp(a->data, TEST_ARRAY_AND_SIZE(expect)));
- g_byte_array_free(a, TRUE);
-}
-
-/* Case 2s: |CLA|INS|P1|P2|LE|
- * Lc = 0, Le = 1..256, n = 5) */
-static
-void
-test_encode_case2s(
- void)
-{ /* CLA INS P1 P2 LE */
- static const guint8 le_1[] = { 0x01, 0x02, 0x03, 0x04, 0x01 };
- static const guint8 le_255[] = { 0x01, 0x02, 0x03, 0x04, 0xff };
- static const guint8 le_256[] = { 0x01, 0x02, 0x03, 0x04, 0x00 };
- GByteArray* a = g_byte_array_new();
-
- g_assert(nfc_tag_t4_build_apdu(a, 0x01, 0x02, 0x03, 0x04, 0, NULL, 1));
- g_assert_cmpuint(a->len, == ,sizeof(le_1));
- g_assert(!memcmp(a->data, TEST_ARRAY_AND_SIZE(le_1)));
-
- g_assert(nfc_tag_t4_build_apdu(a, 0x01, 0x02, 0x03, 0x04, 0, NULL, 255));
- g_assert_cmpuint(a->len, == ,sizeof(le_255));
- g_assert(!memcmp(a->data, TEST_ARRAY_AND_SIZE(le_255)));
-
- g_assert(nfc_tag_t4_build_apdu(a, 0x01, 0x02, 0x03, 0x04, 0, NULL, 256));
- g_assert_cmpuint(a->len, == ,sizeof(le_256));
- g_assert(!memcmp(a->data, TEST_ARRAY_AND_SIZE(le_256)));
-
- g_byte_array_free(a, TRUE);
-}
-
-/* Case 2e: |CLA|INS|P1|P2|00|LE1|LE2|
- * Lc = 0, Le = 257..65536, n = 7 */
-static
-void
-test_encode_case2e(
- void)
-{
- static const guint8 le_257[] =
- /* CLA INS P1 P2 00 LE1 LE2 */
- { 0x01, 0x02, 0x03, 0x04, 0x00, 0x01, 0x01 };
- static const guint8 le_65535[] =
- { 0x01, 0x02, 0x03, 0x04, 0x00, 0xff, 0xff };
- static const guint8 le_65536[] =
- { 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00 };
- GByteArray* a = g_byte_array_new();
-
- g_assert(nfc_tag_t4_build_apdu(a, 0x01, 0x02, 0x03, 0x04, 0, NULL, 257));
- g_assert_cmpuint(a->len, == ,sizeof(le_257));
- g_assert(!memcmp(a->data, TEST_ARRAY_AND_SIZE(le_257)));
-
- g_assert(nfc_tag_t4_build_apdu(a, 0x01, 0x02, 0x03, 0x04, 0, NULL, 65535));
- g_assert_cmpuint(a->len, == ,sizeof(le_65535));
- g_assert(!memcmp(a->data, TEST_ARRAY_AND_SIZE(le_65535)));
-
- g_assert(nfc_tag_t4_build_apdu(a, 0x01, 0x02, 0x03, 0x04, 0, NULL, 65536));
- g_assert_cmpuint(a->len, == ,sizeof(le_65536));
- g_assert(!memcmp(a->data, TEST_ARRAY_AND_SIZE(le_65536)));
-
- g_byte_array_free(a, TRUE);
-}
-
-/* Case 3s: |CLA|INS|P1|P2|LC|...BODY...|
- * Lc = 1..255, n = 6..260 */
-static
-void
-test_encode_case3s(
- void)
-{
- static const guint8 lc_2[] =
- /* CLA INS P1 P2 LC BODY... */
- { 0x01, 0x02, 0x03, 0x04, 0x02, 0x05, 0x06 };
- static const guint8 lc_255[] =
- { 0x01, 0x02, 0x03, 0x04, 0xff,
- 0x00, 0x01, 0x02, 0x03, 0x03, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x13, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
- 0x20, 0x21, 0x22, 0x23, 0x23, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
- 0x30, 0x31, 0x32, 0x33, 0x33, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
- 0x40, 0x41, 0x42, 0x43, 0x43, 0x45, 0x46, 0x47,
- 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
- 0x50, 0x51, 0x52, 0x53, 0x53, 0x55, 0x56, 0x57,
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/core_util/test_core_util.c
^
|
@@ -103,6 +103,515 @@
}
/*==========================================================================*
+ * apdu/encode/fail
+ *==========================================================================*/
+
+static
+void
+test_apdu_encode_fail(
+ void)
+{
+ static const NfcApdu apdu1 =
+ { 0x01, 0x02, 0x03, 0x04, { NULL, 0x10000 }, 0 };
+ static const NfcApdu apdu2 =
+ { 0x01, 0x02, 0x03, 0x04, { NULL, 0 }, 0x10001 };
+ GByteArray* buf = g_byte_array_new();
+
+ g_assert(!nfc_apdu_encode(buf, &apdu1));
+ g_assert_cmpuint(buf->len, == ,0);
+
+ g_assert(!nfc_apdu_encode(buf, &apdu2));
+ g_assert_cmpuint(buf->len, == ,0);
+
+ g_byte_array_free(buf, TRUE);
+}
+
+/*==========================================================================*
+ * apdu/decode/fail
+ *==========================================================================*/
+
+static
+void
+test_apdu_decode_fail(
+ void)
+{
+ static const guint8 not_enough_data[] = {
+ 0x01, 0x02, 0x03
+ };
+ static const GUtilData not_enough = {
+ TEST_ARRAY_AND_SIZE(not_enough_data)
+ };
+ static const guint8 too_much_1_data[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x00
+ /* nfc_apdu_decode doesn't read beyond that */
+ };
+ static const GUtilData too_much_1 = {
+ too_much_1_data, 65545
+ };
+ static const guint8 too_much_2_data[] = {
+ 0x01, 0x02, 0x03, 0x04, 0xff
+ /* nfc_apdu_decode doesn't read beyond that */
+ };
+ static const GUtilData too_much_2 = {
+ too_much_2_data, 262
+ };
+ static const guint8 wrong_lc_1_data[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x00, 0xcc, 0xcc, 0xdd
+ };
+ static const GUtilData wrong_lc_1 = {
+ TEST_ARRAY_AND_SIZE(wrong_lc_1_data)
+ };
+ static const guint8 wrong_lc_2_data[] = {
+ 0x01, 0x02, 0x03, 0x04, 0xff, 0x01
+ };
+ static const GUtilData wrong_lc_2 = {
+ TEST_ARRAY_AND_SIZE(wrong_lc_2_data)
+ };
+ NfcApdu apdu;
+
+ g_assert(!nfc_apdu_decode(&apdu, ¬_enough));
+ g_assert(!nfc_apdu_decode(&apdu, &too_much_1));
+ g_assert(!nfc_apdu_decode(&apdu, &too_much_2));
+ g_assert(!nfc_apdu_decode(&apdu, &wrong_lc_1));
+ g_assert(!nfc_apdu_decode(&apdu, &wrong_lc_2));
+}
+
+/*==========================================================================*
+ * apdu/encode
+ * apdu/decode
+ *==========================================================================*/
+
+typedef struct test_apdu_encode_data {
+ const char* name;
+ NfcApdu apdu;
+ GUtilData encoded;
+} TestApduEncodeData;
+
+/* Case 1: |CLA|INS|P1|P2|
+ * Lc = 0, Le = 0, n = 4 */
+static const guint8 test_apdu_encoded_case1[] = {
+ /* CLA INS P1 P2 */
+ 0x01, 0x02, 0x03, 0x04
+};
+
+/* Case 2s: |CLA|INS|P1|P2|LE|
+ * Lc = 0, Le = 1..256, n = 5) */
+static const guint8 test_apdu_encoded_case2s_le_1[] = {
+ /* CLA INS P1 P2 LE */
+ 0x01, 0x02, 0x03, 0x04, 0x01
+};
+static const guint8 test_apdu_encoded_case2s_le_255[] = {
+ 0x01, 0x02, 0x03, 0x04, 0xff
+};
+static const guint8 test_apdu_encoded_case2s_le_256[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x00
+};
+
+/* Case 2e: |CLA|INS|P1|P2|00|LE1|LE2|
+ * Lc = 0, Le = 257..65536, n = 7 */
+static const guint8 test_apdu_encoded_case2e_le_257[] = {
+ /* CLA INS P1 P2 00 LE1 LE2 */
+ 0x01, 0x02, 0x03, 0x04, 0x00, 0x01, 0x01
+};
+static const guint8 test_apdu_encoded_case2e_le_512[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x00, 0x02, 0x00
+};
+static const guint8 test_apdu_encoded_case2e_le_65535[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x00, 0xff, 0xff
+};
+static const guint8 test_apdu_encoded_case2e_le_65536[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00
+};
+
+/* Case 3s: |CLA|INS|P1|P2|LC|...BODY...|
+ * Lc = 1..255, n = 6..260 */
+static const guint8 test_apdu_encoded_case3s_lc_2[] = {
+ /* CLA INS P1 P2 LC BODY... */
+ 0x01, 0x02, 0x03, 0x04, 0x02, 0x05, 0x06
+};
+static const guint8 test_apdu_encoded_case3s_lc_255[] = {
+ 0x01, 0x02, 0x03, 0x04, 0xff, 0x00, 0x01, 0x02,
+ 0x03, 0x03, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
+ 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
+ 0x13, 0x13, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
+ 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22,
+ 0x23, 0x23, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a,
+ 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32,
+ 0x33, 0x33, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a,
+ 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42,
+ 0x43, 0x43, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a,
+ 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52,
+ 0x53, 0x53, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
+ 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62,
+ 0x63, 0x63, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a,
+ 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72,
+ 0x73, 0x73, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
+ 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82,
+ 0x83, 0x83, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a,
+ 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92,
+ 0x93, 0x93, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a,
+ 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2,
+ 0xa3, 0xa3, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa,
+ 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2,
+ 0xb3, 0xb3, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba,
+ 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2,
+ 0xc3, 0xc3, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca,
+ 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2,
+ 0xd3, 0xd3, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
+ 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2,
+ 0xe3, 0xe3, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
+ 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2,
+ 0xf3, 0xf3, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
+ 0xfb, 0xfc, 0xfd, 0xfe
+};
+
+/* Case 3e: |CLA|INS|P1|P2|00|LC1|LC2|...BODY...|
+ * Lc = 1..65535, n = 8..65542 */
+static const guint8 test_apdu_encoded_case3e_lc_256[] = {
+ /* CLA INS P1 P2 00 LC1 LC2 BODY... */
+ 0x01, 0x02, 0x03, 0x04, 0x00, 0x01, 0x00, 0x00,
+ 0x01, 0x02, 0x03, 0x03, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+ 0x11, 0x12, 0x13, 0x13, 0x15, 0x16, 0x17, 0x18,
+ 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
+ 0x21, 0x22, 0x23, 0x23, 0x25, 0x26, 0x27, 0x28,
+ 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
+ 0x31, 0x32, 0x33, 0x33, 0x35, 0x36, 0x37, 0x38,
+ 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
+ 0x41, 0x42, 0x43, 0x43, 0x45, 0x46, 0x47, 0x48,
+ 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
+ 0x51, 0x52, 0x53, 0x53, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60,
+ 0x61, 0x62, 0x63, 0x63, 0x65, 0x66, 0x67, 0x68,
+ 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
+ 0x71, 0x72, 0x73, 0x73, 0x75, 0x76, 0x77, 0x78,
+ 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80,
+ 0x81, 0x82, 0x83, 0x83, 0x85, 0x86, 0x87, 0x88,
+ 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90,
+ 0x91, 0x92, 0x93, 0x93, 0x95, 0x96, 0x97, 0x98,
+ 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0,
+ 0xa1, 0xa2, 0xa3, 0xa3, 0xa5, 0xa6, 0xa7, 0xa8,
+ 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0,
+ 0xb1, 0xb2, 0xb3, 0xb3, 0xb5, 0xb6, 0xb7, 0xb8,
+ 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0,
+ 0xc1, 0xc2, 0xc3, 0xc3, 0xc5, 0xc6, 0xc7, 0xc8,
+ 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
+ 0xd1, 0xd2, 0xd3, 0xd3, 0xd5, 0xd6, 0xd7, 0xd8,
+ 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0,
+ 0xe1, 0xe2, 0xe3, 0xe3, 0xe5, 0xe6, 0xe7, 0xe8,
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/coverage/run
^
|
@@ -7,6 +7,7 @@
core_adapter \
core_config \
core_crc \
+core_host \
core_initiator \
core_llc \
core_llc_param \
@@ -35,7 +36,10 @@
plugins_dbus_handlers_type_text \
plugins_dbus_handlers_type_uri \
plugins_dbus_service_adapter \
+plugins_dbus_service_host \
plugins_dbus_service_isodep \
+plugins_dbus_service_local_app \
+plugins_dbus_service_local_host \
plugins_dbus_service_ndef \
plugins_dbus_service_peer \
plugins_dbus_service_plugin \
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/plugins_dbus_service_adapter/test_plugins_dbus_service_adapter.c
^
|
@@ -1,38 +1,45 @@
/*
+ * Copyright (C) 2019-2023 Slava Monich <slava@monich.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:
+ * You may use this file under the terms of the 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.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
*
- * 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "nfc_adapter_p.h"
-#include "nfc_plugins.h"
#include "nfc_adapter_impl.h"
+#include "nfc_host.h"
#include "nfc_peer.h"
#include "nfc_initiator_impl.h"
#include "nfc_target_impl.h"
@@ -49,7 +56,7 @@
#include "test_dbus.h"
#define NFC_ADAPTER_INTERFACE "org.sailfishos.nfc.Adapter"
-#define NFC_ADAPTER_INTERFACE_VERSION (2)
+#define NFC_ADAPTER_INTERFACE_VERSION (3)
static TestOpt test_opt;
@@ -57,12 +64,13 @@
GMainLoop* loop;
NfcManager* manager;
NfcAdapter* adapter;
- NfcInitiator* initiator;
DBusServiceAdapter* service;
+ GDBusConnection* client; /* Owned by TestDBus */
+ void* ext;
} TestData;
static
-void
+TestData*
test_data_init(
TestData* test)
{
@@ -74,6 +82,7 @@
g_assert((test->adapter = test_adapter_new()) != NULL);
g_assert(nfc_manager_add_adapter(test->manager, test->adapter));
test->loop = g_main_loop_new(NULL, TRUE);
+ return test;
}
static
@@ -83,25 +92,63 @@
{
nfc_adapter_unref(test->adapter);
nfc_manager_unref(test->manager);
- nfc_initiator_unref(test->initiator);
dbus_service_adapter_free(test->service);
g_main_loop_unref(test->loop);
}
static
void
-test_start_and_get(
+test_started(
+ TestData* test,
+ GDBusConnection* client,
+ GDBusConnection* server)
+{
+ test->client = client;
+ test->service = dbus_service_adapter_new(test->adapter, server);
+ g_assert(test->service);
+}
+
+static
+void
+test_call(
+ TestData* test,
+ const char* method,
+ GVariant* args,
+ GAsyncReadyCallback callback)
+{
+ g_assert(test->client);
+ g_assert(test->service);
+ g_dbus_connection_call(test->client, NULL,
+ dbus_service_adapter_path(test->service),
+ NFC_ADAPTER_INTERFACE, method, NULL, NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, callback, test);
+}
+
+static
+void
+test_start_call(
TestData* test,
GDBusConnection* client,
GDBusConnection* server,
const char* method,
GAsyncReadyCallback callback)
{
- test->service = dbus_service_adapter_new(test->adapter, server);
+ test_started(test, client, server);
+ test_call(test, method, NULL, callback);
+}
+
+static
+void
+test_signal_subscribe(
+ TestData* test,
+ const char* name,
+ GDBusSignalCallback handler)
+{
+ g_assert(test->client);
g_assert(test->service);
- g_dbus_connection_call(client, NULL,
- dbus_service_adapter_path(test->service), NFC_ADAPTER_INTERFACE,
- method, NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, callback, test);
+ g_assert(g_dbus_connection_signal_subscribe(test->client, NULL,
+ NFC_ADAPTER_INTERFACE, name, dbus_service_adapter_path(test->service),
+ NULL, G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE, handler, test, NULL));
}
/*==========================================================================*
@@ -131,8 +178,7 @@
TestData* test = user_data;
const char* path;
- test->service = dbus_service_adapter_new(test->adapter, server);
- g_assert(test->service);
+ test_started(test, client, server);
path = dbus_service_adapter_path(test->service);
g_assert(path);
g_assert(path[0] == '/');
@@ -180,10 +226,10 @@
g_assert(var);
g_variant_get(var, "(ibbuub^ao)", &version, &enabled, &powered,
&modes, &mode, &target_present, &tags);
- GDEBUG("version=%d, enabled=%d, powered=%d, modes=%0x04X, mode=0x%04X, "
+ GDEBUG("version=%d, enabled=%d, powered=%d, modes=0x%04X, mode=0x%04X, "
"target_present=%d, %u tags", version, enabled, powered, modes, mode,
target_present, g_strv_length(tags));
- g_assert(version >= NFC_ADAPTER_INTERFACE_VERSION);
+ g_assert_cmpint(version, >= ,NFC_ADAPTER_INTERFACE_VERSION);
g_assert(enabled);
g_assert(!powered);
g_assert(!target_present);
@@ -200,7 +246,7 @@
GDBusConnection* server,
void* user_data)
{
- test_start_and_get((TestData*)user_data, client, server,
+ test_start_call((TestData*)user_data, client, server,
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/plugins_dbus_service_host/Makefile
^
|
@@ -0,0 +1,8 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_plugins_dbus_service_host
+
+COMMON_SRC = test_main.c test_adapter.c test_initiator.c \
+ test_dbus.c test_dbus_name.c
+
+include ../common/Makefile.plugins
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/plugins_dbus_service_host/test_plugins_dbus_service_host.c
^
|
@@ -0,0 +1,488 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
+ * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_initiator_p.h"
+#include "nfc_adapter.h"
+#include "nfc_host.h"
+
+#include "internal/nfc_manager_i.h"
+
+#include <gutil_log.h>
+#include <gutil_misc.h>
+#include <gutil_idlepool.h>
+
+#include "dbus_service/dbus_service.h"
+
+#include "test_common.h"
+#include "test_adapter.h"
+#include "test_initiator.h"
+#include "test_dbus.h"
+#include "test_dbus_name.h"
+
+#define NFC_HOST_INTERFACE "org.sailfishos.nfc.Host"
+#define NFC_HOST_INTERFACE_VERSION (1)
+
+static TestOpt test_opt;
+
+#define TEST_DBUS_TIMEOUT \
+ ((test_opt.flags & TEST_FLAG_DEBUG) ? -1 : TEST_TIMEOUT_MS)
+
+typedef struct test_data {
+ GMainLoop* loop;
+ NfcManager* manager;
+ NfcAdapter* adapter;
+ NfcInitiator* initiator;
+ DBusServiceAdapter* service;
+ GDBusConnection* server;
+ GDBusConnection* client;
+ GUtilIdlePool* pool;
+} TestData;
+
+static
+void
+test_data_init(
+ TestData* test)
+{
+ NfcPluginsInfo pi;
+
+ memset(test, 0, sizeof(*test));
+ memset(&pi, 0, sizeof(pi));
+ g_assert((test->manager = nfc_manager_new(&pi)) != NULL);
+ g_assert((test->adapter = test_adapter_new()) != NULL);
+ test->adapter->supported_modes |= NFC_MODE_READER_WRITER |
+ NFC_MODE_CARD_EMULATION;
+ g_assert(nfc_manager_add_adapter(test->manager, test->adapter));
+ test->loop = g_main_loop_new(NULL, TRUE);
+ test->pool = gutil_idle_pool_new();
+}
+
+static
+void
+test_start(
+ GDBusConnection* client,
+ GDBusConnection* server,
+ void* user_data)
+{
+ TestData* test = user_data;
+
+ g_object_ref(test->client = client);
+ g_object_ref(test->server = server);
+ test_name_own_set_connection(server);
+ test->service = dbus_service_adapter_new(test->adapter, server);
+ g_assert(nfc_manager_start(test->manager));
+}
+
+static
+void
+test_activate(
+ TestData* test)
+{
+ GDEBUG("Simulating host activation");
+ test->initiator = test_initiator_new();
+ test->initiator->protocol = NFC_PROTOCOL_T4A_TAG;
+ g_assert(nfc_adapter_add_host(test->adapter, test->initiator));
+}
+
+static
+void
+test_data_cleanup(
+ TestData* test)
+{
+ test_name_own_set_connection(NULL);
+ nfc_manager_stop(test->manager, 0);
+ gutil_object_unref(test->client);
+ gutil_object_unref(test->server);
+ nfc_initiator_unref(test->initiator);
+ nfc_adapter_unref(test->adapter);
+ nfc_manager_unref(test->manager);
+ dbus_service_adapter_free(test->service);
+ gutil_idle_pool_destroy(test->pool);
+ g_main_loop_unref(test->loop);
+}
+
+static
+const char*
+test_host_path(
+ TestData* test)
+{
+ NfcHost* host = nfc_adapter_hosts(test->adapter)[0];
+ char* path;
+
+ g_assert(test->service);
+ g_assert(host);
+ path = g_strconcat(dbus_service_adapter_path(test->service), "/",
+ host->name, NULL);
+ gutil_idle_pool_add(test->pool, path, g_free);
+ return path;
+}
+
+static
+void
+test_host_call(
+ TestData* test,
+ const char* method,
+ GVariant* args,
+ GAsyncReadyCallback callback)
+{
+ g_dbus_connection_call(test->client, NULL, test_host_path(test),
+ NFC_HOST_INTERFACE, method, args, NULL, G_DBUS_CALL_FLAGS_NONE,
+ TEST_DBUS_TIMEOUT, NULL, callback, test);
+}
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null(
+ void)
+{
+ dbus_service_host_free(NULL);
+}
+
+/*==========================================================================*
+ * get_all
+ *==========================================================================*/
+
+static
+void
+test_get_all_done(
+ GObject* client,
+ GAsyncResult* result,
+ gpointer user_data)
+{
+ TestData* test = user_data;
+ gint version = 0;
+ gboolean present = FALSE;
+ guint tech = NFC_TECHNOLOGY_UNKNOWN;
+ GError* error = NULL;
+ GVariant* var = g_dbus_connection_call_finish(G_DBUS_CONNECTION(client),
+ result, &error);
+
+ g_assert(var);
+ g_variant_get(var, "(ibu)", &version, &present, &tech);
+ g_variant_unref(var);
+
+ GDEBUG("version=%d, present=%d, tech=0x%02x", version, present, tech);
+ g_assert_cmpint(version, >= ,NFC_HOST_INTERFACE_VERSION);
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/plugins_dbus_service_local_app/Makefile
^
|
@@ -0,0 +1,8 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_plugins_dbus_service_local_app
+
+COMMON_SRC = test_main.c test_adapter.c test_initiator.c \
+ test_dbus.c test_dbus_name.c
+
+include ../common/Makefile.plugins
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/plugins_dbus_service_local_app/test_plugins_dbus_service_local_app.c
^
|
@@ -0,0 +1,981 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_initiator_p.h"
+#include "nfc_initiator_impl.h"
+#include "nfc_adapter.h"
+#include "nfc_host.h"
+#include "nfc_util.h"
+
+#include "internal/nfc_manager_i.h"
+
+#include <gutil_log.h>
+#include <gutil_misc.h>
+
+#include "dbus_service/plugin.h"
+#include "dbus_service/dbus_service.h"
+#include "dbus_service/dbus_service_util.h"
+#include "dbus_service/org.sailfishos.nfc.LocalHostApp.h"
+
+#include "test_common.h"
+#include "test_adapter.h"
+#include "test_initiator.h"
+#include "test_dbus.h"
+#include "test_dbus_name.h"
+
+#define NFC_DAEMON_PATH "/"
+#define NFC_DAEMON_INTERFACE "org.sailfishos.nfc.Daemon"
+
+#define TEST_DBUS_TIMEOUT \
+ ((test_opt.flags & TEST_FLAG_DEBUG) ? -1 : TEST_TIMEOUT_MS)
+
+typedef enum test_activate_flags {
+ TEST_ACTIVATE_FLAGS_NONE = 0,
+ TEST_ACTIVATE_KEEP_INITIATOR_ALIVE = 0x01,
+ TEST_ACTIVATE_EXIT_WHEN_GONE = 0x02
+} TEST_ACTIVATE_FLAGS;
+
+static const char test_host_app_path[] = "/test_app";
+static const char test_host_app_name[] = "TestApp";
+static const guint8 test_host_app_aid_bytes[] = {
+ 0x01, 0x02, 0x03, 0x04
+};
+static const GUtilData test_host_app_aid = {
+ TEST_ARRAY_AND_SIZE(test_host_app_aid_bytes)
+};
+static const guchar test_resp_ok[] = {
+ 0x90, 0x00
+};
+
+static TestOpt test_opt;
+static const char* dbus_sender = ":1.0";
+
+typedef struct test_data {
+ GMainLoop* loop;
+ NfcManager* manager;
+ NfcAdapter* adapter;
+ NfcInitiator* initiator;
+ OrgSailfishosNfcLocalHostApp* app;
+ GDBusConnection* server;
+ GDBusConnection* client;
+ gulong done_id;
+ void* ext;
+} TestData;
+
+static
+void
+test_done(
+ NfcInitiator* initiator,
+ void* loop)
+{
+ GDEBUG("Done");
+ test_quit_later_n(loop, 1);
+}
+
+static
+TestData*
+test_data_init(
+ TestData* test)
+{
+ NfcPluginsInfo pi;
+ static const NfcPluginDesc* const test_builtin_plugins[] = {
+ &NFC_PLUGIN_DESC(dbus_service),
+ NULL
+ };
+
+ memset(test, 0, sizeof(*test));
+ memset(&pi, 0, sizeof(pi));
+ pi.builtins = test_builtin_plugins;
+ g_assert((test->manager = nfc_manager_new(&pi)) != NULL);
+ g_assert((test->adapter = test_adapter_new()) != NULL);
+ test->adapter->supported_modes |= NFC_MODE_READER_WRITER |
+ NFC_MODE_CARD_EMULATION;
+ g_assert(nfc_manager_add_adapter(test->manager, test->adapter));
+ test->loop = g_main_loop_new(NULL, TRUE);
+ test->app = org_sailfishos_nfc_local_host_app_skeleton_new();
+ return test;
+}
+
+static
+void
+test_start(
+ GDBusConnection* client,
+ GDBusConnection* server,
+ void* user_data)
+{
+ TestData* test = user_data;
+
+ g_object_ref(test->client = client);
+ g_object_ref(test->server = server);
+ test_name_own_set_connection(server);
+ g_assert(nfc_manager_start(test->manager));
+}
+
+static
+void
+test_started(
+ TestData* test,
+ GDBusConnection* client,
+ GDBusConnection* server)
+{
+ GError* error = NULL;
+
+ g_assert(test->client == client);
+ g_assert(test->server == server);
+ g_assert(g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON
+ (test->app), client, test_host_app_path, &error));
+}
+
+static
+void
+test_activate(
+ TestData* test,
+ const TestTx* tx_list,
+ gsize tx_count,
+ TEST_ACTIVATE_FLAGS flags)
+{
+ GDEBUG("Simulating host activation");
+ test->initiator = test_initiator_new_with_tx2(tx_list, tx_count,
+ (flags & TEST_ACTIVATE_KEEP_INITIATOR_ALIVE) != 0);
+ if (flags & TEST_ACTIVATE_EXIT_WHEN_GONE) {
+ test->done_id = nfc_initiator_add_gone_handler(test->initiator,
+ test_done, test->loop);
+ }
+ g_assert(nfc_adapter_add_host(test->adapter, test->initiator));
+}
+
+static
+void
+test_data_cleanup(
+ TestData* test)
+{
+ test_name_own_set_connection(NULL);
+ gutil_disconnect_handlers(test->initiator, &test->done_id, 1);
+ nfc_manager_stop(test->manager, 0);
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(test->app));
+ g_object_unref(test->app);
+ g_object_unref(test->client);
+ g_object_unref(test->server);
+ nfc_initiator_unref(test->initiator);
+ nfc_adapter_unref(test->adapter);
+ nfc_manager_unref(test->manager);
+ g_main_loop_unref(test->loop);
+}
+
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/plugins_dbus_service_local_host/Makefile
^
|
@@ -0,0 +1,8 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_plugins_dbus_service_local_host
+
+COMMON_SRC = test_main.c test_adapter.c test_initiator.c \
+ test_dbus.c test_dbus_name.c
+
+include ../common/Makefile.plugins
|
[-]
[+]
|
Added |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/plugins_dbus_service_local_host/test_plugins_dbus_service_local_host.c
^
|
@@ -0,0 +1,611 @@
+/*
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfc_initiator_p.h"
+#include "nfc_initiator_impl.h"
+#include "nfc_adapter.h"
+#include "nfc_host.h"
+#include "nfc_util.h"
+
+#include "internal/nfc_manager_i.h"
+
+#include <gutil_log.h>
+#include <gutil_misc.h>
+
+#include "dbus_service/plugin.h"
+#include "dbus_service/dbus_service.h"
+#include "dbus_service/dbus_service_util.h"
+#include "dbus_service/org.sailfishos.nfc.LocalHostService.h"
+
+#include "test_common.h"
+#include "test_adapter.h"
+#include "test_initiator.h"
+#include "test_dbus.h"
+#include "test_dbus_name.h"
+
+#define NFC_DAEMON_PATH "/"
+#define NFC_DAEMON_INTERFACE "org.sailfishos.nfc.Daemon"
+
+#define TEST_DBUS_TIMEOUT \
+ ((test_opt.flags & TEST_FLAG_DEBUG) ? -1 : TEST_TIMEOUT_MS)
+
+static const char test_host_service_path[] = "/test_host";
+static const char test_host_service_name[] = "TestHost";
+
+static TestOpt test_opt;
+static const char* dbus_sender = ":1.0";
+
+typedef struct test_data {
+ GMainLoop* loop;
+ NfcManager* manager;
+ NfcAdapter* adapter;
+ NfcInitiator* initiator;
+ OrgSailfishosNfcLocalHostService* service;
+ GDBusConnection* server;
+ GDBusConnection* client;
+ gulong done_id;
+} TestData;
+
+static
+void
+test_done(
+ NfcInitiator* initiator,
+ void* loop)
+{
+ GDEBUG("Done");
+ test_quit_later_n(loop, 1);
+}
+
+static
+void
+test_data_init(
+ TestData* test)
+{
+ NfcPluginsInfo pi;
+ static const NfcPluginDesc* const test_builtin_plugins[] = {
+ &NFC_PLUGIN_DESC(dbus_service),
+ NULL
+ };
+
+ memset(test, 0, sizeof(*test));
+ memset(&pi, 0, sizeof(pi));
+ pi.builtins = test_builtin_plugins;
+ g_assert((test->manager = nfc_manager_new(&pi)) != NULL);
+ g_assert((test->adapter = test_adapter_new()) != NULL);
+ test->adapter->supported_modes |= NFC_MODE_READER_WRITER |
+ NFC_MODE_CARD_EMULATION;
+ g_assert(nfc_manager_add_adapter(test->manager, test->adapter));
+ test->loop = g_main_loop_new(NULL, TRUE);
+ test->service = org_sailfishos_nfc_local_host_service_skeleton_new();
+}
+
+static
+void
+test_start(
+ GDBusConnection* client,
+ GDBusConnection* server,
+ void* user_data)
+{
+ TestData* test = user_data;
+
+ g_object_ref(test->client = client);
+ g_object_ref(test->server = server);
+ test_name_own_set_connection(server);
+ g_assert(nfc_manager_start(test->manager));
+}
+
+static
+void
+test_started(
+ TestData* test,
+ GDBusConnection* client,
+ GDBusConnection* server)
+{
+ GError* error = NULL;
+
+ g_assert(test->client == client);
+ g_assert(test->server == server);
+ g_assert(g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON
+ (test->service), client, test_host_service_path, &error));
+}
+
+static
+void
+test_activate(
+ TestData* test,
+ const TestTx* tx_list,
+ gsize tx_count,
+ gboolean stay_alive)
+{
+ GDEBUG("Simulating host activation");
+ test->initiator = test_initiator_new_with_tx2(tx_list, tx_count,
+ stay_alive);
+ if (!stay_alive) {
+ test->done_id = nfc_initiator_add_gone_handler(test->initiator,
+ test_done, test->loop);
+ }
+ g_assert(nfc_adapter_add_host(test->adapter, test->initiator));
+}
+
+static
+void
+test_data_cleanup(
+ TestData* test)
+{
+ test_name_own_set_connection(NULL);
+ gutil_disconnect_handlers(test->initiator, &test->done_id, 1);
+ nfc_manager_stop(test->manager, 0);
+ g_dbus_interface_skeleton_unexport
+ (G_DBUS_INTERFACE_SKELETON(test->service));
+ g_object_unref(test->service);
+ g_object_unref(test->client);
+ g_object_unref(test->server);
+ nfc_initiator_unref(test->initiator);
+ nfc_adapter_unref(test->adapter);
+ nfc_manager_unref(test->manager);
+ g_main_loop_unref(test->loop);
+}
+
+static
+gboolean
+test_initiator_deactivate_cb(
+ void* initiator)
+{
+ nfc_initiator_deactivate(NFC_INITIATOR(initiator));
+ return G_SOURCE_REMOVE;
+}
+
+static
+void
+test_initiator_deactivate_later(
+ NfcInitiator* initiator)
+{
+ g_idle_add_full(G_PRIORITY_HIGH_IDLE, test_initiator_deactivate_cb,
+ nfc_initiator_ref(initiator), g_object_unref);
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/plugins_dbus_service_plugin/test_plugins_dbus_service_plugin.c
^
|
@@ -10,23 +10,27 @@
*
* 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -50,10 +54,12 @@
#define NFC_DAEMON_PATH "/"
#define NFC_DAEMON_INTERFACE "org.sailfishos.nfc.Daemon"
-#define NFC_DAEMON_INTERFACE_VERSION (3)
+#define NFC_DAEMON_INTERFACE_VERSION (4)
static TestOpt test_opt;
static const char* dbus_sender = ":1.0";
+static const char test_host_service_path[] = "/test_host";
+static const char test_host_service_name[] = "TestHost";
#define TEST_DBUS_TIMEOUT \
((test_opt.flags & TEST_FLAG_DEBUG) ? -1 : TEST_TIMEOUT_MS)
@@ -63,12 +69,14 @@
NfcManager* manager;
NfcAdapter* adapter;
GDBusConnection* client; /* Owned by TestDBus */
+ void* ext;
} TestData;
static
-void
-test_data_init2(
+TestData*
+test_data_init3(
TestData* test,
+ NfcAdapter* adapter, /* Consumes the reference */
gboolean add_adapter)
{
NfcPluginsInfo pi;
@@ -81,19 +89,29 @@
memset(&pi, 0, sizeof(pi));
pi.builtins = test_builtin_plugins;
g_assert((test->manager = nfc_manager_new(&pi)) != NULL);
- g_assert((test->adapter = test_adapter_new()) != NULL);
+ g_assert((test->adapter = adapter) != NULL);
if (add_adapter) {
g_assert(nfc_manager_add_adapter(test->manager, test->adapter));
}
test->loop = g_main_loop_new(NULL, TRUE);
+ return test;
}
static
-void
+TestData*
+test_data_init2(
+ TestData* test,
+ gboolean add_adapter)
+{
+ return test_data_init3(test, test_adapter_new(), add_adapter);
+}
+
+static
+TestData*
test_data_init(
TestData* test)
{
- test_data_init2(test, TRUE);
+ return test_data_init2(test, TRUE);
}
static
@@ -143,7 +161,31 @@
/* Generic call without arguments */
g_dbus_connection_call(test->client, NULL,
NFC_DAEMON_PATH, NFC_DAEMON_INTERFACE, method, args, NULL,
- G_DBUS_CALL_FLAGS_NONE, TEST_DBUS_TIMEOUT, NULL, callback, test);
+ G_DBUS_CALL_FLAGS_NONE, TEST_TIMEOUT_MS, NULL, callback, test);
+}
+
+static
+void
+test_call_request_mode(
+ TestData* test,
+ NFC_MODE enable,
+ NFC_MODE disable,
+ GAsyncReadyCallback callback)
+{
+ test_call(test, "RequestMode", g_variant_new ("(uu)",
+ enable, disable), callback);
+}
+
+static
+void
+test_call_release_mode(
+ TestData* test,
+ guint id,
+ GAsyncReadyCallback callback)
+{
+ test_call(test, "ReleaseMode",
+ g_variant_new ("(u)", id),
+ callback);
}
static
@@ -171,6 +213,96 @@
callback);
}
+static
+void
+test_call_request_techs(
+ TestData* test,
+ NFC_TECHNOLOGY enable,
+ NFC_TECHNOLOGY disable,
+ GAsyncReadyCallback callback)
+{
+ test_call(test, "RequestTechs",
+ g_variant_new ("(uu)", enable, disable),
+ callback);
+}
+
+static
+void
+test_call_release_techs(
+ TestData* test,
+ guint id,
+ GAsyncReadyCallback callback)
+{
+ test_call(test, "ReleaseTechs",
+ g_variant_new ("(u)", id),
+ callback);
+}
+
+static
+void
+test_call_register_local_host_service(
+ TestData* test,
+ const char* path,
+ const char* name,
+ GAsyncReadyCallback callback)
+{
+ test_call(test, "RegisterLocalHostService",
+ g_variant_new ("(os)", path, name),
+ callback);
+}
+
+static
+void
+test_call_unregister_local_host_service(
+ TestData* test,
+ const char* path,
+ GAsyncReadyCallback callback)
+{
+ test_call(test, "UnregisterLocalHostService",
+ g_variant_new ("(o)", path),
+ callback);
+}
+
+static
+void
+test_call_register_local_host_app(
+ TestData* test,
+ const char* path,
+ const char* name,
+ const GUtilData* aid,
+ NFC_HOST_APP_FLAGS flags,
+ GAsyncReadyCallback callback)
+{
+ test_call(test, "RegisterLocalHostApp",
+ g_variant_new("(os@ayu)", path, name,
|
[-]
[+]
|
Changed |
_service:tar_git:nfcd-1.2.0.tar.bz2/unit/plugins_dbus_service_util/test_plugins_dbus_service_util.c
^
|
@@ -1,33 +1,40 @@
/*
+ * Copyright (C) 2020-2023 Slava Monich <slava@monich.com>
* 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:
+ * You may use this file under the terms of the 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.
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
*/
#include "test_common.h"
@@ -45,7 +52,6 @@
void)
{
static const guint8 value = 42;
- static const GUtilData data = { &value, sizeof(value) };
GVariant* var = dbus_service_dup_byte_array_as_variant(NULL, 0);
/* Empty variant */
@@ -54,17 +60,11 @@
g_assert(!g_variant_get_size(var));
g_variant_unref(g_variant_take_ref(var));
- var = dbus_service_dup_byte_array_data_as_variant(NULL);
- g_assert(var);
- g_assert_cmpstr(g_variant_get_type_string(var), == ,"ay");
- g_assert(!g_variant_get_size(var));
- g_variant_unref(g_variant_take_ref(var));
-
/* Variant containing some data */
- var = dbus_service_dup_byte_array_data_as_variant(&data);
+ var = dbus_service_dup_byte_array_as_variant(&value, sizeof(value));
g_assert_cmpstr(g_variant_get_type_string(var), == ,"ay");
- g_assert_cmpuint(g_variant_get_size(var), == ,data.size);
- g_assert(!memcmp(g_variant_get_data(var), data.bytes, data.size));
+ g_assert_cmpuint(g_variant_get_size(var), == ,sizeof(value));
+ g_assert(!memcmp(g_variant_get_data(var), &value, sizeof(value)));
g_variant_unref(g_variant_take_ref(var));
}
@@ -123,6 +123,27 @@
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
dbus_service_dict_add_byte_array_data(&builder, name, &data);
test_dict_check_data(g_variant_builder_end(&builder), name, &data);
+
+ /* NULL GUtilData doesn't add anything */
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
+ dbus_service_dict_add_byte_array_data(&builder, name, NULL);
+ var = g_variant_builder_end(&builder);
+ g_assert_cmpuint(g_variant_n_children(var), == ,0);
+ g_variant_unref(g_variant_take_ref(var));
+}
+
+/*==========================================================================*
+ * valid_id
+ *==========================================================================*/
+
+static
+void
+test_valid_id(
+ void)
+{
+ g_assert(dbus_service_valid_id(1));
+ g_assert(!dbus_service_valid_id(NFCD_ID_FAIL));
+ g_assert(!dbus_service_valid_id(NFCD_ID_SYNC));
}
/*==========================================================================*
@@ -136,6 +157,7 @@
g_test_init(&argc, &argv, NULL);
g_test_add_func(TEST_("byte_array"), test_byte_array);
g_test_add_func(TEST_("dict"), test_dict);
+ g_test_add_func(TEST_("valid_id"), test_valid_id);
test_init(&test_opt, argc, argv);
return g_test_run();
}
|