static int mifare_release(int err, void *data) { struct mifare_cookie *cookie = data; DBG("%p", cookie); if (!cookie) return err; if (err < 0 && cookie->cb) { cookie->cb(cookie->adapter_idx, cookie->target_idx, err); near_adapter_disconnect(cookie->adapter_idx); } /* Now free allocs */ g_free(cookie->nfcid1); g_slist_free(cookie->g_sect_list); g_free(cookie->mad_1); g_free(cookie->mad_2); if (cookie->ndef) g_free(cookie->ndef->data); g_free(cookie->ndef); g_free(cookie); cookie = NULL; return err; }
static void tag_present_cb(uint32_t adapter_idx, uint32_t target_idx, int status) { struct near_adapter *adapter; DBG(""); adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(adapter_idx)); if (!adapter) return; if (status < 0) { DBG("Tag is gone"); near_adapter_disconnect(adapter->idx); if (adapter->constant_poll) adapter_start_poll(adapter); return; } adapter->presence_timeout = g_timeout_add_seconds(CHECK_PRESENCE_PERIOD, check_presence, adapter); }
static gboolean check_presence(gpointer user_data) { struct near_adapter *adapter = user_data; struct near_tag *tag; int err; DBG(""); if (!adapter) return FALSE; tag = adapter->tag_link; if (!tag) goto out_err; err = __near_tag_check_presence(tag, tag_present_cb); if (err < 0) { DBG("Could not check target presence"); goto out_err; } return FALSE; out_err: near_adapter_disconnect(adapter->idx); if (adapter->constant_poll) adapter_start_poll(adapter); return FALSE; }
static int adapter_add_tag(struct near_adapter *adapter, uint32_t target_idx, uint32_t protocols, uint16_t sens_res, uint8_t sel_res, uint8_t *nfcid, uint8_t nfcid_len, uint8_t iso15693_dsfid, uint8_t iso15693_uid_len, uint8_t *iso15693_uid) { struct near_tag *tag; uint32_t tag_type; int err; tag = __near_tag_add(adapter->idx, target_idx, protocols, sens_res, sel_res, nfcid, nfcid_len, iso15693_dsfid, iso15693_uid_len, iso15693_uid); if (!tag) return -ENODEV; g_hash_table_insert(adapter->tags, GINT_TO_POINTER(target_idx), tag); tag_type = __near_tag_get_type(tag); err = near_adapter_connect(adapter->idx, target_idx, tag_type); if (err < 0) { near_error("Could not connect"); return err; } err = __near_tag_read(tag, tag_read_cb); if (err < 0) { near_error("Could not read the tag"); near_adapter_disconnect(adapter->idx); __near_adapter_remove_target(adapter->idx, target_idx); } return err; }
static gboolean adapter_recv_event(GIOChannel *channel, GIOCondition condition, gpointer user_data) { struct near_adapter *adapter = user_data; struct near_adapter_ioreq *req; GList *first; int sk; DBG("condition 0x%x", condition); if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) { near_error("Error while reading NFC bytes"); adapter_flush_rx(adapter, -EIO); near_adapter_disconnect(adapter->idx); adapter->presence_timeout = g_timeout_add_seconds(2 * CHECK_PRESENCE_PERIOD, check_presence, adapter); return FALSE; } sk = g_io_channel_unix_get_fd(channel); first = g_list_first(adapter->ioreq_list); if (!first) return TRUE; req = first->data; req->len = recv(sk, req->buf, sizeof(req->buf), 0); adapter->ioreq_list = g_list_remove(adapter->ioreq_list, req); g_idle_add(execute_recv_cb, req); return TRUE; }