diff options
author | Raquel Medina <raquel.medina@konsulko.com> | 2019-02-18 11:52:36 +0200 |
---|---|---|
committer | raquel medina <raquel.medina@konsulko.com> | 2019-05-02 13:15:43 +0000 |
commit | f122b8434c8776e5a19bfb6beda5db093489272b (patch) | |
tree | 9328b2c939e7f2cb3e695b68ad0aaa2b2cc28fe9 /src | |
parent | 509e8df88f8ad8d7e299e6d01077b7014624de3c (diff) |
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 <raquel.medina@konsulko.com>
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
(cherry picked from commit b2676e6e8aae3c6002e9ed3f2c0fa68176051d96)
Diffstat (limited to 'src')
-rw-r--r-- | src/agl-identity-binding.c | 57 |
1 files 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; } |