Skip to content

Commit

Permalink
[dbus] Add GetActivationParameters method for IsoDep interface. JB#50041
Browse files Browse the repository at this point in the history
It's possible now to retrieve Activation parameters for ISO-DEP
interface tags.
  • Loading branch information
LuxInTenebr1s authored and monich committed Aug 21, 2020
1 parent 84d4dbb commit a833403
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 1 deletion.
121 changes: 120 additions & 1 deletion plugins/dbus_service/dbus_service_isodep.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2019 Jolla Ltd.
* Copyright (C) 2019 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:
*
Expand Down Expand Up @@ -34,13 +35,16 @@
#include "dbus_service/org.sailfishos.nfc.IsoDep.h"

#include <nfc_tag_t4.h>
#include <nfc_target.h>

#include <gutil_misc.h>

enum {
CALL_GET_ALL,
CALL_GET_INTERFACE_VERSION,
CALL_TRANSMIT,
CALL_GET_ALL2,
CALL_GET_ACTIVATION_PARAMETERS,
CALL_COUNT
};

Expand All @@ -51,7 +55,7 @@ struct dbus_service_isodep {
gulong call_id[CALL_COUNT];
};

#define NFC_DBUS_ISODEP_INTERFACE_VERSION (1)
#define NFC_DBUS_ISODEP_INTERFACE_VERSION (2)

typedef struct dbus_service_isodep_async_call {
OrgSailfishosNfcIsoDep* iface;
Expand All @@ -70,6 +74,38 @@ dbus_service_isodep_dup_data_as_variant(
NULL, NULL);
}

static
void
dbus_service_isodep_dict_add_value(
GVariantBuilder* builder,
const char* name,
GVariant* value)
{
g_variant_builder_add(builder, "{sv}", name, value);
}

static
void
dbus_service_isodep_dict_add_byte(
GVariantBuilder* builder,
const char* name,
guint8 value)
{
dbus_service_isodep_dict_add_value(builder, name,
g_variant_new_byte(value));
}

static
void
dbus_service_isodep_dict_add_bytes_array(
GVariantBuilder* builder,
const char* name,
const GUtilData* data)
{
dbus_service_isodep_dict_add_value(builder, name,
dbus_service_isodep_dup_data_as_variant(data->bytes, data->size));
}

static
NfcTargetSequence*
dbus_service_isodep_sequence(
Expand Down Expand Up @@ -206,6 +242,83 @@ dbus_service_isodep_handle_transmit(
return TRUE;
}

/* Interface version 2 */

static
GVariant*
dbus_service_isodep_get_act_parameters(
NfcTagType4* t4,
const NfcParamIsoDep* act)
{
GVariantBuilder gvb;
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));

if (G_LIKELY(act)) {
switch(t4->tag.target->technology) {
case NFC_TECHNOLOGY_A:
dbus_service_isodep_dict_add_byte(&gvb, "T0", act->a.t0);
if (act->a.t0 & NFC_PARAM_ISODEP_T0_A) {
dbus_service_isodep_dict_add_byte(&gvb, "TA", act->a.ta);
}
if (act->a.t0 & NFC_PARAM_ISODEP_T0_B) {
dbus_service_isodep_dict_add_byte(&gvb, "TB", act->a.tb);
}
if (act->a.t0 & NFC_PARAM_ISODEP_T0_C) {
dbus_service_isodep_dict_add_byte(&gvb, "TC", act->a.tc);
}
dbus_service_isodep_dict_add_bytes_array(&gvb, "HB", &act->a.t1);
break;
case NFC_TECHNOLOGY_B:
dbus_service_isodep_dict_add_byte(&gvb, "MBLI", act->b.mbli);
dbus_service_isodep_dict_add_byte(&gvb, "DID", act->b.did);
if (act->b.hlr.bytes) {
dbus_service_isodep_dict_add_bytes_array(&gvb, "HLR",
&act->b.hlr);
}
break;
case NFC_TECHNOLOGY_F:
case NFC_TECHNOLOGY_UNKNOWN:
break;
}
}
return g_variant_builder_end(&gvb);
}

/* GetAll2 */

static
gboolean
dbus_service_isodep_handle_get_all2(
OrgSailfishosNfcIsoDep* iface,
GDBusMethodInvocation* call,
DBusServiceIsoDep* self)
{
NfcTagType4* t4 = self->t4;
const NfcParamIsoDep *act = t4->iso_dep;

org_sailfishos_nfc_iso_dep_complete_get_all2(iface, call,
NFC_DBUS_ISODEP_INTERFACE_VERSION,
dbus_service_isodep_get_act_parameters(t4, act));
return TRUE;
}

/* GetActivationParameters */

static
gboolean
dbus_service_isodep_handle_get_act_parameters(
OrgSailfishosNfcIsoDep* iface,
GDBusMethodInvocation* call,
DBusServiceIsoDep* self)
{
NfcTagType4* t4 = self->t4;
const NfcParamIsoDep *act = t4->iso_dep;

org_sailfishos_nfc_iso_dep_complete_get_activation_parameters(iface,
call, dbus_service_isodep_get_act_parameters(t4, act));
return TRUE;
}

/*==========================================================================*
* Interface
*==========================================================================*/
Expand Down Expand Up @@ -246,6 +359,12 @@ dbus_service_isodep_new(
self->call_id[CALL_TRANSMIT] =
g_signal_connect(self->iface, "handle-transmit",
G_CALLBACK(dbus_service_isodep_handle_transmit), self);
self->call_id[CALL_GET_ALL2] =
g_signal_connect(self->iface, "handle-get-all2",
G_CALLBACK(dbus_service_isodep_handle_get_all2), self);
self->call_id[CALL_GET_ACTIVATION_PARAMETERS] =
g_signal_connect(self->iface, "handle-get-activation-parameters",
G_CALLBACK(dbus_service_isodep_handle_get_act_parameters), self);

if (g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON
(self->iface), connection, path, &error)) {
Expand Down
22 changes: 22 additions & 0 deletions plugins/dbus_service/org.sailfishos.nfc.IsoDep.xml
Expand Up @@ -3,6 +3,20 @@
<node>
<!-- ISO-DEP specific extensions to org.sailfishos.nfc.Tag -->
<interface name="org.sailfishos.nfc.IsoDep">
<!--
Activation Parameters:
NFC-A:
"T0" - "y", Format Byte T0
"TA" - "y", Interface Bytes TA (optional)
"TB" - "y", Interface Bytes TB (optional)
"TC" - "y", Interface Bytes TC (optional)
"HB" - "ay", Historical Bytes
NFC-B:
"MBLI" - "y", Maximum Buffer Length Index
"DID" - "y", Device ID
"HLR" - "ay", Higher Layer Response (optional)
-->
<method name="GetAll">
<arg name="version" type="i" direction="out"/>
</method>
Expand All @@ -24,5 +38,13 @@
<arg name="SW1" type="y" direction="out"/>
<arg name="SW2" type="y" direction="out"/>
</method>
<!-- Interface version 2 -->
<method name="GetAll2">
<arg name="version" type="i" direction="out"/>
<arg name="parameters" type="a{sv}" direction="out"/>
</method>
<method name="GetActivationParameters">
<arg name="parameters" type="a{sv}" direction="out"/>
</method>
</interface>
</node>

0 comments on commit a833403

Please sign in to comment.