diff options
author | Raquel Medina <raquel.medina@konsulko.com> | 2018-11-12 14:03:22 +0200 |
---|---|---|
committer | Raquel Medina <raquel.medina@konsulko.com> | 2018-11-25 23:38:13 +0200 |
commit | 533dae6bd4359b72a365f0366fc41c08f3667fee (patch) | |
tree | 98d5cff3e1f59c8222f4a8999c4415dea0129bfb /binding/afm-nfc-binding.c | |
parent | 7177220bd5783048808d6d8392b81447041e6263 (diff) |
binding: nfc: remove dependencies on libnfc
Bug-AGL: SPEC-1921
- remove dependencies on libnfc
- remove unused code (binding/afm-nfc-common.c)
Change-Id: I824094f5d7a409739c479904662e21c900cc8509
Signed-off-by: Raquel Medina <raquel.medina@konsulko.com>
Diffstat (limited to 'binding/afm-nfc-binding.c')
-rw-r--r-- | binding/afm-nfc-binding.c | 127 |
1 files changed, 1 insertions, 126 deletions
diff --git a/binding/afm-nfc-binding.c b/binding/afm-nfc-binding.c index 70a8625..94705de 100644 --- a/binding/afm-nfc-binding.c +++ b/binding/afm-nfc-binding.c @@ -29,133 +29,14 @@ #include <glib-object.h> #include <json-c/json.h> #include <neardal/neardal.h> -#include <nfc/nfc.h> -#include <nfc/nfc-types.h> - #define AFB_BINDING_VERSION 3 #include <afb/afb-binding.h> #include "afm-nfc-common.h" -#define WAIT_FOR_REMOVE(dev) { while (0 == nfc_initiator_target_is_present(dev, NULL)) {} } - static afb_event_t presence_event; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -static const nfc_modulation modulations[] = { - { .nmt = NMT_ISO14443A, .nbr = NBR_106 }, -}; - -static char *get_tag_uid(nfc_target *nt) -{ - if (nt->nm.nmt == NMT_ISO14443A) - return to_hex_string((unsigned char *) &nt->nti.nai.abtUid, nt->nti.nai.szUidLen); - - return NULL; -} - -static void send_detect_event(char *current_id, nfc_binding_data *data) -{ - json_object *jresp; - - if (current_id == NULL) - return; - - jresp = json_object_new_object(); - - json_object_object_add(jresp, "status", json_object_new_string("detected")); - json_object_object_add(jresp, "uid", json_object_new_string(current_id)); - - if (data->jresp) { - json_object_put(data->jresp); - data->jresp = NULL; - } - - json_object_get(jresp); - data->jresp = jresp; - - afb_event_push(presence_event, jresp); -} - -static void *nfc_loop_thread(void *ptr) -{ - nfc_binding_data *data = ptr; - - while (1) { - nfc_target nt; - json_object *jresp; - int res = nfc_initiator_poll_target(data->dev, modulations, ARRAY_SIZE(modulations), 0xff, 2, &nt); - char *current_uid; - - if (res < 0) - break; - - pthread_mutex_lock(&mutex); - - current_uid = get_tag_uid(&nt); - send_detect_event(current_uid, data); - - pthread_mutex_unlock(&mutex); - - WAIT_FOR_REMOVE(data->dev); - - pthread_mutex_lock(&mutex); - - jresp = json_object_new_object(); - json_object_object_add(jresp, "status", json_object_new_string("removed")); - json_object_object_add(jresp, "uid", json_object_new_string(current_uid)); - - if (data->jresp) { - json_object_put(data->jresp); - data->jresp = NULL; - } - - afb_event_push(presence_event, jresp); - - pthread_mutex_unlock(&mutex); - } - - nfc_close(data->dev); - nfc_exit(data->ctx); - free(data); - - return NULL; -} - - -static nfc_binding_data *get_libnfc_instance() -{ - nfc_context *ctx = NULL; - nfc_device *dev = NULL; - nfc_binding_data *data; - - nfc_init(&ctx); - - dev = nfc_open(ctx, NULL); - - if (dev == NULL) { - AFB_WARNING("Cannot get context for libnfc"); - nfc_exit(ctx); - return NULL; - } - - if (nfc_initiator_init(dev) < 0) { - AFB_WARNING("Cannot get initiator mode from libnfc"); - nfc_close(dev); - nfc_exit(ctx); - return NULL; - } - - data = malloc(sizeof(nfc_binding_data)); - - if (data) { - data->ctx = ctx; - data->dev = dev; - } - - return data; -} - static void neard_cb_record_found(const char *tag_name, void *ptr) { nfc_binding_data *data = ptr; @@ -245,18 +126,12 @@ static void *neard_loop_thread(void *ptr) static int init(afb_api_t api) { pthread_t thread_id; - nfc_binding_data *data = get_libnfc_instance(); + nfc_binding_data *data = NULL; char **adapters = NULL; int num_adapters, ret; presence_event = afb_daemon_make_event("presence"); - if (data) { - afb_api_set_userdata(api, data); - - return pthread_create(&thread_id, NULL, nfc_loop_thread, data); - } - ret = neardal_get_adapters(&adapters, &num_adapters); if (ret == NEARDAL_SUCCESS) { |