From 2649ce10558f2f0eb80f4f7f8469c0788f58c7d9 Mon Sep 17 00:00:00 2001 From: Manasij Sur Roy Date: Mon, 19 Jun 2017 13:22:27 +0530 Subject: [PATCH] KONA reported issues fixed, removed unused components Change-Id: Ic063876bb15268eceb837e646a2f8067612617a0 Signed-off-by: Manasij Sur Roy --- CMakeLists.txt | 6 - ble_roaming_agent/CMakeLists.txt | 45 --- ble_roaming_agent/inc/BTRoamingKeys.h | 18 - ble_roaming_agent/src/bt_ragent_main.c | 41 --- ble_roaming_agent/src/fido_gatt_server.c | 312 ----------------- ble_roaming_agent/src/fido_gatt_server.h | 9 - bt_roaming_agent/src/bt_server.c | 2 + common/cryptoutil/src/AsmCrypto.cpp | 13 + fido-ble-ragent.manifest | 5 - packaging/fido-asm.spec | 68 ---- roaming_agent/CMakeLists.txt | 47 --- roaming_agent/inc/RoamingKeys.h | 16 - roaming_agent/src/iotcon_handler.c | 504 ---------------------------- roaming_agent/src/iotcon_handler.h | 15 - roaming_agent/src/ragent_main.c | 43 --- server/CMakeLists.txt | 1 - server/auth_discovery/inc/BleAdProvider.h | 39 --- server/auth_discovery/inc/BleCon.h | 48 --- server/auth_discovery/inc/BtAdProvider.h | 1 + server/auth_discovery/inc/IoTCon.h | 28 -- server/auth_discovery/inc/IotADProvider.h | 57 ---- server/auth_discovery/inc/RoamingUtil.h | 4 - server/auth_discovery/src/AuthManager.cpp | 25 -- server/auth_discovery/src/BleAdProvider.cpp | 415 ----------------------- server/auth_discovery/src/BleCon.cpp | 106 ------ server/auth_discovery/src/BtADProvider.cpp | 12 +- server/auth_discovery/src/BtCon.cpp | 1 - server/auth_discovery/src/IoTCon.cpp | 121 ------- server/auth_discovery/src/IotADProvider.cpp | 217 ------------ server/auth_discovery/src/RAuthStub.cpp | 1 - server/auth_discovery/src/RoamingUtil.cpp | 66 ---- 31 files changed, 23 insertions(+), 2263 deletions(-) delete mode 100644 ble_roaming_agent/CMakeLists.txt delete mode 100644 ble_roaming_agent/inc/BTRoamingKeys.h delete mode 100644 ble_roaming_agent/src/bt_ragent_main.c delete mode 100644 ble_roaming_agent/src/fido_gatt_server.c delete mode 100644 ble_roaming_agent/src/fido_gatt_server.h delete mode 100644 fido-ble-ragent.manifest delete mode 100644 roaming_agent/CMakeLists.txt delete mode 100644 roaming_agent/inc/RoamingKeys.h delete mode 100644 roaming_agent/src/iotcon_handler.c delete mode 100644 roaming_agent/src/iotcon_handler.h delete mode 100644 roaming_agent/src/ragent_main.c delete mode 100644 server/auth_discovery/inc/BleAdProvider.h delete mode 100644 server/auth_discovery/inc/BleCon.h delete mode 100644 server/auth_discovery/inc/IoTCon.h delete mode 100644 server/auth_discovery/inc/IotADProvider.h delete mode 100644 server/auth_discovery/src/BleAdProvider.cpp delete mode 100644 server/auth_discovery/src/BleCon.cpp delete mode 100644 server/auth_discovery/src/IoTCon.cpp delete mode 100644 server/auth_discovery/src/IotADProvider.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1aabe10..1807ca2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,17 +5,11 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") SET(INCLUDEDIR "\${prefix}/include ") -##ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(server) -##ADD_SUBDIRECTORY(test/shell_tc) ADD_SUBDIRECTORY(silent_auth) ADD_SUBDIRECTORY(ui) -ADD_SUBDIRECTORY(roaming_agent) ADD_SUBDIRECTORY(common/dbus_interfaces) ADD_SUBDIRECTORY(bt_roaming_agent) -##ADD_SUBDIRECTORY(ble_roaming_agent) ADD_DEPENDENCIES(fido-asm fido-asm-dbus) ADD_DEPENDENCIES(fido-bt-ragent-service fido-asm-dbus) -##ADD_DEPENDENCIES(fido-ble-ragent-service fido-asm-dbus) -ADD_DEPENDENCIES(fido-roaming-agent-service fido-asm-dbus) ADD_DEPENDENCIES(asmui fido-asm-dbus) diff --git a/ble_roaming_agent/CMakeLists.txt b/ble_roaming_agent/CMakeLists.txt deleted file mode 100644 index f11cdcd..0000000 --- a/ble_roaming_agent/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -SET(BLE_RAGENT_DAEMON fido-ble-ragent-service) - -INCLUDE(FindPkgConfig) -pkg_check_modules(BLE_RAGENT_DAEMON_PKGS REQUIRED - dlog - glib-2.0 - capi-base-common - pkgmgr-info - gio-2.0 - gio-unix-2.0 - gmodule-2.0 - cynara-client - cynara-session - cynara-creds-gdbus - capi-network-connection - capi-base-common - capi-appfw-application - capi-appfw-app-manager - aul - json-glib-1.0 - capi-system-info - capi-system-system-settings - capi-network-bluetooth -) - -FOREACH(flag ${BLE_RAGENT_DAEMON_PKGS_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}") -SET(PKGS_LDFLAGS "${BLE_RAGENT_DAEMON_PKGS_LDFLAGS} -pie") - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ble_roaming_agent/inc/) - -FILE( GLOB BLE_RAGENT_DAEMON_SRCS_CC - src/*.c -) - -ADD_EXECUTABLE(${BLE_RAGENT_DAEMON} ${BLE_RAGENT_DAEMON_SRCS_CC}) - -TARGET_LINK_LIBRARIES(${BLE_RAGENT_DAEMON} ${BLE_RAGENT_DAEMON_PKGS_LDFLAGS} fido-asm-dbus "-ldl") - -INSTALL(TARGETS ${BLE_RAGENT_DAEMON} DESTINATION bin) diff --git a/ble_roaming_agent/inc/BTRoamingKeys.h b/ble_roaming_agent/inc/BTRoamingKeys.h deleted file mode 100644 index 5c066b8..0000000 --- a/ble_roaming_agent/inc/BTRoamingKeys.h +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#ifndef _BT_ROAMINGKEYS_H -#define _BT_ROAMINGKEYS_H - -#define RA_BLE_FRAME_MAX_SIZE 20 -/*TODO: Change to some other uids*/ -#define RA_BLE_ADVERTISING_UUID "89D3502B-0F36-433A-8EF4-C502AD55F8DC" -#define RA_BLE_SERVICE_UUID "89D3502B-0F36-433A-8EF4-C502AD55F8DC" -#define RA_BLE_UUID_REQUEST "9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2" -#define RA_BLE_UUID_RESPONSE "2F7CABCE-808D-411F-9A0C-BB92BA96C102" -#define RA_BLE_SERVICE_REVISION "1.0" -#define RA_BLE_FRAME_MAX_SIZE 20 -#define RA_BLE_DATA_MAX_SIZE 65536 - -#define BT_DISC_TIMEOUT_SEC 5 - -#endif // _BT_ROAMINGKEYS_H diff --git a/ble_roaming_agent/src/bt_ragent_main.c b/ble_roaming_agent/src/bt_ragent_main.c deleted file mode 100644 index 01f52f4..0000000 --- a/ble_roaming_agent/src/bt_ragent_main.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved. - * - * 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. - * - */ - -#include -#include - -#include "fido_gatt_server.h" -#include "AsmHelper.h" - -int -main(int argc, char *argv[]) -{ - _INFO("Starting BT Roaming Agent Service"); - - GMainLoop *mainloop = g_main_loop_new(NULL, FALSE); - - int ret = fido_gatt_server_init(); - _INFO("fido_gatt_server_init=[%d]", ret); - - g_main_loop_run(mainloop); - - _INFO("Stopping BT Roaming Agent Service"); - ret = fido_gatt_server_shutdown(); - _INFO("[%d]", ret); - - return 0; -} diff --git a/ble_roaming_agent/src/fido_gatt_server.c b/ble_roaming_agent/src/fido_gatt_server.c deleted file mode 100644 index d53328e..0000000 --- a/ble_roaming_agent/src/fido_gatt_server.c +++ /dev/null @@ -1,312 +0,0 @@ - -#include -#include -#include -#include - -#include - -#include "fido_gatt_server.h" -#include "BTRoamingKeys.h" -#include "AsmHelper.h" -#include "fido-client-ipc-stub.h" - -#include -#include -#include -#include - -static bool __isStarted = false; - -static Fidoasm* -__asm_get_dbus_proxy(void) -{ -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - - GDBusConnection *connection = NULL; - GError *error = NULL; - - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - - /* Create the object */ - Fidoasm *dbus_proxy = fidoasm_proxy_new_sync(connection, - G_DBUS_PROXY_FLAGS_NONE, - "org.tizen.fidoasm", - "/org/tizen/fidoasm", - NULL, - &error); - - if (error != NULL) - _ERR("bluetooth fidoasm_proxy_new_sync failed %s", error->message); - - return dbus_proxy; -} - -static void -__ra_notify_cb(int result, const char *remote_address, bt_gatt_server_h server, - bt_gatt_h characteristic, bool completed, void *user_data) -{ - _INFO("bluetooth ragent __ra_notify_cb=[%d]", result); -} - -static void -__ra__write_value_requested_cb(const char *remote_address, int request_id, bt_gatt_server_h server, - bt_gatt_h gatt_handle, int offset, - const char *value, int len, void *user_data) -{ - _INFO("bluetooth ragent __ra__write_value_requested_cb=[%s]", value); - - /*Call ASM dbus and receive the response*/ - Fidoasm *asm_proxy = __asm_get_dbus_proxy(); - if (asm_proxy == NULL) { - _ERR("bluetooth Failed to get ASM proxy"); - bt_gatt_server_send_response(request_id, BT_GATT_REQUEST_TYPE_WRITE, - offset, -1, NULL, 0); - return; - } - - - const char *tlvReqB64 = value; - char *tlvRespB64 = NULL; - GError *gErr = NULL; - int tz_err = 0; - fidoasm_call_asm_request_sync(asm_proxy, tlvReqB64, - &tz_err, &tlvRespB64, NULL, &gErr); - if (gErr != NULL) { - - bt_gatt_server_send_response(request_id, BT_GATT_REQUEST_TYPE_WRITE, - offset, -1, NULL, 0); - _ERR("bluetooth Failed returned from ASM"); - return; - } - - int ret = bt_gatt_set_value(gatt_handle, tlvRespB64, strlen(tlvRespB64)); - _INFO("bluetooth ragent bt_gatt_set_value=[%d]", ret); - - bt_gatt_server_send_response(request_id, BT_GATT_REQUEST_TYPE_WRITE, offset, 0, NULL, 0); - - ret = bt_gatt_server_notify_characteristic_changed_value(gatt_handle, __ra_notify_cb, remote_address, NULL); - _INFO("bluetooth ragent bt_gatt_server_notify_characteristic_changed_value=[%d]", ret); -} - -static void -__advertising_state_changed_cb(int result, bt_advertiser_h advertiser, - bt_adapter_le_advertising_state_e adv_state, void* user_data) -{ - _INFO("bluetooth ragent __advertising_state_changed_cb=[%d]", adv_state); -} - -#define MAX_BLE_SIZE 1024 - -static void -onGattConchanged(int result, bool connected, const char *remote_address, void *user_data) -{ - _INFO("remote_address=[%s]", remote_address); - _INFO("connected=[%d]", connected); - _INFO("[%d]", result); -} - -static int -__fido_gatt_server_start(void) -{ - _INFO("bluetooth Request to start GATT server"); - - if (__isStarted == true) { - _INFO("bluetooth Already started"); - return 0; - } - - _INFO("bluetooth New GATT server"); - __isStarted = true; - - bt_gatt_set_connection_state_changed_cb(onGattConchanged, NULL); - - int ret = BT_ERROR_NONE; - bt_gatt_server_h server = NULL; - bt_gatt_h service = NULL; - bt_gatt_h ctrl_pt_write_req = NULL; - bt_gatt_h ctrl_pt_notif_resp = NULL; - int permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE; - - /*Notification enabled */ - char *reqVal = (char*)calloc(MAX_BLE_SIZE, sizeof(char)); - char *respVal = (char*)calloc(MAX_BLE_SIZE, sizeof(char)); - - ret = bt_gatt_server_initialize(); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth ragent bt_gatt_server_initialize=[%d]", ret); - goto FAIL; - } - - ret = bt_gatt_server_create(&server); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth ragent bt_gatt_server_create=[%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent gatt service create"); - ret = bt_gatt_service_create(RA_BLE_SERVICE_UUID, BT_GATT_SERVICE_TYPE_PRIMARY, &service); - if (ret != BT_ERROR_NONE) - goto FAIL; - - _INFO("bluetooth ragent Create GATT Characteristic"); - /* Create GATT Characteristic */ - ret = bt_gatt_characteristic_create(RA_BLE_UUID_REQUEST, - permissions, - BT_GATT_PROPERTY_WRITE, - reqVal, - MAX_BLE_SIZE, - &ctrl_pt_write_req); - if (ret != BT_ERROR_NONE) - goto FAIL; - - ret = bt_gatt_characteristic_create(RA_BLE_UUID_RESPONSE, - permissions, - BT_GATT_PROPERTY_NOTIFY, - respVal, - MAX_BLE_SIZE, - &ctrl_pt_notif_resp); - - _INFO("bluetooth ragent set GATT Characterisitic Callback"); - - ret = bt_gatt_server_set_write_value_requested_cb(ctrl_pt_write_req, - __ra__write_value_requested_cb, NULL); - if (ret != BT_ERROR_NONE) - goto FAIL; - - _INFO("bluetooth ragent Add GATT Characteristic in service"); - /* add GATT Characteristic in service */ - ret = bt_gatt_service_add_characteristic(service, ctrl_pt_write_req); - if (ret != BT_ERROR_NONE) - goto FAIL; - - ret = bt_gatt_service_add_characteristic(service, ctrl_pt_notif_resp); - if (ret != BT_ERROR_NONE) - goto FAIL; - - _INFO("bluetooth ragent Register GATT Service"); - ret = bt_gatt_server_register_service(server, service); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent can not register gatt service."); - goto FAIL; - } - - - _INFO("bluetooth ragent GATT Server Done"); - - ret = bt_gatt_server_start(); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_gatt_server_start failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent GATT Server started"); - - _INFO("bluetooth ragent starting LE adv"); - bt_advertiser_h adv_handle = NULL; - ret = bt_adapter_le_create_advertiser(&adv_handle); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_create_advertiser failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent after bt_adapter_le_create_advertiser"); - - ret = bt_adapter_le_set_advertising_connectable(adv_handle, true); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_set_advertising_connectable failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent after bt_adapter_le_set_advertising_connectable"); - - ret = bt_adapter_le_add_advertising_service_uuid(adv_handle, - BT_ADAPTER_LE_PACKET_ADVERTISING, RA_BLE_ADVERTISING_UUID); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_add_advertising_service_uuid failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent after bt_adapter_le_add_advertising_service_uuid"); - - ret = bt_adapter_le_set_advertising_device_name(adv_handle, - BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, true); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_set_advertising_device_name failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent after bt_adapter_le_set_advertising_device_name"); - - ret = bt_adapter_le_start_advertising_new(adv_handle, - __advertising_state_changed_cb, adv_handle); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_start_advertising_new failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent LE adv done"); - return 0; - -FAIL: - _INFO("bluetooth ragent ERROR"); - bt_gatt_characteristic_destroy(ctrl_pt_write_req); - bt_gatt_characteristic_destroy(ctrl_pt_notif_resp); - bt_gatt_service_destroy(service); - bt_gatt_server_destroy(server); - - return -1; -} - -static int -__fido_gatt_server_stop(void) -{ - _INFO("bluetooth Stopping GATT server"); - __isStarted = false; - bt_gatt_server_deinitialize(); - return 0; -} - -static void -__bt_state_changed_cb(int result, bt_adapter_state_e adapter_state, void* user_data) -{ - _INFO("bluetooth __bt_state_changed_cb=[%d]", adapter_state); - if (adapter_state == BT_ADAPTER_ENABLED) { - __fido_gatt_server_start(); - } -} - -int -fido_gatt_server_shutdown(void) -{ - return __fido_gatt_server_stop(); -} - -int -fido_gatt_server_init(void) -{ - int ret = bt_initialize(); - if ((ret != BT_ERROR_NONE) && (ret != BT_ERROR_ALREADY_DONE)) { - _ERR("bluetooth bt_init failed = [%d]", ret); - return -1; - } - - __isStarted = false; - - bt_adapter_set_state_changed_cb(__bt_state_changed_cb, NULL); - - bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED; - ret = bt_adapter_get_state(&adapter_state); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth bt_adapter_get_state failed = [%d]", ret); - return -1; - } - - if (adapter_state == BT_ADAPTER_ENABLED) { - return __fido_gatt_server_start(); - } - - return 0; -} diff --git a/ble_roaming_agent/src/fido_gatt_server.h b/ble_roaming_agent/src/fido_gatt_server.h deleted file mode 100644 index b03954b..0000000 --- a/ble_roaming_agent/src/fido_gatt_server.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _FIDO_GATT_SERVER_H_ -#define _FIDO_GATT_SERVER_H_ - - -int fido_gatt_server_init(void); -int fido_gatt_server_shutdown(void); - - -#endif /* _FIDO_GATT_SERVER_H_ */ diff --git a/bt_roaming_agent/src/bt_server.c b/bt_roaming_agent/src/bt_server.c index ce0ed1a..0154dd6 100644 --- a/bt_roaming_agent/src/bt_server.c +++ b/bt_roaming_agent/src/bt_server.c @@ -503,5 +503,7 @@ bt_server_stop(void) bt_socket_destroy_rfcomm(server->server_socket_fd); __destroy_server_handle(server); server = NULL; + int ret = bt_deinitialize(); + _INFO("bt_deinitialize=[%d]", ret); return 0; } diff --git a/common/cryptoutil/src/AsmCrypto.cpp b/common/cryptoutil/src/AsmCrypto.cpp index c42d9cb..24eb33d 100644 --- a/common/cryptoutil/src/AsmCrypto.cpp +++ b/common/cryptoutil/src/AsmCrypto.cpp @@ -156,6 +156,8 @@ AsmCrypto::getAsmToken(void) _INFO("%s", macStr.c_str()); asmTok = strdup(macClone); SAFE_DELETE(macClone); + + bt_deinitialize(); return macStr; } } else { @@ -172,6 +174,8 @@ AsmCrypto::getAsmToken(void) _INFO("%s", macStr.c_str()); asmTok = strdup(macClone); SAFE_DELETE(macClone); + + bt_deinitialize(); return macStr; } @@ -214,6 +218,7 @@ AsmCrypto::getAsmToken(void) asmTok = strdup(mac); SAFE_DELETE(mac); + bt_deinitialize(); return tok; } else { @@ -222,11 +227,15 @@ AsmCrypto::getAsmToken(void) if (size <= 0) { fclose(file); _END; + + bt_deinitialize(); return std::string(); } else if (size > 1000) { _ERR("Too big config file, size=[%d], allowed=[1000]", size); fclose(file); _END; + + bt_deinitialize(); return std::string(); } @@ -238,6 +247,8 @@ AsmCrypto::getAsmToken(void) free(config); fclose(file); _END; + + bt_deinitialize(); return std::string(); } @@ -249,6 +260,8 @@ AsmCrypto::getAsmToken(void) _END; asmTok = strdup(config); SAFE_DELETE(config); + + bt_deinitialize(); return tok; } } diff --git a/fido-ble-ragent.manifest b/fido-ble-ragent.manifest deleted file mode 100644 index 97e8c31..0000000 --- a/fido-ble-ragent.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/fido-asm.spec b/packaging/fido-asm.spec index 83ef1df..d327014 100644 --- a/packaging/fido-asm.spec +++ b/packaging/fido-asm.spec @@ -9,8 +9,6 @@ Source0: fido-asm-%{version}.tar.gz Source1: org.tizen.fido-asm.service Source2: org.tizen.fido-asm.conf Source3: fido-asm.service -Source4: fido-roaming-agent.service -##Source5: fido-ble-roaming-agent.service Source6: fido-bt-roaming-agent.service BuildRequires: cmake @@ -91,10 +89,6 @@ install -m 644 %SOURCE3 %{buildroot}%{_unitdir}/fido-asm.service mkdir -p %{buildroot}%{_libdir}/fido/asm/auth mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants -install -m 0644 %SOURCE4 %{buildroot}%{_unitdir}/fido-roaming-agent.service -%install_service multi-user.target.wants fido-roaming-agent.service - -mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants install -m 0644 %SOURCE6 %{buildroot}%{_unitdir}/fido-bt-roaming-agent.service %install_service multi-user.target.wants fido-bt-roaming-agent.service @@ -261,68 +255,6 @@ rm -r /opt/usr/data/silent_auth/ /opt/usr/data/silent_auth/fido_tizen_auth.key ################################################################################# -# FIDO IoT Roaming Agent -################################################################################# -%package -n fido_roaming_agent -Summary: FIDO Roaming Agent -Group: Account - -BuildRequires: cmake -BuildRequires: pkgconfig(capi-appfw-application) -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(bundle) -BuildRequires: pkgconfig(json-glib-1.0) -BuildRequires: pkgconfig(glib-2.0) >= 2.26 -BuildRequires: pkgconfig(gio-unix-2.0) -BuildRequires: pkgconfig(capi-network-connection) - - -%description -n fido_roaming_agent -FIDO Roaming Agent IoTivity Server - -%post -n fido_roaming_agent -mkdir -p /opt/data/fido-ra/ -chown -R service_fw:service_fw /opt/data/fido-ra/ -chsmack -a '_' /opt/data/fido-ra/ - -chown -R service_fw:service_fw /opt/data/fido-ra/*.dat -chsmack -a '_' /opt/data/fido-ra/*.dat - -%files -n fido_roaming_agent -%manifest fido-roaming-agent.manifest -%{_bindir}/* -%{_unitdir}/fido-roaming-agent.service -%{_unitdir}/multi-user.target.wants/fido-roaming-agent.service -%attr(0777,service_fw,service_fw)/opt/data/fido-ra/*.dat - -################################################################################# -# FIDO BLE Roaming Agent -################################################################################# -##%package -n fido_ble_roaming_agent -##Summary: FIDO BLE Roaming Agent -##Group: Account - -##BuildRequires: cmake -##BuildRequires: pkgconfig(capi-appfw-application) -##BuildRequires: pkgconfig(dlog) -##BuildRequires: pkgconfig(bundle) -##BuildRequires: pkgconfig(json-glib-1.0) -##BuildRequires: pkgconfig(glib-2.0) >= 2.26 -##BuildRequires: pkgconfig(gio-unix-2.0) -##BuildRequires: pkgconfig(capi-network-connection) -##BuildRequires: pkgconfig(capi-network-bluetooth) - - -##%description -n fido_ble_roaming_agent -##FIDO BT Roaming Agent GATT Server - -##%files -n fido_ble_roaming_agent -##%manifest fido-ble-ragent.manifest -##%{_bindir}/fido-ble-ragent-service -##%{_unitdir}/fido-ble-roaming-agent.service -##%{_unitdir}/multi-user.target.wants/fido-ble-roaming-agent.service - -################################################################################# # FIDO BT Roaming Agent ################################################################################# %package -n fido_bt_roaming_agent diff --git a/roaming_agent/CMakeLists.txt b/roaming_agent/CMakeLists.txt deleted file mode 100644 index 3039ec9..0000000 --- a/roaming_agent/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -SET(RAGENT_DAEMON fido-roaming-agent-service) - -INCLUDE(FindPkgConfig) -pkg_check_modules(RAGENT_DAEMON_PKGS REQUIRED - dlog - db-util - glib-2.0 - capi-base-common - pkgmgr-info - gio-2.0 - gio-unix-2.0 - gmodule-2.0 - cynara-client - cynara-session - cynara-creds-gdbus - capi-network-connection - capi-base-common - capi-appfw-application - capi-appfw-app-manager - aul - json-glib-1.0 - iotcon - capi-system-info - capi-system-system-settings -) - -FOREACH(flag ${RAGENT_DAEMON_PKGS_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}") -SET(PKGS_LDFLAGS "${RAGENT_DAEMON_PKGS_LDFLAGS} -pie") - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/roaming_agent/inc/) - -FILE( GLOB RAGENT_DAEMON_SRCS_CC - src/*.c -) - -ADD_EXECUTABLE(${RAGENT_DAEMON} ${RAGENT_DAEMON_SRCS_CC}) - -TARGET_LINK_LIBRARIES(${RAGENT_DAEMON} ${RAGENT_DAEMON_PKGS_LDFLAGS} fido-asm-dbus "-ldl") - -INSTALL(TARGETS ${RAGENT_DAEMON} DESTINATION bin) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/common/fido-ra-acl-server.dat DESTINATION /opt/data/fido-ra) diff --git a/roaming_agent/inc/RoamingKeys.h b/roaming_agent/inc/RoamingKeys.h deleted file mode 100644 index 3b23bf9..0000000 --- a/roaming_agent/inc/RoamingKeys.h +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#ifndef ROAMINGKEYS_H -#define ROAMINGKEYS_H - -#define RA_RESOURCE_URI "/fido/auth/roaming/pin" -#define RA_RESOURCE_TYPE "org.tizen.fidoauthroamingpin" - -#define RA_QUERY_KEY_REQUEST "ra_query_prcoess_tlv" -#define RA_QUERY_KEY_SERVER_ID "ra_query_server_id" -#define RA_QUERY_KEY_RESPONSE "ra_response" - -#define RA_ACL_SERVER tzplatform_mkpath(TZ_SYS_DATA, "fido-ra/fido-ra-acl-server.dat") -#define RA_ACL_CLIENT tzplatform_mkpath(TZ_SYS_DATA, "fido-asm/fido-ra-acl-client.dat") - -#endif // ROAMINGKEYS_H diff --git a/roaming_agent/src/iotcon_handler.c b/roaming_agent/src/iotcon_handler.c deleted file mode 100644 index 1703d64..0000000 --- a/roaming_agent/src/iotcon_handler.c +++ /dev/null @@ -1,504 +0,0 @@ -/* - * iotcon_handler.c - * - * Created on: May 16, 2016 - * Author: manasij.r - */ - -#include -#include -#include -#include - -#include -#include - -#include "iotcon_handler.h" -#include "RoamingKeys.h" -#include "AsmHelper.h" -#include "fido-client-ipc-stub.h" - -#include -#include -#include - -#define IC_FEATURE_OIC "http://tizen.org/feature/iot.oic" -#define IC_FEATURE_OCF "http://tizen.org/feature/iot.ocf" - -#include - -//#define ASM_GET_INFO_RESP "{\"responseData\":{\"Authenticators\":[{\"aaid\":\"R001#8001\",\"asmVersions\":[{\"major\":1,\"minor\":0}],\"assertionScheme\":\"UAFV1TLV\",\"title\":\"UAF PIN Roaming\",\"attestationTypes\":[15879],\"tcDisplayContentType\":\"text/plain\",\"description\":\"Tizen Roaming PIN Authenticator\",\"supportedExtensionIDs\":[\"abc\"],\"icon\":\"data:image/png;base64,iVBORw0KGgoAAA\",\"isRoamingAuthenticator\":true,\"isSecondFactorOnly\":false,\"isUserEnrolled\":true,\"keyProtection\":1,\"matcherProtection\":1,\"hasSettings\":true,\"tcDisplay\":1,\"authenticatorIndex\":9,\"authenticationAlgorithm\":1,\"attachmentHint\":2,\"userVerification\":4}]},\"statusCode\":0}" - -/* ra Resource */ -typedef struct _ra_resource_s { - bool state; - char *uri_path; - char *type; - iotcon_resource_interfaces_h ifaces; - int properties; - iotcon_resource_h handle; - iotcon_observers_h observers; - iotcon_representation_h repr; -} ra_resource_s; - -static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, - void *user_data); - -static Fidoasm* -__asm_get_dbus_proxy(void) -{ -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - - GDBusConnection *connection = NULL; - GError *error = NULL; - - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - - /* Create the object */ - Fidoasm *dbus_proxy = fidoasm_proxy_new_sync(connection, - G_DBUS_PROXY_FLAGS_NONE, - "org.tizen.fidoasm", - "/org/tizen/fidoasm", - NULL, - &error); - - if (error != NULL) - _ERR("fidoasm_proxy_new_sync failed %s", error->message); - - return dbus_proxy; -} - -static int -_set_ra_resource(ra_resource_s *ra) -{ - _INFO("_set_ra_resource"); - - int ret; - - ra->state = false; - - ra->uri_path = strdup(RA_RESOURCE_URI); - if (NULL == ra->uri_path) { - return -1; - } - - ra->type = strdup(RA_RESOURCE_TYPE); - if (NULL == ra->type) { - free(ra->uri_path); - return -1; - } - - ret = iotcon_resource_interfaces_create(&ra->ifaces); - if (IOTCON_ERROR_NONE != ret) { - free(ra->type); - free(ra->uri_path); - return -1; - } - - ret = iotcon_resource_interfaces_add(ra->ifaces, IOTCON_INTERFACE_DEFAULT); - if (IOTCON_ERROR_NONE != ret) { - iotcon_resource_interfaces_destroy(ra->ifaces); - free(ra->type); - free(ra->uri_path); - return -1; - } - - ra->properties = IOTCON_RESOURCE_DISCOVERABLE; - -// ret = iotcon_observers_create(&ra->observers); -// if (IOTCON_ERROR_NONE != ret) { -// iotcon_resource_interfaces_destroy(ra->ifaces); -// free(ra->type); -// free(ra->uri_path); -// return -1; -// } - - _INFO("_set_ra_resource end"); - - return 0; -} - -static void _free_ra_resource(ra_resource_s *ra) -{ - iotcon_observers_destroy(ra->observers); - iotcon_resource_interfaces_destroy(ra->ifaces); - free(ra->type); - free(ra->uri_path); -} - -static iotcon_resource_h -_create_ra_resource(char *uri_path, char *type, - iotcon_resource_interfaces_h ifaces, int properties, void *user_data) -{ - _INFO("_create_ra_resource start"); - - int ret; - iotcon_resource_h handle; - iotcon_resource_types_h resource_types; - - ret = iotcon_resource_types_create(&resource_types); - if (IOTCON_ERROR_NONE != ret) { - return NULL; - } - - ret = iotcon_resource_types_add(resource_types, type); - if (IOTCON_ERROR_NONE != ret) { - iotcon_resource_types_destroy(resource_types); - return NULL; - } - - /* register ra resource */ - ret = iotcon_resource_create(uri_path, resource_types, ifaces, properties, - _request_handler, user_data, &handle); - if (IOTCON_ERROR_NONE != ret) { - iotcon_resource_types_destroy(resource_types); - return NULL; - } - - iotcon_resource_types_destroy(resource_types); - - _INFO("_create_ra_resource end"); - - return handle; -} - -static int -_send_response(iotcon_request_h request, iotcon_representation_h repr, - iotcon_response_result_e result) -{ - _INFO("_send_response start"); - - int ret; - iotcon_response_h response; - - ret = iotcon_response_create(request, &response); - if (IOTCON_ERROR_NONE != ret) { - return -1; - } - - ret = iotcon_response_set_result(response, result); - if (IOTCON_ERROR_NONE != ret) { - iotcon_response_destroy(response); - return -1; - } - - ret = iotcon_response_set_representation(response, repr); - if (IOTCON_ERROR_NONE != ret) { - iotcon_response_destroy(response); - return -1; - } - - /* send Representation to the client */ - ret = iotcon_response_send(response); - if (IOTCON_ERROR_NONE != ret) { - iotcon_response_destroy(response); - return -1; - } - - iotcon_response_destroy(response); - - _INFO("_send_response end"); - - return 0; -} - -static iotcon_representation_h -_create_ra_representation(ra_resource_s *ra, char *tlvRespB64) -{ - _INFO("_get_ra_representation start"); - - int ret; - iotcon_attributes_h state = NULL; - iotcon_representation_h repr = NULL; - - /* create a ra Representation */ - ret = iotcon_representation_create(&repr); - if (IOTCON_ERROR_NONE != ret) { - return NULL; - } - - _INFO("After iotcon_representation_create"); - - /* create a ra state */ - ret = iotcon_attributes_create(&state); - if (IOTCON_ERROR_NONE != ret) { - iotcon_representation_destroy(repr); - return NULL; - } - - _INFO("After iotcon_attributes_create"); - - ret = iotcon_representation_set_uri_path(repr, RA_RESOURCE_URI/*ra->uri_path*/); - if (IOTCON_ERROR_NONE != ret) { - iotcon_attributes_destroy(state); - iotcon_representation_destroy(repr); - return NULL; - } - - _INFO("After iotcon_representation_set_uri_path"); - - /*TODO:Call Mobile ASM with the incoming query (Base64 decoded TLV)*/ - //char tlv_b64_dec[5000] = {0,}; - //snprintf(tlv_b64_dec, 4999, "%s", ASM_GET_INFO_RESP); - ret = iotcon_attributes_add_str(state, RA_QUERY_KEY_RESPONSE, tlvRespB64); - if (IOTCON_ERROR_NONE != ret) { - iotcon_attributes_destroy(state); - iotcon_representation_destroy(repr); - return NULL; - } - - _INFO("After iotcon_attributes_add_str"); - ret = iotcon_representation_set_attributes(repr, state); - if (IOTCON_ERROR_NONE != ret) { - iotcon_attributes_destroy(state); - iotcon_representation_destroy(repr); - return NULL; - } - - //iotcon_attributes_destroy(state); - - _INFO("After end [%p]", repr); - return repr; -} - -char* -__getServerId(void) -{ - connection_h conn = NULL; - connection_create(&conn); - - static char *mac = NULL; - if (mac != NULL) - return mac; - - /*Try: Ethernet*/ - int ret = connection_get_mac_address(conn, CONNECTION_TYPE_ETHERNET, &mac); - - /*Try: Wifi*/ - if (ret != CONNECTION_ERROR_NONE) - ret = connection_get_mac_address(conn, CONNECTION_TYPE_WIFI, &mac); - - /*Try: BT*/ - if (ret != CONNECTION_ERROR_NONE) - ret = connection_get_mac_address(conn, CONNECTION_TYPE_BT, &mac); - - return mac; -} - -static int -_request_handler_put(ra_resource_s *ra, iotcon_request_h request) -{ - _INFO("_request_handler_put start"); - - int ret = 0; - - iotcon_representation_h repr = NULL; - iotcon_request_get_representation(request, &repr); - if (repr == NULL) { - _ERR("iotcon_request_get_representation failed"); - return -1; - } - - iotcon_attributes_h attr = NULL; - iotcon_representation_get_attributes(repr, &attr); - if (attr == NULL) { - _ERR("iotcon_representation_get_attributes failed"); - return -1; - } - - char *tlvReqB64 = NULL; - iotcon_attributes_get_str(attr, RA_QUERY_KEY_REQUEST, &tlvReqB64); - if (tlvReqB64 == NULL) { - _ERR("[%s] key missing", RA_QUERY_KEY_REQUEST); - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - - return -1; - } - - char *serverId = NULL; - iotcon_attributes_get_str(attr, RA_QUERY_KEY_SERVER_ID, &serverId); - if (serverId == NULL) { - _ERR("[%s] key missing", RA_QUERY_KEY_SERVER_ID); - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - - return -1; - } - - if (strcmp(serverId, __getServerId()) == 0) { - _ERR("Request from same Device is ignored"); - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - - return -1; - } - - - /*Call ASM dbus and receive the response*/ - Fidoasm *asm_proxy = __asm_get_dbus_proxy(); - if (asm_proxy == NULL) { - _ERR("Failed to get ASM proxy"); - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - return -1; - } - - - char *tlvRespB64 = NULL; - GError *gErr = NULL; - int tz_err = 0; - fidoasm_call_asm_request_sync(asm_proxy, tlvReqB64, - &tz_err, &tlvRespB64, NULL, &gErr); - if (gErr != NULL) { - - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - _ERR("Failed returned from ASM"); - return -1; - } - - iotcon_representation_h resp_repr; - - resp_repr = _create_ra_representation(ra, tlvRespB64); - if (NULL == resp_repr) { - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - _ERR("RA representation create failed"); - return -1; - } - - ret = _send_response(request, resp_repr, IOTCON_RESPONSE_OK); - if (0 != ret) { - iotcon_representation_destroy(resp_repr); - return -1; - } - - iotcon_representation_destroy(resp_repr); - - return 0; -} - -//static bool -//_query_cb(const char *key, const char *value, void *user_data) -//{ -// return IOTCON_FUNC_CONTINUE; -//} - -static void -_request_handler(iotcon_resource_h resource, iotcon_request_h request, - void *user_data) -{ - _INFO("_request_handler start"); - - /*TODO: Only allow if request is not coming from the same device*/ - - ra_resource_s *ra; - iotcon_query_h query; - //int ret, observe_id; - iotcon_request_type_e type; - //iotcon_observe_type_e observe_type; - //char *host_address; - - if (request == NULL) - return; - - int ret = iotcon_request_get_query(request, &query); - if (IOTCON_ERROR_NONE != ret) { - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - return; - } -// if (query) -// iotcon_query_foreach(query, _query_cb, NULL); - - ret = iotcon_request_get_request_type(request, &type); - if (IOTCON_ERROR_NONE != ret) { - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - return; - } - - - ra = user_data; - - - if (IOTCON_REQUEST_PUT == type) { - ret = _request_handler_put(ra, request); - } - else { - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - } - -} - -static bool -__iotcon_handler_is_supported(void) -{ - bool raSupported = false; - system_info_get_platform_bool(IC_FEATURE_OIC, &raSupported); - if (raSupported == false) - system_info_get_platform_bool(IC_FEATURE_OCF, &raSupported); - - return raSupported; -} - -int -iotcon_handler_init(void) -{ - _INFO("iotcon_handler_init"); - if (__iotcon_handler_is_supported() == false) { - _ERR("RA not supported"); - return -1; - } - - int ret; - ra_resource_s ra = {0}; - - - /* initialize iotcon */ - ret = iotcon_initialize(RA_ACL_SERVER); - if (IOTCON_ERROR_NONE != ret) { - return -1; - } - - /* set local ra resource */ - ret = _set_ra_resource(&ra); - if (0 != ret) { - iotcon_deinitialize(); - return -1; - } - - /* add resource options */ - ret = iotcon_resource_interfaces_add(ra.ifaces, IOTCON_INTERFACE_BATCH); - if (IOTCON_ERROR_NONE != ret) { - _free_ra_resource(&ra); - iotcon_deinitialize(); - - return -1; - } - //ra.properties |= IOTCON_RESOURCE_OBSERVABLE; - - /* add presence */ - //g_timeout_add_seconds(10, _presence_timer, NULL); - //iotcon_start_presence(10); - - /* create new ra resource */ - ra.handle = _create_ra_resource(ra.uri_path, ra.type, ra.ifaces, - ra.properties, &ra); - if (NULL == ra.handle) { - - _free_ra_resource(&ra); - iotcon_deinitialize(); - return -1; - } - - //_check_ra_state(my_ra); - - - //iotcon_resource_destroy(ra.handle); - - //_free_ra_resource(&ra); - - /* deinitialize iotcon */ - //iotcon_deinitialize(); - - return 0; -} - - - diff --git a/roaming_agent/src/iotcon_handler.h b/roaming_agent/src/iotcon_handler.h deleted file mode 100644 index 6513123..0000000 --- a/roaming_agent/src/iotcon_handler.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * iotcon_handler.h - * - * Created on: May 16, 2016 - * Author: manasij.r - */ - -#ifndef IOTCON_HANDLER_H_ -#define IOTCON_HANDLER_H_ - - -int iotcon_handler_init(void); - - -#endif /* IOTCON_HANDLER_H_ */ diff --git a/roaming_agent/src/ragent_main.c b/roaming_agent/src/ragent_main.c deleted file mode 100644 index 512f4d9..0000000 --- a/roaming_agent/src/ragent_main.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved. - * - * 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. - * - */ - -#include -#include - -#include "iotcon_handler.h" -#include "AsmHelper.h" - -int -main(int argc, char *argv[]) -{ - _INFO("Starting Roaming Agent Service"); - - int ret = iotcon_handler_init(); - if (ret != 0) { - _ERR("iotcon init failed [%d]", ret); - - return 0; - } - - GMainLoop *mainloop = g_main_loop_new(NULL, FALSE); - - g_main_loop_run(mainloop); - - _INFO("Stopping Roaming Agent Service"); - - return 0; -} diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 3ad6f4a..b72b411 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -22,7 +22,6 @@ pkg_check_modules(SERVICE_PKGS REQUIRED openssl aul json-glib-1.0 - iotcon openssl capi-system-info capi-system-system-settings diff --git a/server/auth_discovery/inc/BleAdProvider.h b/server/auth_discovery/inc/BleAdProvider.h deleted file mode 100644 index c59a96b..0000000 --- a/server/auth_discovery/inc/BleAdProvider.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _BLE_AD_PROVIDER_H -#define _BLE_AD_PROVIDER_H - -#include - -#include "IADProvider.h" -#include - -class BleAdProvider : public IADProvider { - friend class AuthManager; -public: - virtual int init(void); - virtual auth_type_e getType(void); - virtual std::vector *getAuthStubList(void); - virtual void setCache(std::map *stubCache); - virtual IAuthStub* getStubFromCache(int mappedIdx); - - virtual ~BleAdProvider(void); - -private: - BleAdProvider(void); - - static void onGattConchanged(int result, bool connected, - const char *remote_address, void *user_data); - static void onBtStateChanged(int result, bt_adapter_state_e adapter_state, - void *user_data); - static void onLEScanResult(int result, bt_adapter_le_device_scan_result_info_s *info, - void *user_data); - static void finishDiscovery(gpointer data); - static gboolean discoverTimeOutCb(gpointer user_data); - -private: - std::map *__stubCache; - - GMainLoop *__waitLoop; - bool __isValidInst; -}; - -#endif // _BLE_AD_PROVIDER_H diff --git a/server/auth_discovery/inc/BleCon.h b/server/auth_discovery/inc/BleCon.h deleted file mode 100644 index 221deb2..0000000 --- a/server/auth_discovery/inc/BleCon.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _BLE_CON_H -#define _BLE_CON_H - -#include "IAuthConnection.h" -#include -#include - -class GattClient { -public: - GattClient(void) - { - __btClientInfo = NULL; - __btClient = NULL; - __btClientSvc = NULL; - __btClientChrReq = NULL; - __btClientChrResp = NULL; - } - -public: - /*bt_adapter_le_device_scan_result_info_s *__btClientInfo;*/ - char *__btClientInfo; - bt_gatt_client_h __btClient; - bt_gatt_h __btClientSvc; - bt_gatt_h __btClientChrReq; - bt_gatt_h __btClientChrResp; -}; - -class BleCon : public IAuthConnection { -public: - BleCon(void); - ~BleCon(void); - - virtual int init(void *handle); - virtual StringMap* sendReqSync(StringMap *reqData); - virtual int shutdown(void); - virtual char* getInfo(void); -private: - static void onGattServerResponse(bt_gatt_h characteristic, char *value, - int len, void *user_data); - static void onGattWriteComplete(int result, bt_gatt_h request_handle, - void *user_data); -private: - GattClient *__gClient; - GMainLoop *__waitLoop; - StringMap *__resp; -}; - -#endif // _BLE_CON_H diff --git a/server/auth_discovery/inc/BtAdProvider.h b/server/auth_discovery/inc/BtAdProvider.h index 6925333..bfce2d9 100644 --- a/server/auth_discovery/inc/BtAdProvider.h +++ b/server/auth_discovery/inc/BtAdProvider.h @@ -34,6 +34,7 @@ private: bool __isDiscovering; char *__sAddr; bool __isConCbSet; + int __btInitResult; }; #endif // BTADPROVIDER_H diff --git a/server/auth_discovery/inc/IoTCon.h b/server/auth_discovery/inc/IoTCon.h deleted file mode 100644 index f337023..0000000 --- a/server/auth_discovery/inc/IoTCon.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef IOTCON_H -#define IOTCON_H - -#include "IAuthConnection.h" -#include -#include - -class IoTCon : public IAuthConnection { -public: - - IoTCon(void); - ~IoTCon(void); - - virtual int init(void *handle); - virtual StringMap* sendReqSync(StringMap *reqData); - virtual int shutdown(void); - virtual char* getInfo(void); - -private: - static void onResponsePut(iotcon_remote_resource_h resource, iotcon_error_e err, - iotcon_request_type_e request_type, iotcon_response_h response, void *user_data); -private: - GMainLoop *__waitLoop; - iotcon_remote_resource_h __iotClient; - StringMap* __resp; -}; - -#endif // IOTCON_H diff --git a/server/auth_discovery/inc/IotADProvider.h b/server/auth_discovery/inc/IotADProvider.h deleted file mode 100644 index cc1dc28..0000000 --- a/server/auth_discovery/inc/IotADProvider.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved. - * - * 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. - * - */ - -#ifndef _IOT_ADP_H_ -#define _IOT_ADP_H_ - -#include -#include -#include -#include - -#include "IADProvider.h" - -class IAuthStub; - -class IotADProvider : public IADProvider { - - friend class AuthManager; -public: - virtual int init(void); - virtual auth_type_e getType(void); - virtual std::vector *getAuthStubList(void); - virtual void setCache(std::map *stubCache); - virtual IAuthStub* getStubFromCache(int mappedIdx); - - virtual ~IotADProvider(void); - static void finishDiscovery(gpointer data); - static gboolean discoverTimeOutCb(gpointer user_data); - static bool resourceFoundCb(iotcon_remote_resource_h resource, iotcon_error_e result, - void *user_data); -private: - IotADProvider(void); - -private: - /*std::vector *__authList;*/ - std::map *__stubCache; - - GMainLoop *__waitLoop; - bool __isValidInst; - -}; - -#endif /* _IOT_ADP_H_ */ diff --git a/server/auth_discovery/inc/RoamingUtil.h b/server/auth_discovery/inc/RoamingUtil.h index a67e891..24e88aa 100644 --- a/server/auth_discovery/inc/RoamingUtil.h +++ b/server/auth_discovery/inc/RoamingUtil.h @@ -31,10 +31,6 @@ public: static bool isRASupported(void); - static std::string getBTMACAddr(void); - static std::string getDevName(void); - static std::string getP2PMACAddr(void); - static char *getServerId(void); private: RoamingUtil(void) {} diff --git a/server/auth_discovery/src/AuthManager.cpp b/server/auth_discovery/src/AuthManager.cpp index adfb8cb..65bc999 100644 --- a/server/auth_discovery/src/AuthManager.cpp +++ b/server/auth_discovery/src/AuthManager.cpp @@ -21,9 +21,7 @@ #include #include "BoundADProvider.h" -#include "IotADProvider.h" #include "RoamingUtil.h" -#include "BleAdProvider.h" #include "BtAdProvider.h" AuthManager* AuthManager::__this = NULL; @@ -37,29 +35,6 @@ AuthManager::initProviders(void) _INFO("Bound Provider=[%p]", badPro); __providerList.push_back(badPro); - -// if (RoamingUtil::isRASupported() == true) { -// IADProvider *radPro = new IotADProvider(); -// int retRa = radPro->init(); -// if (retRa == 0) { -// _INFO("Roaming Provider=[%p]", radPro); -// __providerList.push_back(radPro); -// } else { -// _INFO("RA not supported"); -// delete radPro; -// } -// } - -// IADProvider *blePro = new BleAdProvider(); -// int retBle = blePro->init(); -// if (retBle == 0) { -// _INFO("BLE Provider=[%p]", blePro); -// __providerList.push_back(blePro); -// } else { -// _INFO("BLE Provider not supported"); -// delete blePro; -// } - IADProvider *btPro = new BtAdProvider(); int retBt = btPro->init(); if (retBt == 0) { diff --git a/server/auth_discovery/src/BleAdProvider.cpp b/server/auth_discovery/src/BleAdProvider.cpp deleted file mode 100644 index 1f66ec7..0000000 --- a/server/auth_discovery/src/BleAdProvider.cpp +++ /dev/null @@ -1,415 +0,0 @@ - -#include "BleAdProvider.h" -#include "IAuthConnection.h" -#include "BleCon.h" -#include "RAuthStub.h" -#include "AsmHelper.h" -#include "BTRoamingKeys.h" - -/*BLE is not working on 3.0*/ -#define DISABLE_BLE - -void -BleAdProvider::onBtStateChanged(int result, bt_adapter_state_e adapter_state, - void *user_data) -{ - _INFO("bluetooth onBtStateChanged=[%d]", adapter_state); - BleAdProvider *btPro = (BleAdProvider*)user_data; - if (adapter_state == BT_ADAPTER_DISABLED) { - if (btPro->__stubCache != NULL) { - _INFO("bluetooth Deletting cache=[%p]", btPro->__stubCache); - delete btPro->__stubCache; - btPro->__stubCache = NULL; - } - } -} - -int -BleAdProvider::init(void) -{ -#ifdef DISABLE_BLE - _INFO("BLE is disabled by ASM"); - return -1; -#endif - - _INFO("bluetooth "); - __stubCache = NULL; - int ret = bt_initialize(); - if(ret != BT_ERROR_NONE && ret != BT_ERROR_ALREADY_DONE) { - _ERR("bluetooth rclient bluetooth service can not initialize=[%d]", ret); - return -1; - } - - bt_adapter_set_state_changed_cb(onBtStateChanged, this); - _INFO("bluetooth "); - return 0; -} - -auth_type_e -BleAdProvider::getType(void) -{ - return AUTH_TYPE_ROAMING; -} - -static bool -__bt_gatt_client_foreach_desc_cb(int total, int index, bt_gatt_h desc_handle, void *data) -{ - char *uuid = NULL; - - bt_gatt_get_uuid(desc_handle, &uuid); - - _INFO("bluetooth [%d / %d] uuid: (%s)", index, total, uuid); - - g_free(uuid); - - return true; -} - -static bool -__bt_gatt_client_foreach_chr_cb(int total, int index, bt_gatt_h chr_handle, void *data) -{ - int ret; - char *uuid = NULL; - - bt_gatt_get_uuid(chr_handle, &uuid); - - _INFO("bluetooth [%d / %d] uuid: (%s)", index, total, uuid); - - g_free(uuid); - - ret = bt_gatt_characteristic_foreach_descriptors(chr_handle, - __bt_gatt_client_foreach_desc_cb, NULL); - if (ret != BT_ERROR_NONE) - _INFO("bluetooth bt_gatt_characteristic_foreach_descriptors failed: %d", ret); - - return true; -} - -static bool -__svcCb(int total, int index, bt_gatt_h gatt_handle, - void *user_data) -{ - int ret; - char *uuid = NULL; - - bt_gatt_get_uuid(gatt_handle, &uuid); - _INFO("bluetooth [%d / %d] uuid: (%s)", index, total, uuid); - - g_free(uuid); - - ret = bt_gatt_service_foreach_characteristics(gatt_handle, - __bt_gatt_client_foreach_chr_cb, NULL); - if (ret != BT_ERROR_NONE) - _INFO("bluetooth bt_gatt_service_foreach_characteristics failed: %d", ret); - - return true; -} - -#define printIfAndRet(e1, e2, str) \ - if (e1 == e2) {\ - _INFO("bluetooth fido asm bt error=[%s]", str);\ - return; \ - }\ - -static void -printBTError(bt_error_e e) -{ - printIfAndRet(e, BT_ERROR_NONE, "BT_ERROR_NONE"); - printIfAndRet(e, BT_ERROR_CANCELLED, "BT_ERROR_CANCELLED"); - printIfAndRet(e, BT_ERROR_INVALID_PARAMETER, "BT_ERROR_INVALID_PARAMETER"); - printIfAndRet(e, BT_ERROR_OUT_OF_MEMORY, "BT_ERROR_OUT_OF_MEMORY"); - printIfAndRet(e, BT_ERROR_RESOURCE_BUSY, "BT_ERROR_RESOURCE_BUSY"); - printIfAndRet(e, BT_ERROR_TIMED_OUT, "BT_ERROR_TIMED_OUT"); - printIfAndRet(e, BT_ERROR_NOW_IN_PROGRESS, "BT_ERROR_NOW_IN_PROGRESS"); - printIfAndRet(e, BT_ERROR_NOT_SUPPORTED, "BT_ERROR_NOT_SUPPORTED"); - printIfAndRet(e, BT_ERROR_PERMISSION_DENIED, "BT_ERROR_PERMISSION_DENIED"); - printIfAndRet(e, BT_ERROR_QUOTA_EXCEEDED, "BT_ERROR_QUOTA_EXCEEDED"); - printIfAndRet(e, BT_ERROR_NO_DATA, "BT_ERROR_NO_DATA"); - printIfAndRet(e, BT_ERROR_DEVICE_POLICY_RESTRICTION, "BT_ERROR_DEVICE_POLICY_RESTRICTION"); - printIfAndRet(e, BT_ERROR_NOT_INITIALIZED, "BT_ERROR_NOT_INITIALIZED"); - printIfAndRet(e, BT_ERROR_NOT_ENABLED, "BT_ERROR_NOT_ENABLED"); - printIfAndRet(e, BT_ERROR_ALREADY_DONE, "BT_ERROR_ALREADY_DONE"); - printIfAndRet(e, BT_ERROR_ALREADY_DONE, "BT_ERROR_ALREADY_DONE"); - printIfAndRet(e, BT_ERROR_OPERATION_FAILED, "BT_ERROR_OPERATION_FAILED"); - printIfAndRet(e, BT_ERROR_NOT_IN_PROGRESS, "BT_ERROR_NOT_IN_PROGRESS"); - printIfAndRet(e, BT_ERROR_REMOTE_DEVICE_NOT_BONDED, "BT_ERROR_REMOTE_DEVICE_NOT_BONDED"); - printIfAndRet(e, BT_ERROR_AUTH_REJECTED, "BT_ERROR_AUTH_REJECTED"); - printIfAndRet(e, BT_ERROR_AUTH_FAILED, "BT_ERROR_AUTH_FAILED"); - printIfAndRet(e, BT_ERROR_REMOTE_DEVICE_NOT_FOUND, "BT_ERROR_REMOTE_DEVICE_NOT_FOUND"); - printIfAndRet(e, BT_ERROR_SERVICE_SEARCH_FAILED, "BT_ERROR_SERVICE_SEARCH_FAILED"); - printIfAndRet(e, BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED, "BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED"); - printIfAndRet(e, BT_ERROR_AGAIN, "BT_ERROR_AGAIN"); - printIfAndRet(e, BT_ERROR_SERVICE_NOT_FOUND, "BT_ERROR_SERVICE_NOT_FOUND"); - printIfAndRet(e, e, "Unknown"); -} - -void -BleAdProvider::onGattConchanged(int result, bool connected, const char *remote_address, void *user_data) -{ - _INFO("bluetooth remote_address=[%s]", remote_address); - _INFO("bluetooth connected=[%d]", connected); - _INFO("bluetooth [%d]", result); - printBTError(static_cast(result)); - if (connected == false) { - _ERR("bluetooth GATT disconnected"); - return; - } - - bt_gatt_h svc = NULL; - bt_gatt_h chrReq = NULL; - bt_gatt_h chrResp = NULL; - bt_gatt_client_h client = NULL; - - _INFO("bluetooth "); - int ret = bt_gatt_client_create(remote_address, &client); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_client_create failed=[%d]", ret); - return; - } - - ret = bt_gatt_client_foreach_services(client, __svcCb, NULL); - printBTError(static_cast(ret)); - - char *cRAddr = NULL; - ret = bt_gatt_client_get_remote_address(client, &cRAddr); - printBTError(static_cast(ret)); - - _INFO("bluetooth bt_gatt_client_get_remote_address=[%s]", cRAddr); - ret = bt_gatt_client_get_service(client, RA_BLE_SERVICE_UUID, &svc); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_client_get_service failed=[%d]", ret); - printBTError(static_cast(ret)); - return; - } - - _INFO("bluetooth "); - ret = bt_gatt_service_get_characteristic(svc, RA_BLE_UUID_REQUEST, &chrReq); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_service_get_characteristic failed=[%d]", ret); - return; - } - - _INFO("bluetooth "); - ret = bt_gatt_service_get_characteristic(svc, RA_BLE_UUID_RESPONSE, &chrResp); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_service_get_characteristic failed=[%d]", ret); - return; - } - - _INFO("bluetooth "); - GattClient *gC = new GattClient(); - gC->__btClientInfo = _SAFE_DUP(remote_address); - gC->__btClient = client; - gC->__btClientSvc = svc; - gC->__btClientChrReq = chrReq; - gC->__btClientChrResp = chrResp; - - IAuthConnection *bleClient = new BleCon(); - bleClient->init(gC); - - IAuthStub *raStub = new RAuthStub(); - raStub->initRemote(bleClient); - - BleAdProvider *blePro = (BleAdProvider*)user_data; - if (blePro->__stubCache == NULL) { - blePro->__stubCache = new std::map(); - } - - /*Index auto incremented, set properly during setCache*/ - blePro->__stubCache->insert(std::make_pair(blePro->__stubCache->size(), raStub)); - - BleAdProvider::finishDiscovery(user_data); -} - -void -BleAdProvider::onLEScanResult(int result, bt_adapter_le_device_scan_result_info_s *info, - void *user_data) -{ - _INFO("bluetooth rclient __bt_adapter_le_scan_result_cb=[%d]", result); - _INFO("bluetooth remote_address=[%s]", info->remote_address); - _INFO("bluetooth address_type=[%d]", info->address_type); - /*_INFO("bluetooth adv_data=[%s]", info->adv_data); - _INFO("bluetooth scan_data=[%s]", info->scan_data);*/ - - if (info->adv_data_len > 31 || info->scan_data_len > 31) { - _INFO("bluetooth ###################"); - bt_adapter_le_stop_scan(); - _INFO("bluetooth ###################"); - return; - } - - bt_adapter_le_packet_type_e pkt_type = BT_ADAPTER_LE_PACKET_ADVERTISING; - int i = 0; - for (i = 0; i < 2; i++) { - char **uuids; - char *device_name; - int tx_power_level; - bt_adapter_le_service_data_s *data_list; - int appearance; - int manufacturer_id; - char *manufacturer_data; - int manufacturer_data_len; - int count; - - pkt_type = static_cast(static_cast(pkt_type) + i); - if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING && info->adv_data == NULL) - continue; - if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE && info->scan_data == NULL) - break; - - if (bt_adapter_le_get_scan_result_service_uuids(info, pkt_type, &uuids, &count) == BT_ERROR_NONE) { - int i; - for (i = 0; i < count; i++) { - _INFO("bluetooth UUID[%d] = %s", i + 1, uuids[i]); - g_free(uuids[i]); - } - g_free(uuids); - } - if (bt_adapter_le_get_scan_result_device_name(info, pkt_type, &device_name) == BT_ERROR_NONE) { - _INFO("bluetooth Device name = %s", device_name); - g_free(device_name); - } - if (bt_adapter_le_get_scan_result_tx_power_level(info, pkt_type, &tx_power_level) == BT_ERROR_NONE) - _INFO("bluetooth TX Power level = %d", tx_power_level); - if (bt_adapter_le_get_scan_result_service_solicitation_uuids(info, pkt_type, &uuids, &count) == BT_ERROR_NONE) { - int i; - for (i = 0; i < count; i++) { - _INFO("bluetooth Solicitation UUID[%d] = %s", i + 1, uuids[i]); - g_free(uuids[i]); - } - g_free(uuids); - } - if (bt_adapter_le_get_scan_result_service_data_list(info, pkt_type, &data_list, &count) == BT_ERROR_NONE) { - int i; - for (i = 0; i < count; i++) { - _INFO("bluetooth Service Data[%d] = [0x%2.2X%2.2X:0x%.2X...]", i + 1, - data_list[i].service_uuid[0], data_list[i].service_uuid[1], data_list[i].service_data[0]); - } - bt_adapter_le_free_service_data_list(data_list, count); - } - if (bt_adapter_le_get_scan_result_appearance(info, pkt_type, &appearance) == BT_ERROR_NONE) - _INFO("bluetooth Appearance = %d", appearance); - if (bt_adapter_le_get_scan_result_manufacturer_data(info, pkt_type, &manufacturer_id, - &manufacturer_data, &manufacturer_data_len) == BT_ERROR_NONE) { - _INFO("bluetooth Manufacturer data[ID:%.4X, 0x%.2X%.2X...(len:%d)]", - manufacturer_id, manufacturer_data[0], manufacturer_data[1], manufacturer_data_len); - g_free(manufacturer_data); - } - } - - /*RA_BLE_ADVERTISING_UUID*/ - - /*_INFO("bluetooth [%d] sec timeout starting", BT_DISC_TIMEOUT_SEC); - g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, BT_DISC_TIMEOUT_SEC, discoverTimeOutCb, user_data, - finishDiscovery);*/ - - _INFO("bluetooth Before bt_gatt_connect"); - - int ret = bt_gatt_connect(info->remote_address, false); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_connect failed=[%d]", ret); - return; - } - - _INFO("bluetooth bt_gatt_connect=[%d]", ret); -} - -void -BleAdProvider::finishDiscovery(gpointer data) -{ - _INFO("bluetooth "); - bt_adapter_le_stop_scan(); - - BleAdProvider *btPro = (BleAdProvider*)(data); - g_main_loop_quit(btPro->__waitLoop); -} - -gboolean -BleAdProvider::discoverTimeOutCb(gpointer user_data) -{ - _INFO("bluetooth discoverTimeOutCb"); - - return G_SOURCE_REMOVE; -} - -std::vector * -BleAdProvider::getAuthStubList(void) -{ - _INFO("bluetooth getAuthStubList"); - delete __stubCache; - __stubCache = NULL; - - __waitLoop = g_main_loop_new(NULL, FALSE); - - bt_gatt_set_connection_state_changed_cb(onGattConchanged, this); - - _INFO("bluetooth starting LE scan"); - int ret = bt_adapter_le_start_scan(onLEScanResult, this); - if (ret != BT_ERROR_NONE) { - bt_gatt_unset_connection_state_changed_cb(); - _ERR("bluetooth rclient bt_adapter_le_start_scan failed."); - bt_adapter_le_stop_scan(); - - return NULL; - } - - _INFO("bluetooth starting wait loop"); - g_main_loop_run(__waitLoop); - - _INFO("bluetooth After waitloop"); - - g_main_loop_unref(__waitLoop); - __waitLoop = NULL; - - if (__stubCache != NULL) { - _INFO("bluetooth BT Roaming Auth Count=[%d]", __stubCache->size()); - } else { - _ERR("bluetooth BT Roaming Auth List is NULL"); - return NULL; - } - - std::vector *stubList = NULL; - - std::map::iterator it = __stubCache->begin(); - for (; it != __stubCache->end(); ++it) { - if (stubList == NULL) - stubList = new std::vector(); - - stubList->push_back(it->second); - } - _INFO("bluetooth "); - return stubList; -} - -void -BleAdProvider::setCache(std::map *stubCache) -{ - _INFO("bluetooth BleAdProvider::setCache"); - if (stubCache != NULL) - _INFO("bluetooth New cache set size =[%d]", stubCache->size()); - - __stubCache = stubCache; -} - -IAuthStub* -BleAdProvider::getStubFromCache(int mappedIdx) -{ - if (__stubCache == NULL) { - _ERR("bluetooth Stub cache NULL"); - return NULL; - } - - return __stubCache->find(mappedIdx)->second; -} - -BleAdProvider::~BleAdProvider(void) -{ - -} - -BleAdProvider::BleAdProvider(void) -{ - __stubCache = NULL; - __waitLoop = NULL; - __isValidInst = false; -} diff --git a/server/auth_discovery/src/BleCon.cpp b/server/auth_discovery/src/BleCon.cpp deleted file mode 100644 index 0636df2..0000000 --- a/server/auth_discovery/src/BleCon.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "BleCon.h" -#include "AsmHelper.h" -#include "BTRoamingKeys.h" -#include "RoamingKeys.h" - -BleCon::BleCon(void) -{ - __gClient = NULL; - __waitLoop = NULL; - __resp = NULL; -} - -BleCon::~BleCon(void) -{ - -} - -int -BleCon::init(void *handle) -{ - __gClient = (GattClient*)handle; - - return 0; -} - -void -BleCon::onGattServerResponse(bt_gatt_h characteristic, char *value, - int len, void *user_data) -{ - _INFO("Response length = [%d]", len); - - BleCon *btCon = (BleCon*)user_data; - btCon->__resp = new StringMap(); - - std::string k(RA_QUERY_KEY_RESPONSE); - std::string v(value); - btCon->__resp->insert(std::make_pair(k, v)); - - g_main_loop_quit(btCon->__waitLoop); -} - -void -BleCon::onGattWriteComplete(int result, bt_gatt_h request_handle, void *user_data) -{ - _INFO("[%d]", result); - BleCon *btCon = (BleCon*)user_data; - if (result != 0) { - g_main_loop_quit(btCon->__waitLoop); - } -} - -StringMap* -BleCon::sendReqSync(StringMap *reqData) -{ - _INFO("sendReqSync start"); - - RET_IF_FAIL(reqData != NULL, NULL); - RET_IF_FAIL(__gClient != NULL, NULL); - - __resp = NULL; - std::string reqTlvB64 = (reqData->find(RA_QUERY_KEY_REQUEST)->second); - char *reqTlvB64Copy = strdup(reqTlvB64.c_str()); - - __waitLoop = g_main_loop_new(NULL, FALSE); - - int ret = bt_gatt_client_set_characteristic_value_changed_cb(__gClient->__btClientChrResp, - onGattServerResponse, this); - _ERR("rclient bt_gatt_client_set_characteristic_value_changed_cb failed=[%d]", ret); - - - ret = bt_gatt_set_value(__gClient->__btClientChrReq, reqTlvB64Copy, strlen(reqTlvB64Copy)); - if (ret != BT_ERROR_NONE) { - _ERR("rclient bt_gatt_set_value failed=[%d]", ret); - goto CATCH; - } - - ret = bt_gatt_client_write_value(__gClient->__btClientChrReq, onGattWriteComplete, this); - if (ret != BT_ERROR_NONE) { - _ERR("rclient bt_gatt_client_write_value failed=[%d]", ret); - goto CATCH; - } - - _INFO("bt_gatt_client_write_value=[%d]", ret); - g_main_loop_run(__waitLoop); - -CATCH: - SAFE_DELETE(reqTlvB64Copy); - g_main_loop_unref(__waitLoop); - bt_gatt_client_unset_characteristic_value_changed_cb(__gClient->__btClientChrResp); - _INFO("sendReqSync=%s", __resp); - return __resp; -} - -int -BleCon::shutdown(void) -{ - return -1; -} - -char* -BleCon::getInfo(void) -{ - RET_IF_FAIL(__gClient != NULL, NULL); - - return __gClient->__btClientInfo; -} diff --git a/server/auth_discovery/src/BtADProvider.cpp b/server/auth_discovery/src/BtADProvider.cpp index c9d370b..ed14653 100644 --- a/server/auth_discovery/src/BtADProvider.cpp +++ b/server/auth_discovery/src/BtADProvider.cpp @@ -5,7 +5,6 @@ #include "RAuthStub.h" #include "AsmHelper.h" #include "BTRoamingKeys.h" -//#include #include #define RA_BT_SERVICE_UUID "00001101-0000-1000-8000-00805F9B34FB" @@ -16,9 +15,9 @@ BtAdProvider::init(void) __isDiscovering = false; __sAddr = NULL; - int ret = bt_initialize(); - _INFO("bt_initialize=[%d]", ret); - if (ret != BT_ERROR_NONE) + __btInitResult = bt_initialize(); + _INFO("bt_initialize=[%d]", __btInitResult); + if (__btInitResult != BT_ERROR_NONE) return -1; __stubCache = NULL; @@ -222,7 +221,10 @@ BtAdProvider::getStubFromCache(int mappedIdx) BtAdProvider::~BtAdProvider(void) { - + if (__btInitResult == BT_ERROR_NONE) { + int ret = bt_deinitialize(); + _INFO("bt_deinitialize=[%d]", ret); + } } BtAdProvider::BtAdProvider(void) diff --git a/server/auth_discovery/src/BtCon.cpp b/server/auth_discovery/src/BtCon.cpp index 01ac26b..3987316 100644 --- a/server/auth_discovery/src/BtCon.cpp +++ b/server/auth_discovery/src/BtCon.cpp @@ -1,7 +1,6 @@ #include "BtCon.h" #include "BTRoamingKeys.h" -#include "RoamingKeys.h" #include "AsmHelper.h" #include #include diff --git a/server/auth_discovery/src/IoTCon.cpp b/server/auth_discovery/src/IoTCon.cpp deleted file mode 100644 index 38bf0f2..0000000 --- a/server/auth_discovery/src/IoTCon.cpp +++ /dev/null @@ -1,121 +0,0 @@ - -#include "IoTCon.h" -#include "AuthnrTypes.h" -#include "AsmHelper.h" -#include "RoamingKeys.h" - -IoTCon::IoTCon(void) -{ - __waitLoop = NULL; - __iotClient = NULL; - __resp = NULL; -} - -IoTCon::~IoTCon(void) -{ - -} - -int -IoTCon::init(void *handle) -{ - __iotClient = (iotcon_remote_resource_h)handle; - - return 0; -} - -void -IoTCon::onResponsePut(iotcon_remote_resource_h resource, iotcon_error_e err, - iotcon_request_type_e request_type, iotcon_response_h response, void *user_data) -{ - _INFO(""); - - IoTCon *conn = (IoTCon*)user_data; - _INFO("onResponsePut [%p]", conn); - - iotcon_representation_h repr = NULL; - iotcon_attributes_h state = NULL; - - iotcon_response_get_representation(response, &repr); - - iotcon_representation_get_attributes(repr, &state); - - char *asm_resp = NULL; - iotcon_attributes_get_str(state, RA_QUERY_KEY_RESPONSE, &asm_resp); - if (asm_resp != NULL) { - _INFO("%s=%s", RA_QUERY_KEY_RESPONSE, asm_resp); - - conn->__resp = new StringMap(); - std::string k(RA_QUERY_KEY_RESPONSE); - std::string v(asm_resp); - conn->__resp->insert(std::make_pair(k, v)); - } else { - _ERR("Failed to get %s", RA_QUERY_KEY_RESPONSE); - conn->__resp = NULL; - } - - _INFO("Before g_main_loop_quit"); - g_main_loop_quit(conn->__waitLoop); -} - -StringMap * -IoTCon::sendReqSync(StringMap *reqData) -{ - RET_IF_FAIL(reqData != NULL, NULL); - - std::string reqTlvB64 = (reqData->find(RA_QUERY_KEY_REQUEST)->second); - std::string svrId = (reqData->find(RA_QUERY_KEY_SERVER_ID)->second); - - iotcon_attributes_h attr = NULL; - iotcon_attributes_create(&attr); - - char *reqTlvB64Copy = strdup(reqTlvB64.c_str()); - char *svrIdCopy = strdup(svrId.c_str()); - iotcon_attributes_add_str(attr, RA_QUERY_KEY_REQUEST, reqTlvB64Copy); - iotcon_attributes_add_str(attr, RA_QUERY_KEY_SERVER_ID, svrIdCopy); - - iotcon_representation_h repr = NULL; - iotcon_representation_create(&repr); - - iotcon_representation_set_attributes(repr, attr); - - - __waitLoop = g_main_loop_new(NULL, FALSE); - int ret = iotcon_remote_resource_put(__iotClient, repr, NULL, onResponsePut, this); - if (ret != IOTCON_ERROR_NONE) { - _ERR("iotcon_remote_resource_get failed"); - iotcon_representation_destroy(repr); - SAFE_DELETE(reqTlvB64Copy); - SAFE_DELETE(svrIdCopy); - return NULL; - } - - iotcon_representation_destroy(repr); - SAFE_DELETE(reqTlvB64Copy); - SAFE_DELETE(svrIdCopy); - _INFO("iotcon_remote_resource_get=[%d]", ret); - g_main_loop_run(__waitLoop); - - _INFO("sendReqSync end"); - - return __resp; -} - -char* -IoTCon::getInfo(void) -{ - char *devId = NULL; - int ret = iotcon_remote_resource_get_device_id(__iotClient, &devId); - if (ret == IOTCON_ERROR_NONE && devId != NULL) { - _INFO("Device Id = [%s]", devId); - return devId; - } - - return NULL; -} - -int -IoTCon::shutdown(void) -{ - return 0; -} diff --git a/server/auth_discovery/src/IotADProvider.cpp b/server/auth_discovery/src/IotADProvider.cpp deleted file mode 100644 index 570a6fe..0000000 --- a/server/auth_discovery/src/IotADProvider.cpp +++ /dev/null @@ -1,217 +0,0 @@ - -#include "IotADProvider.h" - -#include -#include "IoTCon.h" -#include "AsmHelper.h" -#include "RAuthStub.h" -#include "RoamingKeys.h" -#include "AuthIndexHanlder.h" -#include "RoamingUtil.h" - -#define EMPTY_STUB_LIST std::vector() - -#define AUTH_INDEX_START 5 - -void -IotADProvider::finishDiscovery(gpointer data) -{ - _INFO(""); - IotADProvider *rAuthManager = (IotADProvider*)(data); - g_main_loop_quit(rAuthManager->__waitLoop); -} - -gboolean -IotADProvider::discoverTimeOutCb(gpointer user_data) -{ - _INFO("discoverTimeOutCb"); - - return G_SOURCE_REMOVE; -} - -bool -IotADProvider::resourceFoundCb(iotcon_remote_resource_h resource, iotcon_error_e result, - void *user_data) -{ - _INFO(""); - - if (result != IOTCON_ERROR_NONE) { - _ERR("No remote resource found"); - return false; - //return; - } - - char *rDevId = NULL; - iotcon_remote_resource_get_device_id(resource, &rDevId); - if (rDevId == NULL) { - _ERR("iotcon_remote_resource_get_device_id failed"); - return false; - //return; - } - - char *rHostAddr = NULL; - iotcon_remote_resource_get_host_address(resource, &rHostAddr); - if (rHostAddr == NULL) { - _ERR("iotcon_remote_resource_get_host_address failed"); - return false; - //return; - } - - std::string p2pMacAddr = RoamingUtil::getP2PMACAddr(); - std::string btMacAddr = RoamingUtil::getBTMACAddr(); - - _INFO("[%s][%s]", p2pMacAddr.c_str(), btMacAddr.c_str()); - _INFO("[%s]", rDevId); - _INFO("[%s]", rHostAddr); - - if (p2pMacAddr.empty() == false) { - - if (strcmp(rDevId, p2pMacAddr.c_str()) == 0) { - _INFO("Ignoring request from same device"); - return false; - //return; - } - - } else if (btMacAddr.empty() == false) { - if (strcmp(rDevId, btMacAddr.c_str()) == 0) { - _INFO("Ignoring request from same device"); - return false; - //return; - } - } - - IotADProvider *radPro = (IotADProvider*)user_data; - _INFO("this=[%p]", radPro); - - iotcon_remote_resource_h resourceClone = NULL; - - _INFO("Before iotcon_remote_resource_clone"); - int ret = iotcon_remote_resource_clone(resource, &resourceClone); - _INFO("After iotcon_remote_resource_clone"); - if (ret != IOTCON_ERROR_NONE) { - _ERR("Failed to clone remote resource"); - return false; - //return; - } - - IAuthStub *stub = new RAuthStub(); - IAuthConnection *conH = new IoTCon(); - conH->init(resourceClone); - stub->initRemote(conH); - - if (radPro->__stubCache == NULL) { - radPro->__stubCache = new std::map(); - } - - /*Index auto incremented, set properly during setCache*/ - radPro->__stubCache->insert(std::make_pair(radPro->__stubCache->size(), stub)); - - return true; -} - -std::vector* -IotADProvider::getAuthStubList(void) -{ - delete __stubCache; - __stubCache = NULL; - - __waitLoop = g_main_loop_new(NULL, FALSE); - - g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, 1, discoverTimeOutCb, this, - finishDiscovery); - - - iotcon_query_h iotQ = NULL; - iotcon_query_create(&iotQ); - - int ret = iotcon_query_set_resource_type(iotQ, RA_RESOURCE_TYPE); - - ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL, - iotQ, resourceFoundCb, this); - if (IOTCON_ERROR_NONE != ret) { - _ERR("iotcon_find_resource failed"); - iotcon_query_destroy(iotQ); - return NULL; - } - - iotcon_query_destroy(iotQ); - g_main_loop_run(__waitLoop); - - _INFO("After g_main_loop_run"); - - g_main_loop_unref(__waitLoop); - __waitLoop = NULL; - - if (__stubCache != NULL) { - _INFO("Roaming Auth Count=[%d]", __stubCache->size()); - } else { - _ERR("Roaming Auth List is NULL"); - return NULL; - } - - std::vector *stubList = NULL; - - std::map::iterator it = __stubCache->begin(); - for (; it != __stubCache->end(); ++it) { - if (stubList == NULL) - stubList = new std::vector(); - - stubList->push_back(it->second); - } - _INFO(""); - return stubList; -} - -void -IotADProvider::setCache(std::map *stubCache) -{ - _INFO("IotADProvider::setCache"); - if (stubCache != NULL) - _INFO("New cache set size =[%d]", stubCache->size()); - - __stubCache = stubCache; -} - -IAuthStub* -IotADProvider::getStubFromCache(int mappedIdx) -{ - if (__stubCache == NULL) { - _ERR("Stub cache NULL"); - return NULL; - } - - return __stubCache->find(mappedIdx)->second; -} - -IotADProvider::~IotADProvider(void) -{ - if (__isValidInst == true) - iotcon_deinitialize(); -} - -int -IotADProvider::init(void) -{ - int ret = iotcon_initialize(RA_ACL_CLIENT); - if (IOTCON_ERROR_NONE != ret) { - __isValidInst = false; - return -1; - } - - __isValidInst = true; - return 0; -} - -auth_type_e -IotADProvider::getType(void) -{ - return AUTH_TYPE_ROAMING; -} - -IotADProvider::IotADProvider(void) - : __isValidInst(false) -{ - __stubCache = NULL; - __waitLoop = NULL; - __isValidInst = false; -} diff --git a/server/auth_discovery/src/RAuthStub.cpp b/server/auth_discovery/src/RAuthStub.cpp index 922815f..a2319b4 100644 --- a/server/auth_discovery/src/RAuthStub.cpp +++ b/server/auth_discovery/src/RAuthStub.cpp @@ -1,7 +1,6 @@ #include "RAuthStub.h" #include "AsmHelper.h" -#include "RoamingKeys.h" #include "RoamingUtil.h" #include "TlvData.h" #include "AuthIndexHanlder.h" diff --git a/server/auth_discovery/src/RoamingUtil.cpp b/server/auth_discovery/src/RoamingUtil.cpp index cbb3193..9fd6b76 100644 --- a/server/auth_discovery/src/RoamingUtil.cpp +++ b/server/auth_discovery/src/RoamingUtil.cpp @@ -340,48 +340,6 @@ RoamingUtil::isRASupported(void) return raSupported;*/ } -std::string -RoamingUtil::getBTMACAddr(void) -{ - static std::string g_mac_address; - if(g_mac_address.empty() == true) { - bt_initialize(); - char* mac_address = NULL; - bt_adapter_enable(); - int ret = bt_adapter_get_address(&mac_address); - if (ret != 0) { - _ERR("bt_adapter_get_address failed"); - return g_mac_address; - } - - _INFO("bluetooth get mac address : %s", mac_address); - g_mac_address = mac_address; - free(mac_address); - bt_deinitialize(); - } - _INFO("mac address:%s", g_mac_address.c_str()); - - return g_mac_address; -} - - -std::string -RoamingUtil::getDevName(void) -{ - static std::string g_device_name; - if(g_device_name.empty()) { - char* device_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR); - if (device_name == NULL) { - g_device_name = "Tizen"; - } else { - g_device_name = device_name; - } - _INFO("device_name: %s", g_device_name.c_str()); - } - - return g_device_name; -} - char RoamingUtil::makeP2PMAC(char c) { @@ -400,30 +358,6 @@ RoamingUtil::makeP2PMAC(char c) return convert_c; } -std::string -RoamingUtil::getP2PMACAddr(void) -{ - static std::string g_p2p_mac_address; - if(g_p2p_mac_address.empty()) { - char p2p_mac[MAC_ADDR_STR_LEN]; - memset(p2p_mac, 0x0, MAC_ADDR_STR_LEN); - - char* temp_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS); - if (temp_addr == NULL) { - _ERR("vconf_get_str Failed for %s", VCONFKEY_WIFI_BSSID_ADDRESS); - } else { - memcpy(p2p_mac, temp_addr, MAC_ADDR_STR_LEN-1); - p2p_mac[1] = makeP2PMAC(p2p_mac[1]); - _INFO("P2P mac is %s", p2p_mac); - free(temp_addr); - - g_p2p_mac_address = p2p_mac; - } - } - _INFO("p2p mac address:%s", g_p2p_mac_address.c_str()); - return g_p2p_mac_address; -} - char* RoamingUtil::getServerId(void) { -- 2.7.4