From b2676e6e8aae3c6002e9ed3f2c0fa68176051d96 Mon Sep 17 00:00:00 2001 From: Raquel Medina Date: Mon, 18 Feb 2019 11:52:36 +0200 Subject: binding: identity: read vin and user token from nfc tag Original idea and rework from Scott Murray for CES 2019 (funky flounder). This is a simplified version to match agl-service-nfc which in master is not providing all tag record fields but just the content value. To test an nfc tag must be programmed with a text record with value vin:uid. Bug-AGL: SPEC-2158 Change-Id: I12fb8e6b3f9e8259bc3c13829e44f7f0e0159f0a Signed-off-by: Raquel Medina Signed-off-by: Scott Murray --- src/agl-identity-binding.c | 57 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/src/agl-identity-binding.c b/src/agl-identity-binding.c index f246ea9..bac7b90 100644 --- a/src/agl-identity-binding.c +++ b/src/agl-identity-binding.c @@ -234,6 +234,41 @@ out: return ret; } +static void parse_nfc_tag_record(struct json_object *object) +{ + const char *tag_uid; + const char *tag_vin; + const char *value; + char *tmp; + + value = json_object_get_string(object); + if (!value) { + AFB_API_ERROR(this_api, "ignore tag - empty content value"); + goto out; + } + + tag_vin = strtok_r(value,":", &tmp); + if (!tag_vin) { + AFB_API_ERROR(this_api, "ignore tag - missing vin value"); + goto out; + } + + tag_uid = strtok_r(NULL, ":", &tmp); + if (!tag_uid) { + AFB_API_ERROR(this_api, "ignore tag - missing uid value"); + goto out; + } + + if (!strcmp(tag_vin, vin)) { + AFB_API_NOTICE(this_api, "tag record: vin=%s, key=%s", tag_vin, tag_uid); + agl_forgerock_download_request(vin, "nfc", tag_uid); + } + +out: + return; + +} + static void on_nfc_target_add(struct json_object *object) { struct json_object *json_status; @@ -246,6 +281,10 @@ static void on_nfc_target_add(struct json_object *object) goto out; } + AFB_API_DEBUG(this_api, + "nfc/presence debug: %s", + json_object_to_json_string(object)); + if (!json_object_object_get_ex(object, "status", &json_status)) { AFB_API_ERROR(this_api, "nfc/presence missing status"); goto out; @@ -256,19 +295,13 @@ static void on_nfc_target_add(struct json_object *object) goto out; } - if (json_object_object_get_ex(object, "uid", &json_uid)) - { - uid = json_object_get_string(json_uid); - AFB_API_NOTICE(this_api, - "nfc tag detected, call forgerock with vincode=%s and key=%s", - vin ? vin : default_vin, uid); - - agl_forgerock_download_request(vin ? vin : default_vin, "nfc", uid); + if (!json_object_object_get_ex(object, "uid", &json_uid)) { + AFB_API_ERROR(this_api, "nfc/presence missing uid"); + goto out; } - else - AFB_API_ERROR(this_api, - "nfc tag detected event but no UID found: %s", - json_object_to_json_string(object)); + + parse_nfc_tag_record(json_uid); + out: return; } -- cgit 1.2.3-korg