From 2ca7f3a4a03db3e7d7fa15504fa3d69e1c6bd217 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 31 Oct 2017 10:50:24 +0100 Subject: Split in two: agl-identity-service and uds-ble-id-init-service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The binding is splitted in two parts and packeged as widgets. The two parts are: - uds-ble-id-init-service This service provides a UDS (User Data Service) over BLE. It detects writes to the email of the user to initiate the authentication process. - agl-identity-service This service queries the Forgerock's Edge Controller to fill user data and make it available. The actual code is not fully functionnal. Signed-off-by: José Bollo --- .../src/uds-ble-id-init-service.c | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 uds-ble-id-init-service/src/uds-ble-id-init-service.c (limited to 'uds-ble-id-init-service/src/uds-ble-id-init-service.c') diff --git a/uds-ble-id-init-service/src/uds-ble-id-init-service.c b/uds-ble-id-init-service/src/uds-ble-id-init-service.c new file mode 100644 index 0000000..f887963 --- /dev/null +++ b/uds-ble-id-init-service/src/uds-ble-id-init-service.c @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2015, 2016, 2017 "IoT.bzh" + * Author: José Bollo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define AFB_BINDING_VERSION 2 +#include + +#include "aia-uds-bluez.h" + +#if !defined(AUTO_START_ADVISE) +#define AUTO_START_ADVISE 1 +#endif + +static int advising; + +static struct afb_event event; + +static int autoadvise = AUTO_START_ADVISE; + +/****************************************************************/ + +static void on_uds_change(const struct aia_uds *uds) +{ + struct json_object *object; + + AFB_INFO("UDS changed" + " first-name%s[%.*s]" + " last-name%s[%.*s]" + " email%s[%.*s]" + " language%s[%.*s]", + uds->first_name.changed ? "*" : "", (int)uds->first_name.length, uds->first_name.data ?:"", + uds->last_name.changed ? "*" : "", (int)uds->last_name.length, uds->last_name.data ?:"", + uds->email.changed ? "*" : "", (int)uds->email.length, uds->email.data ?:"", + uds->language.changed ? "*" : "", (int)uds->language.length, uds->language.data ?:""); + + if (uds->email.changed) { + object = json_object_new_object(); + json_object_object_add(object, "incoming", json_object_new_string(uds->email.data)); + afb_event_push(event, object); + } +} + +static void start (struct afb_req request) +{ + int rc; + + if (!advising) { + rc = aia_uds_advise(1, NULL, NULL); + if (rc < 0) { +/* +TODO: solve the issue + afb_req_fail(request, "failed", "start scan failed"); + return; +*/ + AFB_ERROR("Ignoring scan start failed, because probably already in progress"); + } + } + advising = advising + 1; + afb_req_subscribe(request, event); + afb_req_success(request, NULL, NULL); +} + + +static void stop (struct afb_req request) +{ + if (advising) { + advising = advising - 1; + if (!advising) + aia_uds_advise(0, NULL, NULL); + } + afb_req_success(request, NULL, NULL); +} + +static int init() +{ + sd_bus *bus; + int rc; + + bus = afb_daemon_get_system_bus(); + rc = bus ? aia_uds_init(bus) : -ENOTSUP; + if (rc < 0) { + errno = -rc; + return -1; + } + + aia_uds_set_on_change(on_uds_change); + + event = afb_daemon_make_event("event"); + if (!afb_event_is_valid(event)) + return -1; + + rc = aia_uds_advise(autoadvise, NULL, NULL); + advising = autoadvise && rc >= 0; + return rc < 0 ? rc : 0; +} + + +// NOTE: this sample does not use session to keep test a basic as possible +// in real application most APIs should be protected with AFB_SESSION_CHECK +static const struct afb_verb_v2 verbs[]= +{ + {"start" , start, NULL, "start User Data Service", AFB_SESSION_NONE }, + {"stop" , stop , NULL, "stop User Data Service" , AFB_SESSION_NONE }, + {NULL} +}; + +const struct afb_binding_v2 afbBindingV2 = +{ + .api = "uds-ble-init-id", + .specification = NULL, + .info = "AGL Identitity initiator above BLE's User Data Service", + .verbs = verbs, + .preinit = NULL, + .init = init, + .onevent = NULL, + .noconcurrency = 1 +}; + +/* vim: set colorcolumn=80: */ + -- cgit 1.2.3-korg