Skip to content

Commit

Permalink
[core] Serialize reactivation and transmit requests. JB#51200
Browse files Browse the repository at this point in the history
It didn't matter before, because reactivation was only happening during
initialization of ISO-DEP targets. The whole process was controlled by
nfcd, no external requests could be submitted until after the target
has been initialized, everything was nice and simple.

Now that we are considering exposing reactivation functionality over
D-Bus, we need to serialize reactivation and transmit requests and
that's a totally different game.
  • Loading branch information
monich committed Oct 6, 2020
1 parent e478ccc commit 93da21f
Show file tree
Hide file tree
Showing 5 changed files with 480 additions and 150 deletions.
19 changes: 14 additions & 5 deletions core/src/nfc_tag_t4.c
Expand Up @@ -379,20 +379,30 @@ nfc_tag_t4_initialized(
NfcTag* tag = &self->tag;

GASSERT(!priv->init_id);
g_object_ref(self);
nfc_target_sequence_unref(priv->init_seq);
nfc_iso_dep_ndef_read_free(priv->init_read);
priv->init_seq = NULL;
priv->init_read = NULL;
nfc_tag_set_initialized(tag);
g_object_unref(self);
}

static
void
nfc_tag_t4_init_done(
NfcTarget* target,
void* user_data)
NFC_REACTIVATE_STATUS status,
void* self)
{
nfc_tag_t4_initialized(NFC_TAG_T4(user_data));
/*
* It doesn't make sense to mark tag as initialized in case of
* reactivation timeout, because the tag going to get deactivated
* and dropped right after this function returns.
*/
if (status != NFC_REACTIVATE_STATUS_TIMEOUT) {
nfc_tag_t4_initialized(NFC_TAG_T4(self));
}
}

static
Expand All @@ -407,10 +417,9 @@ nfc_tag_t4_ndef_read_done(
* done now, to avoid blocking presence checks in case if reactivation
* times out.
*/
nfc_target_sequence_unref(priv->init_seq);
priv->init_seq = NULL;
GDEBUG("Reactivating Type 4 tag");
if (!nfc_target_reactivate(self->tag.target, nfc_tag_t4_init_done, self)) {
if (!nfc_target_reactivate(self->tag.target, priv->init_seq,
nfc_tag_t4_init_done, self)) {
GDEBUG("Oops. Failed to reactivate, leaving the tag as is");
nfc_tag_t4_initialized(self);
}
Expand Down

0 comments on commit 93da21f

Please sign in to comment.