From 7a47f921ef2e02cb89c633370eb1ce9dbe6e71bd Mon Sep 17 00:00:00 2001 From: Abhay Agarwal Date: Fri, 5 Feb 2021 14:44:52 +0530 Subject: [PATCH 01/16] ua-api: Add support for product API's This patch adds support in ua-api to handle product API's. Change-Id: Ied7769ad1f550a81e643a7ab894625860924c5ba Signed-off-by: Abhay Agarwal --- include/product/ua-api-product.h | 136 ++++++++ include/product/ua-internal-product.h | 51 +++ packaging/ua-manager.spec | 1 + ua-api/CMakeLists.txt | 8 + ua-api/product/include/ua-common-product.h | 39 +++ ua-api/product/include/ua-event-handler-product.h | 35 +++ ua-api/product/include/ua-request-sender-product.h | 44 +++ ua-api/product/ua-api-product.c | 80 +++++ ua-api/product/ua-common-product.c | 84 +++++ ua-api/product/ua-event-handler-product.c | 143 +++++++++ ua-api/product/ua-request-sender-product.c | 347 +++++++++++++++++++++ 11 files changed, 968 insertions(+) create mode 100644 include/product/ua-api-product.h create mode 100644 include/product/ua-internal-product.h create mode 100644 ua-api/product/include/ua-common-product.h create mode 100644 ua-api/product/include/ua-event-handler-product.h create mode 100644 ua-api/product/include/ua-request-sender-product.h create mode 100644 ua-api/product/ua-api-product.c create mode 100644 ua-api/product/ua-common-product.c create mode 100644 ua-api/product/ua-event-handler-product.c create mode 100644 ua-api/product/ua-request-sender-product.c diff --git a/include/product/ua-api-product.h b/include/product/ua-api-product.h new file mode 100644 index 0000000..8163007 --- /dev/null +++ b/include/product/ua-api-product.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 __TIZEN_UA_NETWORK_UA_API_PRODUCT_H__ +#define __TIZEN_UA_NETWORK_UA_API_PRODUCT_H__ + +#include +#include + +#ifndef TIZEN_ERROR_UA +#define TIZEN_ERROR_UA 0x11170000 /**< To-Do: This should move to tizen_error.h */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Macro for event enum. + * @since_tizen 6.5 + */ +#define GENERATE_PRODUCT_EVENT_ENUM(ENUM) ENUM, + +/** + * @brief Macro to print event string out. + * @since_tizen 6.5 + */ +#define GENERATE_PRODUCT_EVENT_STRING(STRING) #STRING, + +/** + * @brief Enumerations macro of UA framework product event codes. + * @since_tizen 6.5 + */ +typedef enum { + UAM_PRODUCT_EVENT_TEST, /** Test */ + UAM_PRODUCT_EVENT_MAX, /**< Max. event number */ +} uam_product_event_e; + +/** + * @brief Event data structure. + * @since_tizen 6.5 + */ +typedef struct { + int result; /**< Result code */ + void *data; /**< Data pointer */ +} uam_product_event_data_s; + +/** + * @brief Callback to be invoked when receiving product events. + * @since_tizen 6.5 + * + * @remarks The @a event_param should not be released. + * @remarks The @a event_param can be used only in the callback. + * + * @param[in] event Event type. + * @param[in] event_param The event data structure. + * @param[in] user_data The user data passed in _uam_product_init() + * + * @exception + * @pre + * @post + * + * @see _uam_product_init() + */ +typedef void (*uam_product_event_cb)(int event, uam_product_event_data_s *event_param, void *user_data); + +/** + * @brief Initializes client library. + * @since_tizen 6.5 + * + * @param[in] cb Callback handler + * @param[in] user_data The user data. + * + * @return 0 on success, otherwise a negative error value + * @retval #UAM_ERROR_NONE Successful + * @retval #UAM_ERROR_INVALID_PARAMETER Invalid parameters + * @rerval #UAM_ERROR_ALREADY_REGISTERED Already registered + * @retval #UAM_ERROR_INTERNAL Internal error + * + * @exception + * @pre + * @post + */ +int _uam_product_init(uam_product_event_cb cb, void *user_data); + +/** + * @brief De-initializes client library. + * @since_tizen 6.5 + * + * @return 0 on success, otherwise a negative error value + * @retval #UAM_ERROR_NONE Successful + * @rerval #UAM_ERROR_NOT_REGISTERED Not registered + * @retval #UAM_ERROR_INTERNAL Internal error + * + * @exception + * @pre + * @post + */ +int _uam_product_deinit(void); + +/** + * @brief Test. + * @since_tizen 6.5 + * + * @return 0 on success, otherwise a negative error value + * @retval #UAM_ERROR_NONE Successful + * @retval #UAM_ERROR_INVALID_PARAMETER Invalid parameters + * @retval #UAM_ERROR_INTERNAL Internal error + * + * @exception + * @pre + * @post + */ +int _uam_product_test(); + + +#ifdef __cplusplus +} +#endif +#endif /* __TIZEN_UA_NETWORK_UA_API_PRODUCT_H__ */ diff --git a/include/product/ua-internal-product.h b/include/product/ua-internal-product.h new file mode 100644 index 0000000..c0ddb2b --- /dev/null +++ b/include/product/ua-internal-product.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 __UAM_INTERNAL_PRODUCT_H__ +#define __UAM_INTERNAL_PRODUCT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define UAM_PRODUCT_DBUS_NAME "net.uamd_product" +#define UAM_PRODUCT_DAEMON_PATH "/net/uamd_product" + +#define UAM_PRODUCT_EVENT_INTERFACE "net.ua.event_product" +#define UAM_PRODUCT_EVENT_PATH "/net/ua/event_product" + +#define FOREACH_PRODUCT_REQUEST(REQUEST) \ + REQUEST(UAM_PRODUCT_REQUEST_TEST) \ + REQUEST(UAM_PRODUCT_REQUEST_MAX) + +#define GENERATE_PRODUCT_REQUEST_ENUM(ENUM) ENUM, +#define GENERATE_PRODUCT_REQUEST_STRING(STRING) #STRING, + +typedef enum { + FOREACH_PRODUCT_REQUEST(GENERATE_PRODUCT_REQUEST_ENUM) +} uam_product_request_e; + +#define UAM_PRODUCT_SIGNAL_TEST "Test" + +#define CASE_TO_STR(x) case x: return #x; + +#ifdef __cplusplus +} +#endif +#endif /* __UAM_INTERNAL_PRODUCT_H__ */ diff --git a/packaging/ua-manager.spec b/packaging/ua-manager.spec index 492f992..76196a7 100644 --- a/packaging/ua-manager.spec +++ b/packaging/ua-manager.spec @@ -115,6 +115,7 @@ cp ua-manager.service %{buildroot}%{_unitdir}/ua-manager.service %files devel %defattr(-, root, root) %{_includedir}/ua-manager/ua-api.h +%{_includedir}/ua-manager/ua-api-product.h %{_libdir}/pkgconfig/ua-api.pc %%attr(644,-,-) %{_libdir}/libua-api.so diff --git a/ua-api/CMakeLists.txt b/ua-api/CMakeLists.txt index d365c5d..17945fb 100644 --- a/ua-api/CMakeLists.txt +++ b/ua-api/CMakeLists.txt @@ -10,6 +10,9 @@ SET(LIB_PKGCONFIG_DIR "${LIB_PATH}/pkgconfig") INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/product) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/product) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/product/include) INCLUDE(FindPkgConfig) pkg_check_modules(PKGS REQUIRED @@ -41,10 +44,15 @@ SET(SRCS src/ua-common.c src/ua-event-handler.c src/ua-request-sender.c + product/ua-api-product.c + product/ua-common-product.c + product/ua-event-handler-product.c + product/ua-request-sender-product.c ) SET(HEADERS ua-api.h + product/ua-api-product.h ) ADD_LIBRARY(${LIB_NAME} SHARED ${SRCS}) diff --git a/ua-api/product/include/ua-common-product.h b/ua-api/product/include/ua-common-product.h new file mode 100644 index 0000000..8e195c9 --- /dev/null +++ b/ua-api/product/include/ua-common-product.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 __UAM_COMMON_PRODUCT_H__ +#define __UAM_COMMON_PRODUCT_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +GDBusConnection *_uam_product_get_gdbuam_conn(void); + +const char *_uam_product_request_to_str(unsigned int req); +const char *_uam_product_event_to_str(unsigned int event); + +#ifdef __cplusplus +} +#endif +#endif /* __UAM_COMMON_PRODUCT_H__ */ diff --git a/ua-api/product/include/ua-event-handler-product.h b/ua-api/product/include/ua-event-handler-product.h new file mode 100644 index 0000000..f9acb80 --- /dev/null +++ b/ua-api/product/include/ua-event-handler-product.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 __UAM_EVENT_HANDLER_PRODUCT_H__ +#define __UAM_EVENT_HANDLER_PRODUCT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +int _uam_product_register_event_handler( + uam_product_event_cb event_cb, void *user_data); + +int _uam_product_unregister_event_handler(void); + +#ifdef __cplusplus +} +#endif +#endif /* __UAM_EVENT_HANDLER_PRODUCT_H__ */ diff --git a/ua-api/product/include/ua-request-sender-product.h b/ua-api/product/include/ua-request-sender-product.h new file mode 100644 index 0000000..f515ca2 --- /dev/null +++ b/ua-api/product/include/ua-request-sender-product.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 __UAM_REQUEST_SENDER_PRODUCT_H__ +#define __UAM_REQUEST_SENDER_PRODUCT_H__ + +#include "ua-api-product.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _uam_product_gdbuam_deinit_proxy(void); + +int _uam_product_sync_request( + int req_func, GArray *in_param1, + GArray *in_param2, GArray *in_param3, + GArray *in_param4, GArray **out_param); + +int _uam_product_async_request(int req_func, + GArray *in_param1, GArray *in_param2, + GArray *in_param3, GArray *in_param4, + uam_product_event_cb callback, void *user_data); + +#ifdef __cplusplus +} +#endif +#endif /* __UAM_REQUEST_SENDER_PRODUCT_H__ */ diff --git a/ua-api/product/ua-api-product.c b/ua-api/product/ua-api-product.c new file mode 100644 index 0000000..ddfe54a --- /dev/null +++ b/ua-api/product/ua-api-product.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 +#include +#include +#include +#include + +typedef struct { + void *callback; + void *user_data; +} uam_product_callback_info_t; + +static uam_product_callback_info_t cb_info; + +UAM_EXPORT_API int _uam_product_init(uam_product_event_cb cb, void *user_data) +{ + FUNC_ENTRY; + int ret; + + ret = _uam_product_register_event_handler(cb, user_data); + if (UAM_ERROR_NONE == ret || UAM_ERROR_ALREADY_REGISTERED == ret) { + cb_info.callback = cb; + cb_info.user_data = user_data; + return UAM_ERROR_NONE; + } + + FUNC_EXIT; + return ret; +} + +UAM_EXPORT_API int _uam_product_deinit(void) +{ + FUNC_ENTRY; + int ret; + + ret = _uam_product_unregister_event_handler(); + + if (UAM_ERROR_NONE != ret && UAM_ERROR_NOT_REGISTERED != ret) + return ret; + + FUNC_EXIT; + return ret; +} + +UAM_EXPORT_API int _uam_product_test() +{ + FUNC_ENTRY; + int ret; + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + ret = _uam_product_sync_request(UAM_PRODUCT_REQUEST_TEST, + in_param1, in_param2, in_param3, in_param4, &out_param); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} diff --git a/ua-api/product/ua-common-product.c b/ua-api/product/ua-common-product.c new file mode 100644 index 0000000..274d80e --- /dev/null +++ b/ua-api/product/ua-common-product.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 "ua-api.h" +#include "ua-common.h" +#include "ua-internal-product.h" +#include "ua-api-product.h" + +static const char *request_string[] = { + FOREACH_PRODUCT_REQUEST(GENERATE_PRODUCT_REQUEST_STRING) +}; + +static GDBusConnection *gdbuam_conn = NULL; + +static GDBusConnection *__uam_product_get_shared_gdbuam_conn(void) +{ + FUNC_ENTRY; + GError *error = NULL; + GDBusConnection *shared_conn = NULL; + + shared_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!shared_conn) { + UAM_ERR("Unable to connect to dbus"); + if (error) { + UAM_ERR("Error: %s", error->message); + g_clear_error(&error); + } + return NULL; + } + + FUNC_EXIT; + return shared_conn; +} + +GDBusConnection *_uam_product_get_gdbuam_conn(void) +{ + FUNC_ENTRY; + + if (gdbuam_conn) { + if (g_dbus_connection_is_closed(gdbuam_conn)) + gdbuam_conn = __uam_product_get_shared_gdbuam_conn(); + + FUNC_EXIT; + return gdbuam_conn; + } + + gdbuam_conn = __uam_product_get_shared_gdbuam_conn(); + FUNC_EXIT; + return gdbuam_conn; +} + +const char *_uam_product_request_to_str(unsigned int req) +{ + retv_if(UAM_PRODUCT_REQUEST_MAX <= req, NULL); + + return request_string[req]; +} + +const char *_uam_product_event_to_str(unsigned int event) +{ + retv_if(UAM_PRODUCT_EVENT_MAX <= event, NULL); + + switch (event) { + CASE_TO_STR(UAM_PRODUCT_EVENT_TEST) + default: + return "UNKNOWN ERROR"; + } +} diff --git a/ua-api/product/ua-event-handler-product.c b/ua-api/product/ua-event-handler-product.c new file mode 100644 index 0000000..9b473e0 --- /dev/null +++ b/ua-api/product/ua-event-handler-product.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 "ua-common.h" +#include "ua-api.h" +#include "ua-internal-product.h" +#include "ua-common-product.h" +#include "ua-api-product.h" + +typedef struct { + guint id; + void *cb; + void *user_data; +} uam_product_event_handler_data_t; + +static gboolean is_registered = FALSE; +static uam_product_event_handler_data_t *event_handler_data = NULL; + +static void __uam_product_send_event(int event, int result, + void *data, void *callback, void *user_data) +{ + FUNC_ENTRY; + uam_product_event_data_s event_data; + + UAM_INFO("Event: %s [0x%4.4X], result= %s [0x%4.4X]", + _uam_product_event_to_str(event), event, + _uam_error_to_str(result), result); + + ret_if(NULL == callback); + + memset(&event_data, 0x00, sizeof(uam_product_event_data_s)); + event_data.result = result; + event_data.data = data; + + ((uam_product_event_cb)callback)(event, &event_data, user_data); + + FUNC_EXIT; +} + +static void __uam_product_event_handler(GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + FUNC_ENTRY; + int result = UAM_ERROR_NONE; + int event = -1; + + uam_product_event_handler_data_t *event_info = user_data; + + ret_if(NULL == event_info); + + if (0 != strcasecmp(object_path, UAM_PRODUCT_EVENT_PATH)) + return; + + if (0 != strcasecmp(interface_name, UAM_PRODUCT_EVENT_INTERFACE)) + return; + + if (0 == strcasecmp(signal_name, UAM_PRODUCT_SIGNAL_TEST)) { + UAM_DBG("signal received: %s", signal_name); + + event = UAM_PRODUCT_EVENT_TEST; + + __uam_product_send_event(event, result, NULL, + event_info->cb, event_info->user_data); + } else { + UAM_WARN("Unknown signal received: %s", signal_name); + } + + FUNC_EXIT; +} + +int _uam_product_register_event_handler(uam_product_event_cb event_cb, void *user_data) +{ + FUNC_ENTRY; + GDBusConnection *conn; + const char *path = UAM_PRODUCT_EVENT_PATH; + const char *interface = UAM_PRODUCT_EVENT_INTERFACE; + GDBusSignalCallback event_func = __uam_product_event_handler; + + retv_if(TRUE == is_registered, UAM_ERROR_ALREADY_REGISTERED); + + conn = _uam_product_get_gdbuam_conn(); + retv_if(NULL == conn, UAM_ERROR_INTERNAL); + + event_handler_data = g_malloc0(sizeof(uam_product_event_handler_data_t)); + if (event_handler_data) { + event_handler_data->cb = event_cb; + event_handler_data->user_data = user_data; + event_handler_data->id = g_dbus_connection_signal_subscribe(conn, + NULL, interface, NULL, path, NULL, 0, + event_func, event_handler_data, NULL); + } else { + UAM_ERR("Memory allocation error"); + return UAM_ERROR_OUT_OF_MEMORY; + } + + is_registered = TRUE; + + FUNC_EXIT; + return UAM_ERROR_NONE; +} + +int _uam_product_unregister_event_handler(void) +{ + FUNC_ENTRY; + GDBusConnection *conn; + + retv_if(FALSE == is_registered, UAM_ERROR_NOT_REGISTERED); + is_registered = FALSE; + + retv_if(NULL == event_handler_data, UAM_ERROR_INTERNAL); + + conn = _uam_product_get_gdbuam_conn(); + retv_if(NULL == conn, UAM_ERROR_INTERNAL); + + g_dbus_connection_signal_unsubscribe(conn, event_handler_data->id); + memset(event_handler_data, 0, sizeof(uam_product_event_handler_data_t)); + g_free(event_handler_data); + event_handler_data = NULL; + + FUNC_EXIT; + return UAM_ERROR_NONE; +} diff --git a/ua-api/product/ua-request-sender-product.c b/ua-api/product/ua-request-sender-product.c new file mode 100644 index 0000000..4a9c3d5 --- /dev/null +++ b/ua-api/product/ua-request-sender-product.c @@ -0,0 +1,347 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 "ua-api.h" +#include "ua-common.h" +#include "ua-internal-product.h" +#include "ua-common-product.h" +#include "ua-request-sender-product.h" +#include "ua-event-handler-product.h" +#include "ua-api-product.h" + +typedef struct { + int req_func; + void *cb; + void *user_data; +} uam_product_req_info_t; + +static GSList *pending_requests; +static GDBusProxy *uam_product_proxy; + +static GDBusProxy *__uam_product_gdbuam_init_proxy(void) +{ + FUNC_ENTRY; + GDBusConnection *conn; + GDBusProxy *proxy; + GError *err = NULL; + + conn = _uam_product_get_gdbuam_conn(); + retv_if(NULL == conn, NULL); + + proxy = g_dbus_proxy_new_sync(conn, + G_DBUS_PROXY_FLAGS_NONE, NULL, + UAM_PRODUCT_DBUS_NAME, + UAM_PRODUCT_DAEMON_PATH, + UAM_PRODUCT_DBUS_NAME, + NULL, &err); + if (!proxy) { + UAM_ERR("Unable to create proxy"); + if (err) { + UAM_ERR("Error: %s", err->message); + g_clear_error(&err); + } + + return NULL; + } + + uam_product_proxy = proxy; + FUNC_EXIT; + return proxy; +} + +static GDBusProxy *__uam_product_gdbuam_get_proxy(void) +{ + return (uam_product_proxy) ? uam_product_proxy : __uam_product_gdbuam_init_proxy(); +} + +void _uam_product_gdbuam_deinit_proxy(void) +{ + FUNC_ENTRY; + + if (uam_product_proxy) { + g_object_unref(uam_product_proxy); + uam_product_proxy = NULL; + } + + FUNC_EXIT; +} + +static void __uam_product_get_event_info(int req_func, GArray *output, + int *event, void **param_data) +{ + ret_if(event == NULL); + + UAM_DBG("Request function : %s (0x%x)", + _uam_product_request_to_str(req_func), req_func); + + switch (req_func) { + default: + UAM_ERR("Unknown request function"); + return; + } +} + +static void __uam_product_fill_garray_from_variant(GVariant *var, GArray *param) +{ + FUNC_ENTRY; + + char *data; + int size; + + size = g_variant_get_size(var); + if (size > 0) { + data = (char *)g_variant_get_data(var); + if (data) + g_array_append_vals(param, data, size); + } + + FUNC_EXIT; +} + +int _uam_product_sync_request( + int req_func, + GArray *in_param1, + GArray *in_param2, + GArray *in_param3, + GArray *in_param4, + GArray **out_param + ) +{ + FUNC_ENTRY; + int result = UAM_ERROR_NONE; + gint timeout; + GDBusProxy *proxy = NULL; + GVariant *ret = NULL; + GVariant *param1 = NULL; + GVariant *param2 = NULL; + GVariant *param3 = NULL; + GVariant *param4 = NULL; + + GVariant *input_param = NULL; + GVariant *result_param = NULL; + GError *error = NULL; + + UAM_INFO_C("Request function : %s (0x%x)", + _uam_product_request_to_str(req_func), req_func); + + proxy = __uam_product_gdbuam_get_proxy(); + retv_if(NULL == proxy, UAM_ERROR_INTERNAL); + + param1 = g_variant_new_from_data((const GVariantType *)"ay", + in_param1->data, in_param1->len, + TRUE, NULL, NULL); + param2 = g_variant_new_from_data((const GVariantType *)"ay", + in_param2->data, in_param2->len, + TRUE, NULL, NULL); + param3 = g_variant_new_from_data((const GVariantType *)"ay", + in_param3->data, in_param3->len, + TRUE, NULL, NULL); + param4 = g_variant_new_from_data((const GVariantType *)"ay", + in_param4->data, in_param4->len, + TRUE, NULL, NULL); + + timeout = 10000; + + input_param = g_variant_new("(i@ay@ay@ay@ay)", req_func, param1, + param2, param3, param4); + + ret = g_dbus_proxy_call_sync(proxy, "uam_product_request", + input_param, G_DBUS_CALL_FLAGS_NONE, timeout, + NULL, &error); + /* + * Note: params1~4 and in_params are unreferenced within the g_dbus_proxy_call_sync function. + * + * ------------------------------------------------------------------------------ + * Call flow: + * g_dbus_proxy_call_sync_internal -> g_dbus_connection_call_sync -> + * g_dbus_connection_call_sync_internal -> g_dbus_message_set_body -> + * g_variant_unref(message->body); + * ------------------------------------------------------------------------------ + */ + if (!ret) { + UAM_ERR("dBUS-RPC failed"); + if (error != NULL) { + UAM_ERR("D-Bus API failure: errCode[%x], message[%s]", + error->code, error->message); + g_clear_error(&error); + } + + return UAM_ERROR_INTERNAL; + } + + g_variant_get(ret, "(iv)", &result, &result_param); + + if (result_param) { + *out_param = g_array_new(TRUE, TRUE, sizeof(gchar)); + __uam_product_fill_garray_from_variant(result_param, *out_param); + g_variant_unref(result_param); + } + + g_variant_unref(ret); + + FUNC_EXIT; + return result; +} + +static void __uam_product_async_request_cb( + GObject *object, + GAsyncResult *res, + gpointer user_data + ) +{ + FUNC_ENTRY; + int event = -1; + int result = UAM_ERROR_NONE; + uam_product_event_data_s event_data; + uam_product_req_info_t *req_info = user_data; + + GError *error = NULL; + GVariant *value; + GVariant *param1; + GArray *out_param = NULL; + + memset(&event_data, 0x00, sizeof(uam_product_event_data_s)); + + value = g_dbus_proxy_call_finish(G_DBUS_PROXY(object), res, &error); + if (!value) { + UAM_ERR("D-Bus API failed"); + if (error) { + /* dBUS gives error cause */ + UAM_ERR("Error: [%s]", error->message); + g_clear_error(&error); + } + + ret_if(req_info == NULL); + + result = UAM_ERROR_TIMED_OUT; + } else { + g_variant_get(value, "(iv)", &result, ¶m1); + g_variant_unref(value); + + if (param1) { + out_param = g_array_new(TRUE, TRUE, sizeof(gchar)); + __uam_product_fill_garray_from_variant(param1, out_param); + g_variant_unref(param1); + } + + /* Callback should be invoked only in case of failure */ + if (UAM_ERROR_NONE == result) + goto done; + + if (!req_info || !req_info->cb) + goto done; + } + + UAM_INFO("result= %s [0x%4.4X]", _uam_error_to_str(result), result); + event_data.result = result; + + if (req_info && req_info->req_func) { + __uam_product_get_event_info(req_info->req_func, out_param, + &event, &event_data.data); + + ((uam_product_event_cb)req_info->cb)( + event, &event_data, req_info->user_data); + } + +done: + if (out_param) + g_array_unref(out_param); + + if (req_info) { + pending_requests = g_slist_remove( + pending_requests, (void *)req_info); + g_free(req_info); + req_info = NULL; + } + FUNC_EXIT; +} + +int _uam_product_async_request( + int req_func, + GArray *in_param1, + GArray *in_param2, + GArray *in_param3, + GArray *in_param4, + uam_product_event_cb callback, + void *user_data + ) +{ + FUNC_ENTRY; + int result = UAM_ERROR_NONE; + uam_product_req_info_t *req_info; + gint timeout = -1; + GDBusProxy *proxy; + GVariant *param1 = NULL; + GVariant *param2 = NULL; + GVariant *param3 = NULL; + GVariant *param4 = NULL; + GVariant *input_param = NULL; + + UAM_INFO_C("Request function : %s (0x%x)", + _uam_product_request_to_str(req_func), req_func); + + proxy = __uam_product_gdbuam_get_proxy(); + retv_if(NULL == proxy, UAM_ERROR_INTERNAL); + + req_info = g_malloc0(sizeof(uam_product_req_info_t)); + if (req_info) { + req_info->req_func = req_func; + req_info->cb = callback; + req_info->user_data = user_data; + } else { + UAM_ERR("Memory allocation error"); + return UAM_ERROR_OUT_OF_MEMORY; + } + param1 = g_variant_new_from_data((const GVariantType *)"ay", + in_param1->data, in_param1->len, + TRUE, NULL, NULL); + param2 = g_variant_new_from_data((const GVariantType *)"ay", + in_param2->data, in_param2->len, + TRUE, NULL, NULL); + param3 = g_variant_new_from_data((const GVariantType *)"ay", + in_param3->data, in_param3->len, + TRUE, NULL, NULL); + param4 = g_variant_new_from_data((const GVariantType *)"ay", + in_param4->data, in_param4->len, + TRUE, NULL, NULL); + + input_param = g_variant_new("(i@ay@ay@ay@ay)", req_func, param1, + param2, param3, param4); + + g_dbus_proxy_call(proxy, "uam_product_request", + input_param, + G_DBUS_CALL_FLAGS_NONE, + timeout, NULL, + __uam_product_async_request_cb, req_info); + /* + * Note: In_params is unreferenced within the g_dbus_proxy_call_sync function. + * + * ------------------------------------------------------------------------------ + * Call flow: + * g_dbus_proxy_call_sync_internal -> g_dbus_connection_call_sync -> + * g_dbus_connection_call_sync_internal -> g_dbus_message_set_body -> + * g_variant_unref(message->body); + * ------------------------------------------------------------------------------ + */ + + pending_requests = g_slist_append(pending_requests, req_info); + + FUNC_EXIT; + return result; +} -- 2.7.4 From a66cfd435ff3079865023a08079a280940f484b9 Mon Sep 17 00:00:00 2001 From: Abhay Agarwal Date: Tue, 9 Feb 2021 11:48:59 +0530 Subject: [PATCH 02/16] ua-daemon: Add support for product API's This patch adds support in ua-daemon to handle product API's. Change-Id: Ic37f326f04bbcdd6c67734ae5ae7f48ab677afa7 Signed-off-by: Abhay Agarwal --- packaging/ua-manager.conf | 7 + ua-daemon/CMakeLists.txt | 6 + ua-daemon/include/ua-manager-common.h | 9 + .../product/include/ua-manager-common-product.h | 69 ++++ .../product/include/ua-manager-core-product.h | 37 +++ ua-daemon/product/ua-manager-common-product.c | 104 ++++++ ua-daemon/product/ua-manager-core-product.c | 36 +++ .../product/ua-manager-event-sender-product.c | 74 +++++ .../product/ua-manager-request-handler-product.c | 348 +++++++++++++++++++++ ua-daemon/src/ua-manager-main.c | 7 + ua-daemon/src/ua-manager-request-handler.c | 8 +- 11 files changed, 698 insertions(+), 7 deletions(-) create mode 100644 ua-daemon/product/include/ua-manager-common-product.h create mode 100644 ua-daemon/product/include/ua-manager-core-product.h create mode 100644 ua-daemon/product/ua-manager-common-product.c create mode 100755 ua-daemon/product/ua-manager-core-product.c create mode 100644 ua-daemon/product/ua-manager-event-sender-product.c create mode 100755 ua-daemon/product/ua-manager-request-handler-product.c diff --git a/packaging/ua-manager.conf b/packaging/ua-manager.conf index d4eacda..fc03da1 100644 --- a/packaging/ua-manager.conf +++ b/packaging/ua-manager.conf @@ -5,15 +5,22 @@ + + + + + + + diff --git a/ua-daemon/CMakeLists.txt b/ua-daemon/CMakeLists.txt index 8ae9d3d..5078005 100644 --- a/ua-daemon/CMakeLists.txt +++ b/ua-daemon/CMakeLists.txt @@ -24,6 +24,10 @@ SET(SRCS src/pm/ua-cloud-plugin-handler.c src/pm/ua-vendor-plugin-manager.c src/pm/ua-vendor-plugin-handler.c + product/ua-manager-common-product.c + product/ua-manager-request-handler-product.c + product/ua-manager-event-sender-product.c + product/ua-manager-core-product.c ) IF("${CMAKE_BUILD_TYPE}" STREQUAL "") @@ -33,7 +37,9 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ua-plugins/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/product) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/product/include) SET(PKG_MODULES dlog diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h index 612ce34..7ed1738 100644 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -82,6 +82,12 @@ do { \ *ptr = NULL; \ } while (0) +#define UAM_PRIVLEVEL_PUBLIC 0 +#define UAM_PRIVLEVEL_PLATFORM 1 + +#define UAM_SYNC_FUNCTION 0 +#define UAM_ASYNC_FUNCTION 1 + typedef struct { int result; int function; @@ -107,6 +113,9 @@ GSList **_uam_manager_get_sender_apps(void); void _uam_get_sender_from_app_num(const int app_num, char **dest); +int __sender_to_app_num_operations(unsigned int *app_num, + const char *sender); + void _uam_manager_remove_req_ctxt_from_list( uam_request_context_t *req_info); diff --git a/ua-daemon/product/include/ua-manager-common-product.h b/ua-daemon/product/include/ua-manager-common-product.h new file mode 100644 index 0000000..1fb2eb2 --- /dev/null +++ b/ua-daemon/product/include/ua-manager-common-product.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 __UAM_MANAGER_COMMON_PRODUCT_H__ +#define __UAM_MANAGER_COMMON_PRODUCT_H__ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define UAM_PRODUCT_SYNC_FUNCTION 0 +#define UAM_PRODUCT_ASYNC_FUNCTION 1 + +typedef struct { + int result; + int function; + char *sender; + unsigned int tid; + GDBusMethodInvocation *context; + gpointer data; +} uam_product_request_context_t; + +int _uam_manager_product_register(void); + +void _uam_manager_product_unregister(void); + +void _uam_manager_product_method_return( + GDBusMethodInvocation *invocation, + GArray *out_param, int result); + +void _uam_manager_product_method_return( + GDBusMethodInvocation *invocation, + GArray *out_param, int result); + +int _uam_manager_product_send_event( + const char *dest, int event, GVariant *param); + +GDBusConnection *_uam_manager_product_get_gdbus_conn(void); + +const char *_uam_manager_product_request_to_str(unsigned int req); + +const char *_uam_manager_product_event_to_str(unsigned int event); + +#ifdef __cplusplus +} +#endif +#endif /* __UAM_MANAGER_COMMON_PRODUCT_H__ */ diff --git a/ua-daemon/product/include/ua-manager-core-product.h b/ua-daemon/product/include/ua-manager-core-product.h new file mode 100644 index 0000000..b1f37c4 --- /dev/null +++ b/ua-daemon/product/include/ua-manager-core-product.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 __UAM_MANAGER_CORE_PRODUCT_H__ +#define __UAM_MANAGER_CORE_PRODUCT_H__ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int _uam_product_core_test(); + +#ifdef __cplusplus +} +#endif +#endif /* __UAM_MANAGER_CORE_PRODUCT_H__ */ diff --git a/ua-daemon/product/ua-manager-common-product.c b/ua-daemon/product/ua-manager-common-product.c new file mode 100644 index 0000000..560be22 --- /dev/null +++ b/ua-daemon/product/ua-manager-common-product.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 + +#include "ua-manager-common.h" +#include "ua-plugin.h" +#include "ua-api-product.h" +#include "ua-internal-product.h" +#include "ua-manager-common-product.h" + +static const char *request_string[] = { + FOREACH_PRODUCT_REQUEST(GENERATE_PRODUCT_REQUEST_STRING) +}; + +static GDBusConnection *g_dbus_conn = NULL; + +static GDBusConnection *__uam_manager_product_get_shared_g_dbus_conn(void) +{ + FUNC_ENTRY; + GError *error = NULL; + GDBusConnection *shared_conn = NULL; + + shared_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!shared_conn) { + UAM_ERR("Unable to connect to dbus"); + if (error) { + UAM_ERR("Error: %s", error->message); + g_clear_error(&error); + } + return NULL; + } + + FUNC_EXIT; + return shared_conn; +} + +GDBusConnection *_uam_manager_product_get_gdbus_conn(void) +{ + FUNC_ENTRY; + + if (g_dbus_conn) { + if (g_dbus_connection_is_closed(g_dbus_conn)) + g_dbus_conn = __uam_manager_product_get_shared_g_dbus_conn(); + + FUNC_EXIT; + return g_dbus_conn; + } + + g_dbus_conn = __uam_manager_product_get_shared_g_dbus_conn(); + FUNC_EXIT; + return g_dbus_conn; +} + +const char *_uam_manager_product_request_to_str(unsigned int req) +{ + retv_if(UAM_PRODUCT_REQUEST_MAX <= req, NULL); + + return request_string[req]; +} + +const char *_uam_manager_product_event_to_str(unsigned int event) +{ + retv_if(UAM_PRODUCT_EVENT_MAX <= event, NULL); + + switch (event) { + CASE_TO_STR(UAM_PRODUCT_EVENT_TEST) + default: + return "UNKNOWN ERROR"; + } +} + +void _uam_manager_product_method_return( + GDBusMethodInvocation *invocation, GArray *out_param, int result) +{ + FUNC_ENTRY; + GVariant *out_var = NULL; + GVariant *return_var = NULL; + out_var = g_variant_new_from_data((const GVariantType *)"ay", + out_param->data, out_param->len, TRUE, NULL, NULL); + + return_var = g_variant_new("(iv)", result, out_var); + + g_dbus_method_invocation_return_value(invocation, return_var); + + FUNC_EXIT; +} diff --git a/ua-daemon/product/ua-manager-core-product.c b/ua-daemon/product/ua-manager-core-product.c new file mode 100755 index 0000000..d92fdff --- /dev/null +++ b/ua-daemon/product/ua-manager-core-product.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 "ua-api-product.h" +#include "ua-internal-product.h" +#include "ua-plugin-manager.h" +#include "ua-manager-common-product.h" + +int _uam_product_core_test() +{ + FUNC_ENTRY; + + _uam_manager_product_send_event(NULL, UAM_PRODUCT_EVENT_TEST, + g_variant_new("(i)", UAM_ERROR_NONE)); + + FUNC_EXIT; + return UAM_ERROR_NONE; +} diff --git a/ua-daemon/product/ua-manager-event-sender-product.c b/ua-daemon/product/ua-manager-event-sender-product.c new file mode 100644 index 0000000..871a2ce --- /dev/null +++ b/ua-daemon/product/ua-manager-event-sender-product.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 "ua-manager-common.h" +#include "ua-api-product.h" +#include "ua-internal-product.h" +#include "ua-manager-common-product.h" + +#define UA_PRODUCT_EVENT "UA_PRODUCT_EVENT" + +#define CASE_TO_STR(x) case x: return #x; + +const char* __uam_product_event_str(int event) +{ + switch (event) { + CASE_TO_STR(UAM_PRODUCT_EVENT_TEST) + default : + return "Unknown Event"; + } +} + +int _uam_manager_product_send_event(const char *dest, int event, GVariant *param) +{ + FUNC_ENTRY; + char *signal; + GError *error = NULL; + GDBusConnection *conn; + + conn = _uam_manager_product_get_gdbus_conn(); + retv_if(conn == NULL, UAM_ERROR_INTERNAL); + + switch (event) { + case UAM_PRODUCT_EVENT_TEST: + signal = UAM_PRODUCT_SIGNAL_TEST; + break; + default: + UAM_ERR("Unhandled event"); + return UAM_ERROR_INTERNAL; + } + + UAM_INFO_C("Destination: [%s], event: [%s], signal: [%s]", + dest, _uam_manager_product_event_to_str(event), signal); + + if (!g_dbus_connection_emit_signal(conn, dest, UAM_PRODUCT_EVENT_PATH, + UAM_PRODUCT_EVENT_INTERFACE, signal, param, &error)) { + UAM_ERR("Error while sending Signal: %s", signal); + if (error) { + UAM_ERR("Error Code [%d], Error Message [%s]", + error->code, error->message); + g_clear_error(&error); + } + + return UAM_ERROR_INTERNAL; + } + + FUNC_EXIT; + return UAM_ERROR_NONE; +} diff --git a/ua-daemon/product/ua-manager-request-handler-product.c b/ua-daemon/product/ua-manager-request-handler-product.c new file mode 100755 index 0000000..b246323 --- /dev/null +++ b/ua-daemon/product/ua-manager-request-handler-product.c @@ -0,0 +1,348 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Author: Abhay Agarwal + * + * 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 "ua-internal.h" +#include "ua-manager-common.h" +#include "ua-internal-product.h" +#include "ua-manager-common-product.h" +#include "ua-manager-core-product.h" + +static GDBusConnection *uam_manager_product_conn; +static guint g_dbus_object_id = 0; +static guint owner_id = 0; +static guint owner_sig_id = 0; + +static const gchar uam_manager_product_introspection_xml[] = +"" +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +""; + +typedef struct { + uam_product_request_e request; + int priv_level; + int function_type; +} uam_product_request_table_s; + + +static uam_product_request_table_s request_table[] = { + { UAM_PRODUCT_REQUEST_TEST, UAM_PRIVLEVEL_PLATFORM, UAM_PRODUCT_SYNC_FUNCTION }, +}; + +static int __uam_manager_product_sync_request_handler( + GDBusMethodInvocation *context, + int function, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4, + GArray **out_param1) +{ + FUNC_ENTRY; + int result = UAM_ERROR_NOT_SUPPORTED; + char *sender = NULL; + unsigned int app_num = 0; + + sender = (char*)g_dbus_method_invocation_get_sender(context); + + __sender_to_app_num_operations(&app_num, sender); + UAM_DBG("sender[%s], app_num[%u]", sender, app_num); + + if (app_num <= 0) + UAM_ERR("app_num[%d] is invalid", app_num); + + switch (function) { + case UAM_PRODUCT_REQUEST_TEST: { + + result = _uam_product_core_test(); + break; + } + default: + UAM_WARN("UnSupported function [%s(0x%4.4X)]", + _uam_manager_product_request_to_str(function), function); + result = UAM_ERROR_NOT_SUPPORTED; + break; + } + + FUNC_EXIT; + return result; +} + +static int __uam_manager_product_async_request_handler( + GDBusMethodInvocation *context, + int function, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4, + GArray **out_param1) +{ + FUNC_ENTRY; + int result = UAM_ERROR_NOT_SUPPORTED; + char *sender = NULL; + unsigned int app_num = 0; + + sender = (char*)g_dbus_method_invocation_get_sender(context); + + __sender_to_app_num_operations(&app_num, sender); + UAM_DBG("sender[%s], app_num[%u]", sender, app_num); + + switch (function) { + default: + UAM_WARN("UnSupported function [%s(0x%4.4X)]", + _uam_manager_product_request_to_str(function), function); + result = UAM_ERROR_NOT_SUPPORTED; + break; + } + + FUNC_EXIT; + return result; +} + +static int __uam_manager_product_get_function_type(int function) +{ + return request_table[function].function_type; +} + +static void __uam_manager_product_method( + GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + FUNC_ENTRY; + int result = UAM_ERROR_NONE; + + UAM_DBG("Sender[%s] Method[%s] Path[%s] Interface[%s]", + sender, method_name, object_path, interface_name); + + if (0 == g_strcmp0(method_name, "uam_product_request")) { + int function; + + GVariant *in_param1 = NULL; + GVariant *in_param2 = NULL; + GVariant *in_param3 = NULL; + GVariant *in_param4 = NULL; + GArray *out_param1 = NULL; + + g_variant_get(parameters, "(i@ay@ay@ay@ay)", &function, + &in_param1, &in_param2, &in_param3, &in_param4); + + out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar)); + + UAM_DBG("Request function = [%s (0x%4.4X)]", + _uam_manager_product_request_to_str(function), function); + + if (UAM_PRODUCT_SYNC_FUNCTION == + __uam_manager_product_get_function_type(function)) { + + result = __uam_manager_product_sync_request_handler( + invocation, function, in_param1, in_param2, + in_param3, in_param4, &out_param1); + } else { + result = __uam_manager_product_async_request_handler( + invocation, function, in_param1, in_param2, + in_param3, in_param4, &out_param1); + + if (UAM_ERROR_NONE == result) { + UAM_DBG("Request context is saved, do not send reply over dbus"); + goto done; + } + } + + if (UAM_ERROR_NONE != result) { + UAM_ERR("Request [%s (0x%4.4X)] is failed with [%s (0x%4.4X])", + _uam_manager_product_request_to_str(function), function, + _uam_manager_error_to_str(result), result); + } + + _uam_manager_product_method_return(invocation, out_param1, result); + +done: + g_variant_unref(in_param1); + g_variant_unref(in_param2); + g_variant_unref(in_param3); + g_variant_unref(in_param4); + g_array_unref(out_param1); + } + + FUNC_EXIT; + return; +} + +static GDBusNodeInfo *__uam_manager_product_create_method_node_info( + const gchar *introspection_data) +{ + FUNC_ENTRY; + GError *err = NULL; + GDBusNodeInfo *node_info = NULL; + + if (introspection_data == NULL) { + UAM_ERR("Introspection XML not present"); + return NULL; + } + + node_info = g_dbus_node_info_new_for_xml(introspection_data, &err); + if (err) { + UAM_ERR("Unable to create node: %s", err->message); + g_clear_error(&err); + } + + FUNC_EXIT; + return node_info; +} + +static const GDBusInterfaceVTable uam_method_table = { + __uam_manager_product_method, + NULL, + NULL, + {0} +}; + +static int __uam_manager_product_register_object( + GDBusConnection *conn, GDBusNodeInfo *node_info) +{ + FUNC_ENTRY; + GError *error = NULL; + + retv_if(NULL == node_info, UAM_ERROR_INTERNAL); + + g_dbus_object_id = g_dbus_connection_register_object(conn, + UAM_PRODUCT_DAEMON_PATH, + node_info->interfaces[0], + &uam_method_table, + NULL, NULL, &error); + retv_if(0 == g_dbus_object_id, UAM_ERROR_INTERNAL); + + FUNC_EXIT; + return UAM_ERROR_NONE; +} + +static int __uam_manager_product_unregister_object(GDBusConnection *conn) +{ + FUNC_ENTRY; + + if (g_dbus_object_id > 0) { + g_dbus_connection_unregister_object( + conn, g_dbus_object_id); + g_dbus_object_id = 0; + } + + FUNC_EXIT; + return UAM_ERROR_NONE; +} + +static void __uam_manager_product_name_acquired_cb( + GDBusConnection *connection, const gchar *name, gpointer user_data) +{ + UAM_INFO("DBus name [%s] acquired", name); +} + +static void __uam_manager_product_name_lost_cb( + GDBusConnection *connection, const gchar *name, gpointer user_data) +{ + if (NULL == connection) { + UAM_ERR("connection to the bus can't be made"); + return; + } + + UAM_ERR("DBus name [%s] lost", name); +} + + +static void __uam_manager_product_bus_acquired_cb( + GDBusConnection *connection, const gchar *name, gpointer user_data) +{ + FUNC_ENTRY; + + UAM_INFO("DBus %s bus acquired", name); + + GDBusNodeInfo *node_info = NULL; + + UAM_INFO("DBus bus acquired"); + + ret_if(connection == NULL); + + node_info = __uam_manager_product_create_method_node_info( + uam_manager_product_introspection_xml); + ret_if(node_info == NULL); + + __uam_manager_product_register_object(connection, node_info); + g_dbus_node_info_unref(node_info); + + uam_manager_product_conn = connection; + g_object_ref(uam_manager_product_conn); + FUNC_EXIT; +} + +int _uam_manager_product_register(void) +{ + FUNC_ENTRY; + + owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, + UAM_PRODUCT_DBUS_NAME, + G_BUS_NAME_OWNER_FLAGS_REPLACE, + __uam_manager_product_bus_acquired_cb, + __uam_manager_product_name_acquired_cb, + __uam_manager_product_name_lost_cb, + NULL, NULL); + if (0 == owner_id) + goto fail; + + UAM_DBG("owner_id is [%d]", owner_id); + + FUNC_EXIT; + return UAM_ERROR_NONE; + +fail: + if (uam_manager_product_conn) { + g_object_unref(uam_manager_product_conn); + uam_manager_product_conn = NULL; + } + return UAM_ERROR_INTERNAL; +} + +void _uam_manager_product_unregister(void) +{ + FUNC_ENTRY; + + if (uam_manager_product_conn) { + g_dbus_connection_signal_unsubscribe(uam_manager_product_conn, owner_sig_id); + __uam_manager_product_unregister_object(uam_manager_product_conn); + g_bus_unown_name(owner_id); + g_dbus_connection_flush_sync(uam_manager_product_conn, NULL, NULL); + g_object_unref(uam_manager_product_conn); + uam_manager_product_conn = NULL; + } + + FUNC_EXIT; +} diff --git a/ua-daemon/src/ua-manager-main.c b/ua-daemon/src/ua-manager-main.c index f05caec..3e1e03e 100644 --- a/ua-daemon/src/ua-manager-main.c +++ b/ua-daemon/src/ua-manager-main.c @@ -20,6 +20,7 @@ #include "ua-api.h" #include "ua-internal.h" #include "ua-manager-common.h" +#include "ua-manager-common-product.h" #include "ua-plugin-manager.h" GMainLoop *main_loop; @@ -37,6 +38,9 @@ static void __uam_manager_cleanup(void) /* Deinit plugins */ _uam_pm_deinit(); + /* unregister ua-manager product*/ + _uam_manager_product_unregister(); + /* unregister ua-manager*/ _uam_manager_unregister(); } @@ -169,6 +173,9 @@ static int __uam_manager_init(void) result = _uam_manager_register(); retv_if(UAM_ERROR_NONE != result, result); + result = _uam_manager_product_register(); + retv_if(UAM_ERROR_NONE != result, result); + result = _uam_pm_init(); if (UAM_ERROR_NONE != result) { _uam_manager_unregister(); diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 671a640..2a740ea 100755 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -23,12 +23,6 @@ #include #include -#define UAM_PRIVLEVEL_PUBLIC 0 -#define UAM_PRIVLEVEL_PLATFORM 1 - -#define UAM_SYNC_FUNCTION 0 -#define UAM_ASYNC_FUNCTION 1 - extern GMainLoop *main_loop; /* For maintaining Application Sync API call requests */ @@ -338,7 +332,7 @@ void _uam_get_sender_from_app_num(const int app_num, char **sender) FUNC_EXIT; } -static int __sender_to_app_num_operations(unsigned int *app_num, const char *sender) +int __sender_to_app_num_operations(unsigned int *app_num, const char *sender) { FUNC_ENTRY; GSList * l1 = NULL; -- 2.7.4 From eb699e8b91576a3a0b72591063ae457f52906b19 Mon Sep 17 00:00:00 2001 From: DoHyun Pyun Date: Thu, 25 Feb 2021 08:20:16 +0900 Subject: [PATCH 03/16] Fix the security configuration issue (Shell Script) All command line tools in any shell script should be executed in designated location or executed as absolute path. Change-Id: I8f9548f7fda0db656ede895be2fd7c92e2c9161f Signed-off-by: DoHyun Pyun --- ua-daemon/data/create-ua-db.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ua-daemon/data/create-ua-db.sh b/ua-daemon/data/create-ua-db.sh index 912793b..9bb6e42 100755 --- a/ua-daemon/data/create-ua-db.sh +++ b/ua-daemon/data/create-ua-db.sh @@ -1,4 +1,5 @@ #!/bin/bash +PATH=/bin:/usr/bin:/sbin:/usr/sbin sqlite3 /opt/usr/dbspace/.ua-manager-data.db < /usr/share/ua_db.sql chown network_fw:network_fw /opt/usr/dbspace/.ua-manager-data.db* -- 2.7.4 From 8d6986b772c4becc5adb380849ae96cdc9649ad7 Mon Sep 17 00:00:00 2001 From: "hyunuk.tak" Date: Tue, 23 Mar 2021 08:59:30 +0900 Subject: [PATCH 04/16] Modify default policy for dbus Change-Id: I3a02f401a9c7614d42bb7919e41a1b4c89fac522 Signed-off-by: hyunuk.tak --- packaging/ua-manager.conf | 10 ++++++---- packaging/ua-manager.spec | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packaging/ua-manager.conf b/packaging/ua-manager.conf index fc03da1..509be15 100644 --- a/packaging/ua-manager.conf +++ b/packaging/ua-manager.conf @@ -16,11 +16,13 @@ - + - - - + + + + + diff --git a/packaging/ua-manager.spec b/packaging/ua-manager.spec index 76196a7..00885ae 100644 --- a/packaging/ua-manager.spec +++ b/packaging/ua-manager.spec @@ -1,6 +1,6 @@ Name: ua-manager Summary: User awareness manager -Version: 0.14.11 +Version: 0.14.12 Release: 1 License: Apache-2.0 Source0: %{name}-%{version}.tar.gz -- 2.7.4 From 325289c04d93bb46180ff20d80dd8f4c5cb4b45f Mon Sep 17 00:00:00 2001 From: "hyunuk.tak" Date: Fri, 26 Mar 2021 08:37:44 +0900 Subject: [PATCH 05/16] Modify to check privilege Change privilege as below userawareness, userawareness.admin => bluetooth, network.get, location Add request for adding/removing sensor Change-Id: Iedd72ba46ac0a93b1ba320f637a9b0aa464686d1 Signed-off-by: hyunuk.tak --- include/ua-api.h | 34 +++ include/ua-internal.h | 7 +- ua-api/src/ua-api.c | 36 +++ ua-daemon/include/ua-manager-common.h | 5 +- .../product/ua-manager-request-handler-product.c | 4 +- ua-daemon/src/ua-manager-request-handler.c | 284 +++++++++++++++------ 6 files changed, 287 insertions(+), 83 deletions(-) mode change 100644 => 100755 include/ua-api.h mode change 100644 => 100755 include/ua-internal.h mode change 100644 => 100755 ua-api/src/ua-api.c mode change 100644 => 100755 ua-daemon/include/ua-manager-common.h diff --git a/include/ua-api.h b/include/ua-api.h old mode 100644 new mode 100755 index b4fa365..8ac4301 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -1471,6 +1471,40 @@ int _uam_service_add_payload(const char *service, */ int _uam_get_added_payloads(GPtrArray **payload_list); +/** + * @brief Requests to add a sensor info. + * @since_tizen 6.5 + * + * @param[in] bitmask Sensor bitmask. + * + * @return 0 on success, otherwise a negative error value + * @retval #UAM_ERROR_NONE Successful + * @retval #UAM_ERROR_INVALID_PARAMETER Invalid parameters + * @retval #UAM_ERROR_INTERNAL Internal error + * + * @exception + * @pre + * @post + */ +int _uam_request_add_sensor(unsigned int bitmask); + +/** + * @brief Requests to remove a sensor info. + * @since_tizen 6.5 + * + * @param[in] bitmask Sensor bitmask. + * + * @return 0 on success, otherwise a negative error value + * @retval #UAM_ERROR_NONE Successful + * @retval #UAM_ERROR_INVALID_PARAMETER Invalid parameters + * @retval #UAM_ERROR_INTERNAL Internal error + * + * @exception + * @pre + * @post + */ +int _uam_request_remove_sensor(unsigned int bitmask); + #ifdef __cplusplus } #endif diff --git a/include/ua-internal.h b/include/ua-internal.h old mode 100644 new mode 100755 index c6f5e6a..0e3e2e0 --- a/include/ua-internal.h +++ b/include/ua-internal.h @@ -32,8 +32,9 @@ extern "C" { #define UAM_SERVICE_DBUS "org.freedesktop.DBus" #define UAM_INTERFACE_DBUS "org.freedesktop.DBus" -#define UAM_PRIVILEGE_PUBLIC "http://tizen.org/privilege/userawareness" -#define UAM_PRIVILEGE_PLATFORM "http://tizen.org/privilege/userawareness.admin" +#define UAM_PRIVILEGE_BLUETOOTH "http://tizen.org/privilege/bluetooth" +#define UAM_PRIVILEGE_NETWORK "http://tizen.org/privilege/network.get" +#define UAM_PRIVILEGE_LOCATION "http://tizen.org/privilege/location" #define FOREACH_REQUEST(REQUEST) \ REQUEST(UAM_REQUEST_GET_AVAILABLE_SENSORS) \ @@ -89,6 +90,8 @@ extern "C" { REQUEST(UAM_REQUEST_ADD_PAYLOAD) \ REQUEST(UAM_REQUEST_ADD_PAYLOAD_TO_SERVICE) \ REQUEST(UAM_REQUEST_GET_PAYLOADS) \ + REQUEST(UAM_REQUEST_ADD_SENSOR) \ + REQUEST(UAM_REQUEST_REMOVE_SENSOR) \ REQUEST(UAM_REQUEST_MAX) #define GENERATE_REQUEST_ENUM(ENUM) ENUM, diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c old mode 100644 new mode 100755 index b9e4e7e..cb3336b --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -1535,3 +1535,39 @@ UAM_EXPORT_API int _uam_get_added_payloads(GPtrArray **payload_list) FUNC_EXIT; return ret; } + +UAM_EXPORT_API int _uam_request_add_sensor(unsigned int bitmask) +{ + FUNC_ENTRY; + int ret; + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &bitmask, sizeof(unsigned int)); + ret = _uam_sync_request(UAM_REQUEST_ADD_SENSOR, + in_param1, in_param2, in_param3, in_param4, &out_param); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} + +UAM_EXPORT_API int _uam_request_remove_sensor(unsigned int bitmask) +{ + FUNC_ENTRY; + int ret; + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &bitmask, sizeof(unsigned int)); + ret = _uam_sync_request(UAM_REQUEST_REMOVE_SENSOR, + in_param1, in_param2, in_param3, in_param4, &out_param); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h old mode 100644 new mode 100755 index 7ed1738..78d3105 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -82,8 +82,9 @@ do { \ *ptr = NULL; \ } while (0) -#define UAM_PRIVLEVEL_PUBLIC 0 -#define UAM_PRIVLEVEL_PLATFORM 1 +#define UAM_PRIVTYPE_NA 0x00 +#define UAM_PRIVTYPE_DEVICE 0x01 +#define UAM_PRIVTYPE_LOCATION 0x02 #define UAM_SYNC_FUNCTION 0 #define UAM_ASYNC_FUNCTION 1 diff --git a/ua-daemon/product/ua-manager-request-handler-product.c b/ua-daemon/product/ua-manager-request-handler-product.c index b246323..6bf2216 100755 --- a/ua-daemon/product/ua-manager-request-handler-product.c +++ b/ua-daemon/product/ua-manager-request-handler-product.c @@ -45,13 +45,13 @@ static const gchar uam_manager_product_introspection_xml[] = typedef struct { uam_product_request_e request; - int priv_level; + int privilege_type; int function_type; } uam_product_request_table_s; static uam_product_request_table_s request_table[] = { - { UAM_PRODUCT_REQUEST_TEST, UAM_PRIVLEVEL_PLATFORM, UAM_PRODUCT_SYNC_FUNCTION }, + { UAM_PRODUCT_REQUEST_TEST, UAM_PRIVTYPE_NA, UAM_PRODUCT_SYNC_FUNCTION }, }; static int __uam_manager_product_sync_request_handler( diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 2a740ea..64dbf46 100755 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -64,64 +64,66 @@ static const gchar uam_manager_introspection_xml[] = typedef struct { uam_request_e request; - int priv_level; + int privilege_type; int function_type; } uam_request_table_s; static uam_request_table_s request_table[] = { - { UAM_REQUEST_GET_AVAILABLE_SENSORS, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_IS_SENSOR_READY, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_DEFAULT_USER, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_ADD_USER, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_DELETE_USER, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_UPDATE_USER, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_USER_BY_ACCOUNT, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_USER_BY_DEVICE_ID, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_USER_BY_MAC, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_USERS, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_ADD_DEVICE, UAM_PRIVLEVEL_PUBLIC, UAM_ASYNC_FUNCTION }, - { UAM_REQUEST_DELETE_DEVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_UPDATE_DEVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_DELETE_DEVICE_BY_DEVICE_ID, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_DELETE_DEVICE_BY_MAC, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_DEVICE_BY_DEVICE_ID, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_DEVICE_BY_MAC, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_DEVICES, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_USER_DEVICES, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_IS_DEVICE_ADDED, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_SET_DETECTION_THRESHOLD, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_START_PRESENCE_DETECTION, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_STOP_PRESENCE_DETECTION, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_START_ABSENCE_DETECTION, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_STOP_ABSENCE_DETECTION, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_SET_LOW_POWER_MODE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_REGISTER_APP, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_DEREGISTER_APP, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_ADD_USER_TO_SERVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_REMOVE_USER_FROM_SERVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_ADD_DEVICE_TO_SERVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_REMOVE_DEVICE_FROM_SERVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_SET_DEVICE_SERVICES_DISCRIMINANT, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_DEVICE_SERVICES_DISCRIMINANT, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_DEVICE_SERVICES_LAST_SEEN, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_SET_SERVICE_DETECTION_CYCLE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_SERVICE_DETECTION_CYCLE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_DETECTION_WINDOW, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_SET_DETECTION_WINDOW, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_RESET_DB, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_DEFAULT_SERVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_REGISTER_SERVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_UPDATE_SERVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_UNREGISTER_SERVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_SERVICE_DEVICES, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_SERVICE_USERS, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_SERVICES, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_ADD_IBEACON_ADV, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_ADD_PAYLOAD, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_ADD_PAYLOAD_TO_SERVICE, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, - { UAM_REQUEST_GET_PAYLOADS, UAM_PRIVLEVEL_PUBLIC, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_AVAILABLE_SENSORS, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_IS_SENSOR_READY, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_DEFAULT_USER, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_ADD_USER, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_DELETE_USER, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_UPDATE_USER, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_USER_BY_ACCOUNT, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_USER_BY_DEVICE_ID, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_USER_BY_MAC, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_USERS, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_ADD_DEVICE, UAM_PRIVTYPE_DEVICE, UAM_ASYNC_FUNCTION }, + { UAM_REQUEST_DELETE_DEVICE, UAM_PRIVTYPE_DEVICE, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_UPDATE_DEVICE, UAM_PRIVTYPE_DEVICE, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_DELETE_DEVICE_BY_DEVICE_ID, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_DELETE_DEVICE_BY_MAC, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_DEVICE_BY_DEVICE_ID, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_DEVICE_BY_MAC, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_DEVICES, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_USER_DEVICES, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_IS_DEVICE_ADDED, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_SET_DETECTION_THRESHOLD, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_START_PRESENCE_DETECTION, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_STOP_PRESENCE_DETECTION, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_START_ABSENCE_DETECTION, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_STOP_ABSENCE_DETECTION, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_SET_LOW_POWER_MODE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES, UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_REGISTER_APP, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_DEREGISTER_APP, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_ADD_USER_TO_SERVICE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_REMOVE_USER_FROM_SERVICE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_ADD_DEVICE_TO_SERVICE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_REMOVE_DEVICE_FROM_SERVICE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_SET_DEVICE_SERVICES_DISCRIMINANT, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_DEVICE_SERVICES_DISCRIMINANT, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_DEVICE_SERVICES_LAST_SEEN, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_SET_SERVICE_DETECTION_CYCLE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_SERVICE_DETECTION_CYCLE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_DETECTION_WINDOW, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_SET_DETECTION_WINDOW, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_RESET_DB, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_DEFAULT_SERVICE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_REGISTER_SERVICE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_UPDATE_SERVICE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_UNREGISTER_SERVICE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_SERVICE_DEVICES, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_SERVICE_USERS, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_SERVICES, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_ADD_IBEACON_ADV, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_ADD_PAYLOAD, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_ADD_PAYLOAD_TO_SERVICE, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_GET_PAYLOADS, UAM_PRIVTYPE_NA, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_ADD_SENSOR, UAM_PRIVTYPE_DEVICE, UAM_SYNC_FUNCTION }, + { UAM_REQUEST_REMOVE_SENSOR, UAM_PRIVTYPE_DEVICE, UAM_SYNC_FUNCTION }, }; #define UAM_ASYNC_REQUEST_TIMEOUT 11 /* 11 sec */ @@ -1070,6 +1072,10 @@ static int __uam_manager_sync_request_handler( } break; } + case UAM_REQUEST_ADD_SENSOR: + case UAM_REQUEST_REMOVE_SENSOR: + result = UAM_ERROR_NONE; + break; default: UAM_WARN("UnSupported function [%s(0x%4.4X)]", _uam_manager_request_to_str(function), function); @@ -1301,19 +1307,133 @@ static int __uam_manager_get_function_type(int function) return request_table[function].function_type; } -static int __uam_manager_get_priv_level(int function) +static int __uam_manager_get_privilege_type(int function) { - return request_table[function].priv_level; + return request_table[function].privilege_type; } -gboolean __uam_manager_check_privilege(int function, - const char *unique_name) +static unsigned int __uam_manager_get_device_type( + int function, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4) +{ + unsigned int device_type = 0; + + switch (function) { + case UAM_REQUEST_ADD_SENSOR: + case UAM_REQUEST_REMOVE_SENSOR: { + unsigned int bitmask; + + __uam_manager_copy_params(in_param1, + &bitmask, sizeof(unsigned int)); + + if (bitmask == UAM_SENSOR_BITMASK_BT || + bitmask == UAM_SENSOR_BITMASK_BLE) { + device_type = UAM_SENSOR_BITMASK_BT; + } else if (bitmask == UAM_SENSOR_BITMASK_WIFI) { + device_type = UAM_SENSOR_BITMASK_WIFI; + } + + break; + } + case UAM_REQUEST_ADD_DEVICE: + case UAM_REQUEST_DELETE_DEVICE:{ + uam_device_info_s dev_info; + + __uam_manager_copy_params(in_param2, + &dev_info, sizeof(uam_device_info_s)); + + if (dev_info.type == UAM_TECH_TYPE_BT || + dev_info.type == UAM_TECH_TYPE_BLE) { + device_type = UAM_TECH_TYPE_BT; + } else if (dev_info.type == UAM_TECH_TYPE_WIFI) { + device_type = UAM_TECH_TYPE_WIFI; + } + + break; + } + case UAM_REQUEST_UPDATE_DEVICE: { + uam_device_info_s dev_info; + + __uam_manager_copy_params(in_param1, + &dev_info, sizeof(uam_device_info_s)); + + if (dev_info.type == UAM_TECH_TYPE_BT || + dev_info.type == UAM_TECH_TYPE_BLE) { + device_type = UAM_TECH_TYPE_BT; + } else if (dev_info.type == UAM_TECH_TYPE_WIFI) { + device_type = UAM_TECH_TYPE_WIFI; + } + + break; + } + case UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES: + case UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES: + case UAM_REQUEST_START_PRESENCE_DETECTION: + case UAM_REQUEST_STOP_PRESENCE_DETECTION: + case UAM_REQUEST_START_ABSENCE_DETECTION: + case UAM_REQUEST_STOP_ABSENCE_DETECTION: { + unsigned int bitmask = 0; + + __uam_manager_copy_params(in_param1, + &bitmask, sizeof(unsigned int)); + + if (bitmask == UAM_SENSOR_BITMASK_BT || + bitmask == UAM_SENSOR_BITMASK_BLE) { + device_type = UAM_SENSOR_BITMASK_BT; + } else if (bitmask == UAM_SENSOR_BITMASK_WIFI) { + device_type = UAM_SENSOR_BITMASK_WIFI; + } + + break; + } + default : + device_type = 0; + break; + } + + return device_type; +} + +static gboolean __uam_manager_check_cynara( + char *client_creds, + char *client_session, + char *user_creds, + const char *privilege) +{ + int ret; + + if (privilege) { + ret = cynara_check(p_cynara, client_creds, + client_session, user_creds, privilege); + if (ret != CYNARA_API_ACCESS_ALLOWED) { + UAM_ERR("Access denied: %s", privilege); + return FALSE; + } + + UAM_INFO("[%s][%s]", client_creds, privilege); + } + + return TRUE; +} + +static gboolean __uam_manager_check_privilege( + const char *unique_name, + int function, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4) { - int ret_val; gboolean result = TRUE; char *client_creds = NULL; char *user_creds = NULL; char *client_session = ""; + unsigned int device_type = 0; + char *device_privilege = NULL; + char *location_privilege = NULL; retv_if(unique_name == NULL, FALSE); @@ -1326,27 +1446,36 @@ gboolean __uam_manager_check_privilege(int function, return FALSE; } - UAM_DBG("%s, %s, %s", unique_name, client_creds, user_creds); + if (UAM_PRIVTYPE_DEVICE == __uam_manager_get_privilege_type(function)) { + device_type = __uam_manager_get_device_type(function, + in_param1, in_param2, in_param3, in_param4); + if (device_type == UAM_TECH_TYPE_BT) + device_privilege = UAM_PRIVILEGE_BLUETOOTH; + else if (device_type == UAM_TECH_TYPE_WIFI) + device_privilege = UAM_PRIVILEGE_NETWORK; + } else if ((UAM_PRIVTYPE_DEVICE | UAM_PRIVTYPE_LOCATION) + == __uam_manager_get_privilege_type(function)) { + device_type = __uam_manager_get_device_type(function, + in_param1, in_param2, in_param3, in_param4); + if (device_type == UAM_TECH_TYPE_BT) + device_privilege = UAM_PRIVILEGE_BLUETOOTH; + else if (device_type == UAM_TECH_TYPE_WIFI) + device_privilege = UAM_PRIVILEGE_NETWORK; - if (UAM_PRIVLEVEL_PUBLIC == __uam_manager_get_priv_level(function)) { - ret_val = cynara_check(p_cynara, client_creds, - client_session, user_creds, UAM_PRIVILEGE_PUBLIC); + /* TODO: It will be added in later + location_privilege = UAM_PRIVILEGE_LOCATION; + */ + } - UAM_INFO("Client Credentials [%s]", client_creds); - if (ret_val != CYNARA_API_ACCESS_ALLOWED) { - UAM_ERR("Fail to access: %s", UAM_PRIVILEGE_PUBLIC); - result = FALSE; - } - } else { - ret_val = cynara_check(p_cynara, client_creds, - client_session, user_creds, UAM_PRIVILEGE_PLATFORM); + if (!(result = __uam_manager_check_cynara(client_creds, + client_session, user_creds, device_privilege))) + goto done; - if (ret_val != CYNARA_API_ACCESS_ALLOWED) { - UAM_ERR("Fail to access: %s", UAM_PRIVILEGE_PLATFORM); - result = FALSE; - } - } + if (!(result = __uam_manager_check_cynara(client_creds, + client_session, user_creds, location_privilege))) + goto done; +done: g_free(client_creds); g_free(user_creds); @@ -1432,7 +1561,8 @@ static void __uam_manager_method( out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar)); - if (__uam_manager_check_privilege(function, (const char *)sender) == FALSE) { + if (__uam_manager_check_privilege((const char *)sender, function, + in_param1, in_param2, in_param3, in_param4) == FALSE) { UAM_ERR("Client don't have the privilege to excute this function"); /* TODO: result = UAM_ERROR_PERMISSION_DENIED; -- 2.7.4 From d36b2ab9d6b4d1102f745d3d096baa7f93497e13 Mon Sep 17 00:00:00 2001 From: rohit singh Date: Wed, 12 May 2021 17:22:29 +0530 Subject: [PATCH 06/16] Fix for __uam_manager_get_device_type Issue: Return type mismatch issue. Inside function __uam_manager_get_device_type() enum UAM_SENSOR_BITMASK_* is used instead of UAM_TECH_TYPE-*, which was inconsistent to the function calling __uam_manager_get_device_type(). Solution: Changed UAM_SENSOR_BITMASK_* to UAM_TECH_TYPE-*. Change-Id: I1df188dd713379e8c594de86707bf39e05a7fec9 --- ua-daemon/src/ua-manager-request-handler.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 64dbf46..c1728be 100755 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -1331,9 +1331,9 @@ static unsigned int __uam_manager_get_device_type( if (bitmask == UAM_SENSOR_BITMASK_BT || bitmask == UAM_SENSOR_BITMASK_BLE) { - device_type = UAM_SENSOR_BITMASK_BT; + device_type = UAM_TECH_TYPE_BT; } else if (bitmask == UAM_SENSOR_BITMASK_WIFI) { - device_type = UAM_SENSOR_BITMASK_WIFI; + device_type = UAM_TECH_TYPE_WIFI; } break; @@ -1382,9 +1382,9 @@ static unsigned int __uam_manager_get_device_type( if (bitmask == UAM_SENSOR_BITMASK_BT || bitmask == UAM_SENSOR_BITMASK_BLE) { - device_type = UAM_SENSOR_BITMASK_BT; + device_type = UAM_TECH_TYPE_BT; } else if (bitmask == UAM_SENSOR_BITMASK_WIFI) { - device_type = UAM_SENSOR_BITMASK_WIFI; + device_type = UAM_TECH_TYPE_WIFI; } break; -- 2.7.4 From 476858a937335f9384cb7d05692866fb48d5cda7 Mon Sep 17 00:00:00 2001 From: rohit singh Date: Mon, 24 May 2021 11:23:55 +0530 Subject: [PATCH 07/16] Dead default in switch Issue: The statements in the default case are never executed. Solution: Removal of the retv statement will solve the issue. Change-Id: I74cc0d357acbb7bc5ce986ef532f5684b3ab74fa Signed-off-by: rohit.singh --- ua-api/product/ua-common-product.c | 2 -- ua-api/src/ua-common.c | 3 +-- ua-daemon/product/ua-manager-common-product.c | 2 -- ua-daemon/src/ua-manager-common.c | 3 +-- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/ua-api/product/ua-common-product.c b/ua-api/product/ua-common-product.c index 274d80e..bf18a17 100644 --- a/ua-api/product/ua-common-product.c +++ b/ua-api/product/ua-common-product.c @@ -74,8 +74,6 @@ const char *_uam_product_request_to_str(unsigned int req) const char *_uam_product_event_to_str(unsigned int event) { - retv_if(UAM_PRODUCT_EVENT_MAX <= event, NULL); - switch (event) { CASE_TO_STR(UAM_PRODUCT_EVENT_TEST) default: diff --git a/ua-api/src/ua-common.c b/ua-api/src/ua-common.c index 6a96333..91e756d 100644 --- a/ua-api/src/ua-common.c +++ b/ua-api/src/ua-common.c @@ -92,8 +92,6 @@ const char *_uam_request_to_str(unsigned int req) const char *_uam_event_to_str(unsigned int event) { - retv_if(UAM_EVENT_MAX <= event, NULL); - switch (event) { CASE_TO_STR(UAM_EVENT_USER_ADDED) CASE_TO_STR(UAM_EVENT_USER_REMOVED) @@ -114,6 +112,7 @@ const char *_uam_event_to_str(unsigned int event) CASE_TO_STR(UAM_EVENT_SERVICE_REGISTERED) CASE_TO_STR(UAM_EVENT_SERVICE_UNREGISTERED) CASE_TO_STR(UAM_EVENT_SENSOR_STATUS_CHANGED) + CASE_TO_STR(UAM_EVENT_DAEMON_TERMINATED) default: return "UNKNOWN ERROR"; } diff --git a/ua-daemon/product/ua-manager-common-product.c b/ua-daemon/product/ua-manager-common-product.c index 560be22..e004f64 100644 --- a/ua-daemon/product/ua-manager-common-product.c +++ b/ua-daemon/product/ua-manager-common-product.c @@ -78,8 +78,6 @@ const char *_uam_manager_product_request_to_str(unsigned int req) const char *_uam_manager_product_event_to_str(unsigned int event) { - retv_if(UAM_PRODUCT_EVENT_MAX <= event, NULL); - switch (event) { CASE_TO_STR(UAM_PRODUCT_EVENT_TEST) default: diff --git a/ua-daemon/src/ua-manager-common.c b/ua-daemon/src/ua-manager-common.c index 8e2622b..0edf391 100644 --- a/ua-daemon/src/ua-manager-common.c +++ b/ua-daemon/src/ua-manager-common.c @@ -75,8 +75,6 @@ const char *_uam_manager_request_to_str(unsigned int req) const char *_uam_manager_event_to_str(unsigned int event) { - retv_if(UAM_EVENT_MAX <= event, NULL); - switch (event) { CASE_TO_STR(UAM_EVENT_USER_ADDED) CASE_TO_STR(UAM_EVENT_USER_REMOVED) @@ -97,6 +95,7 @@ const char *_uam_manager_event_to_str(unsigned int event) CASE_TO_STR(UAM_EVENT_SERVICE_REGISTERED) CASE_TO_STR(UAM_EVENT_SERVICE_UNREGISTERED) CASE_TO_STR(UAM_EVENT_SENSOR_STATUS_CHANGED) + CASE_TO_STR(UAM_EVENT_DAEMON_TERMINATED) default: return "UNKNOWN ERROR"; } -- 2.7.4 From bfa397530ec2911f04c70e69a6b399d609bb2b22 Mon Sep 17 00:00:00 2001 From: rohit singh Date: Sun, 16 May 2021 18:51:34 +0530 Subject: [PATCH 08/16] Change implentation for ua_service_add_user Issue: Earlier ua_service_add_user is not having the support for Service -> User -> Device hierarchy structure. Solution: Added implementation to maintain service_user mapping at the daemon side so that whenever a device gets added to user it automatically gets added to the respective service with which the user is mapped to. Change-Id: I4cfca7db3f6e8fa6616d68c0570f86f23838022c Signed-off-by: rohit.singh --- ua-daemon/include/ua-manager-core.h | 5 ++ ua-daemon/src/ua-manager-core.c | 113 +++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index 5fc3d10..a9904f6 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -106,6 +106,11 @@ typedef struct uam_db_device_info { int app_num; /**< Identity of respective app */ } uam_db_device_info_t; +typedef struct uam_svc_user_info { + char* account; /**< Account */ + char* svc_name; /**< Service name */ +} uam_svc_user_info_t; + typedef struct uam_db_user_info { int user_id; /**< User ID */ char *name; /**< User name */ diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index ffad383..ea17f9f 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -49,6 +49,8 @@ static GSList *users; /* List of users - uam_db_user_info_t */ static GSList *devices; /* List of devices - uam_db_device_info_t */ static GSList *services; /* List of services - uam_db_service_info_t */ static GSList *svc_devs; /* List of service device mapping - uam_svc_dev_info_t */ +static GSList *svc_users; /* List of service user mapping - uam_svc_user_info_t */ + static GSList *payloads; /* List of payloads - uam_db_payload_info_t */ static GSList *temp_devices; /* List of devices whichi will be temporary and \ will be cleared in the end of addition \ @@ -184,6 +186,35 @@ static gint __compare_svc_name(gconstpointer data, gconstpointer user_data) return g_strcmp0(service->name, svc_name); } +static gint __compare_svc_user(gconstpointer data, gconstpointer user_data) +{ + const uam_svc_user_info_t *svc_user = data; + const uam_svc_user_info_t *tmp_svc_user = user_data; + + retv_if(NULL == svc_user, -1); + retv_if(NULL == tmp_svc_user, -1); + retv_if(NULL == svc_user->svc_name, -1); + retv_if(NULL == tmp_svc_user->svc_name, -1); + retv_if(NULL == svc_user->account, -1); + retv_if(NULL == tmp_svc_user->account, -1); + + if (g_strcmp0(svc_user->svc_name, tmp_svc_user->svc_name) == 0) + return g_strcmp0(svc_user->account, tmp_svc_user->account); + else + return g_strcmp0(svc_user->svc_name, tmp_svc_user->svc_name); +} + +static gint __compare_svc_user_account(gconstpointer data, gconstpointer user_data) +{ + const uam_svc_user_info_t *svc_user = data; + const char *account = user_data; + + retv_if(NULL == svc_user, -1); + retv_if(NULL == account, -1); + + return g_strcmp0(svc_user->account, account); +} + static gint __compare_payload(gconstpointer data, gconstpointer user_data) { const uam_db_payload_info_t *db_payload = data; @@ -952,6 +983,44 @@ static void _uam_device_match_count(const char *device_id, int tech_type, FUNC_EXIT; } +/* Initial service_user mapping. Here, using user's device list information + * and the service_device mapping, service and user are mapped. + */ +static void __init_svc_user_mapping() +{ + FUNC_ENTRY; + GSList *l, *ll, *tmp; + + for (l = svc_devs; NULL != l; l = g_slist_next(l)) { + + uam_svc_dev_info_t *svc_dev = l->data; + char *device_id = svc_dev->device_id; + + /* Search for devices */ + ll = __search_device(device_id, svc_dev->app_num); + + uam_db_device_info_t *device = ll->data; + uam_db_user_info_t *user_info = device->user; + + if (!user_info) + continue; + + uam_svc_user_info_t *svc_user = g_new0(uam_svc_user_info_t, 1); + + svc_user->svc_name = g_strdup(svc_dev->service); + svc_user->account = g_strdup(user_info->account); + + tmp = g_slist_find_custom(svc_users, svc_user, __compare_svc_user); + if (!tmp) + svc_users = g_slist_prepend(svc_users, svc_user); + else { + free_n_null(&(svc_user->svc_name)); + free_n_null(&(svc_user->account)); + free_n_null(&svc_user); + } + } +} + static int __get_uam_db_dev_list_to_uam_dev_list( GSList *db_dev_list, uam_device_info_s **device_list, int *count, const int app_num) @@ -1504,7 +1573,7 @@ int _uam_core_is_device_added(uam_device_info_s *dev, gboolean *is_added) continue; if (__is_mac_addr(addr->addr_type) && - !strcasecmp(addr->address,dev->mac)) { + !strcasecmp(addr->address, dev->mac)) { *is_added = TRUE; break; } @@ -2259,6 +2328,17 @@ int _uam_core_service_add_user(const char *svc_name, const char *account, const } } + /* Add service to user mapping */ + uam_svc_user_info_t *svc_user = g_new0(uam_svc_user_info_t, 1); + svc_user->svc_name = g_strdup(svc_name); + svc_user->account = g_strdup(account); + + l = g_slist_find_custom(svc_users, svc_user, __compare_svc_user); + if (!l) + svc_users = g_slist_prepend(svc_users, svc_user); + else + UAM_INFO("USER SERVICE MAPPING ALLREADY PRESENT."); + __uam_db_end_transaction(1); FUNC_EXIT; @@ -3045,6 +3125,9 @@ int _uam_core_init(void) } } + /* Update user_service_mapping */ + __init_svc_user_mapping(); + /* Fetch iBeacon adv list */ db_adv_list = _uam_db_get_all_advs(-1); if (!db_adv_list) { @@ -3163,6 +3246,20 @@ void _uam_core_deinit(void) g_slist_free(svc_devs); svc_devs = NULL; + /* Release allocated memory for service users */ + for (l = svc_users; NULL != l; l = g_slist_next(l)) { + uam_svc_user_info_t *svc_user = l->data; + + if (!svc_user) + continue; + + g_free(svc_user->svc_name); + g_free(svc_user->account); + g_free(svc_user); + } + g_slist_free(svc_users); + svc_users = NULL; + /* Release allocated memory for payloads */ for (l = payloads; NULL != l; l = g_slist_next(l)) { uam_db_payload_info_t *payload = l->data; @@ -3346,6 +3443,20 @@ int _uam_core_handle_device_added(int status, __uam_db_end_transaction(0); goto done; } + + /* Add device to user mapped service */ + uam_svc_user_info_t* svc_user = NULL; + + l = g_slist_find_custom(svc_users, user->account, __compare_svc_user_account); + if (!l) + UAM_WARN("User service mapping not found."); + else + svc_user = l->data; + + if (svc_user != NULL && svc_user->svc_name) + _uam_core_service_add_device(svc_user->svc_name, dev_info->device_id, + dev_info->type, dev_info->app_num); + __uam_db_end_transaction(1); /** End database transaction */ -- 2.7.4 From c6e1ff211ff158dc0f2d971224d1ee82b85783cb Mon Sep 17 00:00:00 2001 From: rohit singh Date: Mon, 17 May 2021 17:33:19 +0530 Subject: [PATCH 09/16] Fix for ua_foreach_service Issue: In a scenario when a service is registered and when ua_foreach_service() is called it failed to get the newly registered services though the service got persisted to db. Solution: Logical error fix w.r.t app_num attribute of struct uam_service_info_s at the daemon side solved the issue. Change-Id: I055779441191e9439e66ab715c173f91c16b2817 --- ua-daemon/src/ua-manager-request-handler.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index c1728be..dea0cad 100755 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -927,10 +927,12 @@ static int __uam_manager_sync_request_handler( } case UAM_REQUEST_REGISTER_SERVICE: { uam_service_info_s svc; - svc.app_num = app_num; __uam_manager_copy_params(in_param1, &svc, sizeof(uam_service_info_s)); + + svc.app_num = app_num; + UAM_DBG("Name: [%s] Threshold presence: [%d] absence: [%d]", svc.name, svc.presence_threshold, svc.absence_threshold); result = _uam_core_register_service(&svc, app_num); @@ -939,10 +941,12 @@ static int __uam_manager_sync_request_handler( } case UAM_REQUEST_UPDATE_SERVICE: { uam_service_info_s svc; - svc.app_num = app_num; __uam_manager_copy_params(in_param1, &svc, sizeof(uam_service_info_s)); + + svc.app_num = app_num; + UAM_DBG("Name: [%s] Threshold presence: [%d] absence: [%d]", svc.name, svc.presence_threshold, svc.absence_threshold); -- 2.7.4 From 5cf26dfea4a14c2cab0a2b9ff5fd0acba1ab139b Mon Sep 17 00:00:00 2001 From: rohit singh Date: Thu, 27 May 2021 10:46:12 +0530 Subject: [PATCH 10/16] Modify service-user based API's This patch modifies: 1) ua_service_remove_user 2) adds the app_num attribute support to the service-user hierarchy based API's. Change-Id: I6d080b0356b9fb8a3632c0c09e8f057698673faa Signed-off-by: rohit.singh --- ua-daemon/include/ua-manager-core.h | 1 + ua-daemon/src/ua-manager-core.c | 103 +++++++++++++++++++++++++----------- 2 files changed, 72 insertions(+), 32 deletions(-) diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index a9904f6..d94526e 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -109,6 +109,7 @@ typedef struct uam_db_device_info { typedef struct uam_svc_user_info { char* account; /**< Account */ char* svc_name; /**< Service name */ + int app_num; /**< Identity of respective app */ } uam_svc_user_info_t; typedef struct uam_db_user_info { diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index ea17f9f..e85edd7 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -199,20 +199,26 @@ static gint __compare_svc_user(gconstpointer data, gconstpointer user_data) retv_if(NULL == tmp_svc_user->account, -1); if (g_strcmp0(svc_user->svc_name, tmp_svc_user->svc_name) == 0) - return g_strcmp0(svc_user->account, tmp_svc_user->account); + if (g_strcmp0(svc_user->account, tmp_svc_user->account) == 0) + return svc_user->app_num == tmp_svc_user->app_num ? 0 : -1; + else + return -1; else - return g_strcmp0(svc_user->svc_name, tmp_svc_user->svc_name); + return -1; } static gint __compare_svc_user_account(gconstpointer data, gconstpointer user_data) { const uam_svc_user_info_t *svc_user = data; - const char *account = user_data; + const uam_db_user_info_t *user = user_data; retv_if(NULL == svc_user, -1); - retv_if(NULL == account, -1); + retv_if(NULL == user, -1); - return g_strcmp0(svc_user->account, account); + if (g_strcmp0(svc_user->account, user->account) == 0) + return svc_user->app_num == user->app_num ? 0 : -1; + else + return -1; } static gint __compare_payload(gconstpointer data, gconstpointer user_data) @@ -596,6 +602,26 @@ GSList* __search_user(const char *account, int app_num) return l; } +GSList* __search_svc_user(const char* svc_name, const char* account, int app_num) +{ + GSList* l; + + uam_svc_user_info_t *svc_user; + + svc_user = g_new0(uam_svc_user_info_t, 1); + svc_user->svc_name = g_strdup(svc_name); + svc_user->account = g_strdup(account); + svc_user->app_num = app_num; + + l = g_slist_find_custom(svc_users, svc_user, __compare_svc_user); + + free_n_null(&(svc_user->svc_name)); + free_n_null(&(svc_user->account)); + free_n_null(&svc_user); + + return l; +} + GSList* __search_device(const char *device_id, int app_num) { /* Search device in existing device list */ @@ -1005,18 +1031,15 @@ static void __init_svc_user_mapping() if (!user_info) continue; - uam_svc_user_info_t *svc_user = g_new0(uam_svc_user_info_t, 1); + tmp = __search_svc_user(svc_dev->service, user_info->account, svc_dev->app_num); + if (!tmp) { - svc_user->svc_name = g_strdup(svc_dev->service); - svc_user->account = g_strdup(user_info->account); + uam_svc_user_info_t *svc_user = g_new0(uam_svc_user_info_t, 1); + svc_user->svc_name = g_strdup(svc_dev->service); + svc_user->account = g_strdup(user_info->account); + svc_user->app_num = svc_dev->app_num; - tmp = g_slist_find_custom(svc_users, svc_user, __compare_svc_user); - if (!tmp) svc_users = g_slist_prepend(svc_users, svc_user); - else { - free_n_null(&(svc_user->svc_name)); - free_n_null(&(svc_user->account)); - free_n_null(&svc_user); } } } @@ -2328,19 +2351,22 @@ int _uam_core_service_add_user(const char *svc_name, const char *account, const } } + __uam_db_end_transaction(1); + /* Add service to user mapping */ - uam_svc_user_info_t *svc_user = g_new0(uam_svc_user_info_t, 1); - svc_user->svc_name = g_strdup(svc_name); - svc_user->account = g_strdup(account); + l = __search_svc_user(svc_name, account, app_num); + + if (!l) { + uam_svc_user_info_t *svc_user = g_new0(uam_svc_user_info_t, 1); + svc_user->svc_name = g_strdup(svc_name); + svc_user->account = g_strdup(account); + svc_user->app_num = app_num; - l = g_slist_find_custom(svc_users, svc_user, __compare_svc_user); - if (!l) svc_users = g_slist_prepend(svc_users, svc_user); + } else UAM_INFO("USER SERVICE MAPPING ALLREADY PRESENT."); - __uam_db_end_transaction(1); - FUNC_EXIT; return ret; } @@ -2402,8 +2428,21 @@ int _uam_core_service_remove_user(const char *svc_name, const char *account, con } } } + __uam_db_end_transaction(1); + /* Removne service-user mapping from svc_users */ + + l = __search_svc_user(svc_name, account, app_num); + retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); + + uam_svc_user_info_t *svc_user = l->data; + svc_users = g_slist_remove_all(svc_users, svc_user); + + g_free(svc_user->svc_name); + g_free(svc_user->account); + g_free(svc_user); + FUNC_EXIT; return UAM_ERROR_NONE; } @@ -3247,18 +3286,18 @@ void _uam_core_deinit(void) svc_devs = NULL; /* Release allocated memory for service users */ - for (l = svc_users; NULL != l; l = g_slist_next(l)) { - uam_svc_user_info_t *svc_user = l->data; + for (l = svc_users; NULL != l; l = g_slist_next(l)) { + uam_svc_user_info_t *svc_user = l->data; - if (!svc_user) - continue; + if (!svc_user) + continue; - g_free(svc_user->svc_name); - g_free(svc_user->account); - g_free(svc_user); - } - g_slist_free(svc_users); - svc_users = NULL; + g_free(svc_user->svc_name); + g_free(svc_user->account); + g_free(svc_user); + } + g_slist_free(svc_users); + svc_users = NULL; /* Release allocated memory for payloads */ for (l = payloads; NULL != l; l = g_slist_next(l)) { @@ -3447,7 +3486,7 @@ int _uam_core_handle_device_added(int status, /* Add device to user mapped service */ uam_svc_user_info_t* svc_user = NULL; - l = g_slist_find_custom(svc_users, user->account, __compare_svc_user_account); + l = g_slist_find_custom(svc_users, user, __compare_svc_user_account); if (!l) UAM_WARN("User service mapping not found."); else -- 2.7.4 From 0972ec0d4cb1c286a6e21751264da20ac6733478 Mon Sep 17 00:00:00 2001 From: rohit singh Date: Mon, 31 May 2021 16:02:41 +0530 Subject: [PATCH 11/16] Fix style issues This patches fixes the styles issues as shown in the check-patch script. Change-Id: Iccf3afcab19debd2850b5d8fd1a3250ee894a36d Signed-off-by: rohit.singh --- ua-api/src/ua-event-handler.c | 2 +- ua-daemon/src/ua-manager-core.c | 19 ++++++++----------- ua-daemon/src/ua-manager-main.c | 16 ++++++++-------- ua-daemon/src/ua-manager-request-handler.c | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/ua-api/src/ua-event-handler.c b/ua-api/src/ua-event-handler.c index e035209..7a19c87 100644 --- a/ua-api/src/ua-event-handler.c +++ b/ua-api/src/ua-event-handler.c @@ -417,7 +417,7 @@ void _uam_register_name_owner_changed(void) return; } - if(owner_sig_id != 0) + if (owner_sig_id != 0) return; owner_sig_id = g_dbus_connection_signal_subscribe(conn, diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index e85edd7..22ea76b 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -2228,9 +2228,8 @@ static int _uam_core_update_svc_dev_info(const char *device_id, uam_tech_type_e svc->service = g_strdup(svc_name); svc->payload = g_new0(uam_db_payload_info_t, 1); - if (payload_info) { + if (payload_info) __uam_copy_uam_payload_info(svc->payload, payload_info); - } svc_devs = g_slist_append(svc_devs, svc); } @@ -2240,10 +2239,9 @@ static int _uam_core_update_svc_dev_info(const char *device_id, uam_tech_type_e if (last_seen > 0) svc->last_seen = last_seen; - if (payload_info) { - /* TODO free existing payload structure */ + /* TODO free existing payload structure */ + if (payload_info) __uam_copy_uam_payload_info(svc->payload, payload_info); - } UAM_DBG("Service [%s] device [%s] tech_type [%d] discriminant [%d] " \ "last_seen [%llu] payload primary key [%d] app number [%d]", @@ -2809,9 +2807,9 @@ static int __uam_core_start_detection(int detection_type, retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER); l = g_slist_find_custom(services, svc_name, __compare_svc_name); - if (!l) { + if (!l) UAM_ERR("Service not found"); - } + retv_if(NULL == l, UAM_ERROR_NOT_FOUND); retv_if(NULL == l->data, UAM_ERROR_INTERNAL); @@ -3432,11 +3430,10 @@ int _uam_core_handle_device_added(int status, __get_default_service_name(dev_info->app_num, &default_service_name); l = g_slist_find_custom(services, default_service_name, __compare_svc_name); - if (!l) { + if (!l) UAM_WARN("Default service not found"); - } else { + else service = l->data; - } /** updates for svc dev*/ ret = _uam_core_update_svc_dev_info(dev_info->device_id, dev_info->type, @@ -3760,7 +3757,7 @@ static int __uam_core_update_device_addr(uam_db_address_info_t *addr, retv_if(!addr, UAM_ERROR_INVALID_PARAMETER); retv_if(!dev_info, UAM_ERROR_INVALID_PARAMETER); - switch(addr->addr_type) { + switch (addr->addr_type) { case UAM_ADDR_TYPE_IPv4: if (strcasecmp(addr->address, dev_info->ipv4_addr)) { UAM_DBG("Old IPv4: %s, New IPv4: %s", diff --git a/ua-daemon/src/ua-manager-main.c b/ua-daemon/src/ua-manager-main.c index 3e1e03e..523baea 100644 --- a/ua-daemon/src/ua-manager-main.c +++ b/ua-daemon/src/ua-manager-main.c @@ -50,20 +50,20 @@ static void __uam_manager_cleanup(void) static gboolean __uam_manager_terminate_idle_cb(gpointer user_data) { - FUNC_ENTRY; + FUNC_ENTRY; - __uam_manager_cleanup(); + __uam_manager_cleanup(); - UAM_INFO("Quit g_main loop"); + UAM_INFO("Quit g_main loop"); - if (main_loop) - g_main_loop_quit(main_loop); + if (main_loop) + g_main_loop_quit(main_loop); - UAM_INFO("ua-manager terminated"); + UAM_INFO("ua-manager terminated"); - FUNC_EXIT; + FUNC_EXIT; - return FALSE; + return FALSE; } void _uam_manager_terminate(void) diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index dea0cad..e15b65b 100755 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -1393,7 +1393,7 @@ static unsigned int __uam_manager_get_device_type( break; } - default : + default: device_type = 0; break; } -- 2.7.4 From 2e0ce8fa25bb2a4074c164d89cd45710aa7f6dfd Mon Sep 17 00:00:00 2001 From: rohit singh Date: Mon, 7 Jun 2021 17:30:57 +0530 Subject: [PATCH 12/16] Modify ua_service_foreach_users This patch modifies ua_service_foreach_users based on service->user->device hierarchy. Change-Id: I31ac658cc553ffa3e98ab26f57ab5c8b08ca2ed1 Signed-off-by: rohit.singh --- ua-daemon/src/ua-manager-core.c | 49 ++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 22ea76b..7a58c30 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -4669,25 +4669,24 @@ int _uam_core_get_service_devices(const char *svc_name, } static void __get_service_user_list( - uam_db_service_info_t* service, uam_user_info_s **user_list, int *count) + const char* svc_name, uam_user_info_s **user_list, int *count, const int app_num) { FUNC_ENTRY; - GSList *l; + GSList *l, *ll; int indx = 0; GSList *svc_user_list = NULL; *count = 0; /* Calculate number of users */ - for (l = service->dev_techs; NULL != l; l = g_slist_next(l)) { - uam_db_tech_info_t *tech = l->data; - if (!tech || !tech->addresses) + for (l = svc_users; NULL != l; l = g_slist_next(l)) { + uam_svc_user_info_t *svc_user = l->data; + if (!svc_user || !svc_user->svc_name || !svc_user->account) continue; - GSList *l1; - uam_db_user_info_t *db_info = tech->device->user; - l1 = g_slist_find_custom(svc_user_list , db_info->account, __compare_user_account); - if (NULL == l1) - svc_user_list = g_slist_append(svc_user_list, db_info); + if (g_strcmp0(svc_user->svc_name, svc_name) == 0) + if (svc_user->app_num == app_num) + svc_user_list = g_slist_append(svc_user_list, svc_user); + } *count = g_slist_length(svc_user_list); @@ -4695,16 +4694,26 @@ static void __get_service_user_list( /* Copy users */ for (l = svc_user_list; l; l = g_slist_next(l)) { - uam_db_user_info_t *db_info = l->data; + uam_svc_user_info_t *svc_user = l->data; + uam_db_user_info_t *user; - if (!db_info || !db_info->account) + if (!svc_user || !svc_user->svc_name || !svc_user->account) + continue; + + /* Retrieve user from list */ + ll = __search_user(svc_user->account, app_num); + if (NULL == ll) continue; + user = ll->data; + g_strlcpy((*user_list)[indx].account, - db_info->account, UAM_USER_ACCOUNT_MAX_STRING_LEN); - if (db_info->name) - g_strlcpy((*user_list)[indx].name, - db_info->name, UAM_USER_NAME_MAX_STRING_LEN); + svc_user->account, UAM_USER_ACCOUNT_MAX_STRING_LEN); + + g_strlcpy((*user_list)[indx].name, + user->name, UAM_USER_NAME_MAX_STRING_LEN); + + (*user_list)[indx].app_num = app_num; indx += 1; } @@ -4717,14 +4726,8 @@ int _uam_core_get_service_users(const char *svc_name, int *count, uam_user_info_s **user_list, const int app_num) { FUNC_ENTRY; - uam_db_service_info_t *service; - GSList *l; - - l = g_slist_find_custom(services, svc_name, __compare_svc_name); - retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); - service = l->data; - __get_service_user_list(service, user_list, count); + __get_service_user_list(svc_name, user_list, count, app_num); FUNC_EXIT; return UAM_ERROR_NONE; -- 2.7.4 From a21c3e2d971385ab2d9fe811bf7fd88df6f9f40d Mon Sep 17 00:00:00 2001 From: rohit singh Date: Wed, 9 Jun 2021 16:08:47 +0530 Subject: [PATCH 13/16] Fix derefencing of null pointer issue Return value of a function '__search_device' is dereferenced inside __init_svc_user_mapping() function. Change-Id: Ibeb9cdc49dc5fdfa8c94f036dca5c6802c0929eb Signed-off-by: rohit.singh --- ua-daemon/src/ua-manager-core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 7a58c30..6195c78 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -1024,6 +1024,8 @@ static void __init_svc_user_mapping() /* Search for devices */ ll = __search_device(device_id, svc_dev->app_num); + if (NULL == ll) + continue; uam_db_device_info_t *device = ll->data; uam_db_user_info_t *user_info = device->user; -- 2.7.4 From 3555f2a32b5e2dc30892d58674fb9d3227fc9ba5 Mon Sep 17 00:00:00 2001 From: rohit singh Date: Mon, 14 Jun 2021 16:35:39 +0530 Subject: [PATCH 14/16] Add multi-application support for service api's This patch adds the multi-applcation support for service based api's and methods. Change-Id: I21f73c208825161d547f052eb2eebfd4c37c1c21 Signed-off-by: rohit.singh --- ua-daemon/include/ua-manager-core.h | 8 +- ua-daemon/src/ua-manager-core.c | 125 ++++++++++++++++++----------- ua-daemon/src/ua-manager-request-handler.c | 8 +- 3 files changed, 87 insertions(+), 54 deletions(-) diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index d94526e..b3970fd 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -190,16 +190,16 @@ int _uam_core_set_detection_threshold(unsigned int sensor, int presence_threshold, int absence_threshold); int _uam_core_start_presence_detection(const char *svc_name, char *sender, - unsigned int sensors); + unsigned int sensors, int app_num); int _uam_core_stop_presence_detection(const char *svc_name, char *sender, - unsigned int sensors); + unsigned int sensors, int app_num); int _uam_core_start_absence_detection(const char *svc_name, char *sender, - unsigned int sensors); + unsigned int sensors, int app_num); int _uam_core_stop_absence_detection(const char *svc_name, char *sender, - unsigned int sensors); + unsigned int sensors, int app_num); int _uam_core_set_low_power_mode(unsigned int bit_mask, gboolean mode); diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 6195c78..75d1685 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -174,16 +174,20 @@ static gint __compare_user_id(gconstpointer data, gconstpointer user_data) return 0; } -static gint __compare_svc_name(gconstpointer data, gconstpointer user_data) +static gint __compare_service(gconstpointer data, gconstpointer user_data) { const uam_db_service_info_t *service = data; - const char *svc_name = user_data; + const uam_db_service_info_t *tmp = user_data; retv_if(NULL == service, -1); retv_if(NULL == service->name, -1); - retv_if(NULL == svc_name, -1); + retv_if(NULL == tmp, -1); + retv_if(NULL == tmp->name, -1); - return g_strcmp0(service->name, svc_name); + if (service->app_num == tmp->app_num) + return g_strcmp0(service->name, tmp->name); + else + return -1; } static gint __compare_svc_user(gconstpointer data, gconstpointer user_data) @@ -584,6 +588,24 @@ static void __uam_copy_db_service_info( } /* Utility functions to search */ +GSList* __search_service(GSList* list, const char *svc_name, int app_num) +{ + /* Search user in existing user list */ + GSList *l; + uam_db_service_info_t *temp_svc; + + temp_svc = g_new0(uam_db_service_info_t, 1); + temp_svc->name = g_strdup(svc_name); + temp_svc->app_num = app_num; + + l = g_slist_find_custom(list, temp_svc, __compare_service); + + g_free(temp_svc->name); + g_free(temp_svc); + + return l; +} + GSList* __search_user(const char *account, int app_num) { /* Search user in existing user list */ @@ -671,7 +693,7 @@ static char *__get_mac_addr(uam_db_tech_info_t *tech) } static uam_monitor_info_t *__uam_find_monitor(GSList *monitor_list, - const char *name, const char *svc_name, uam_pm_detection_mode_e mode) + const char *name, const char *svc_name, uam_pm_detection_mode_e mode, const int app_num) { // FUNC_ENTRY; GSList *l; @@ -688,7 +710,8 @@ static uam_monitor_info_t *__uam_find_monitor(GSList *monitor_list, if ((mode == monitor->mode) && (0 == g_strcmp0(monitor->name, name)) && - (0 == g_strcmp0(monitor->service->name, svc_name))) { + (0 == g_strcmp0(monitor->service->name, svc_name)) && + (monitor->service->app_num == app_num)) { UAM_DBG("Monitoring application found in list"); return monitor; } @@ -1233,19 +1256,19 @@ static GSList *__convert_db_svc_list_to_uam_svc_list(GSList *db_svc_list) for (l = db_svc_list; NULL != l; l = g_slist_next(l)) { db_service_info_t *db_svc = l->data; uam_db_service_info_t *service; - GSList *l1; + GSList *ll; if (!db_svc) continue; - l1 = g_slist_find_custom(services, - db_svc->service_name, __compare_svc_name); - if (!l1) { + ll = __search_service(services, db_svc->service_name, db_svc->app_num); + + if (!ll) { service = g_new0(uam_db_service_info_t, 1); __uam_copy_db_service_info(service, db_svc); services = g_slist_append(services, service); } else - service = l1->data; + service = ll->data; svc_list = g_slist_append(svc_list, service); } @@ -2301,7 +2324,7 @@ int _uam_core_service_add_user(const char *svc_name, const char *account, const user = l->data; /* Retrieve service from list */ - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); service = l->data; @@ -2322,8 +2345,7 @@ int _uam_core_service_add_user(const char *svc_name, const char *account, const if (!tech) continue; - l2 = g_slist_find_custom(tech->svc_list, svc_name, - __compare_svc_name); + l2 = __search_service(tech->svc_list, svc_name, app_num); if (NULL != l2) continue; @@ -2389,7 +2411,7 @@ int _uam_core_service_remove_user(const char *svc_name, const char *account, con user = l->data; /* Retrieve service from list */ - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); retv_if(UAM_ERROR_NONE != __uam_db_begin_transaction(), UAM_ERROR_DB_FAILED); @@ -2408,8 +2430,7 @@ int _uam_core_service_remove_user(const char *svc_name, const char *account, con if (!tech) continue; - l2 = g_slist_find_custom(tech->svc_list, svc_name, - __compare_svc_name); + l2 = __search_service(tech->svc_list, svc_name, app_num); if (NULL == l2) continue; @@ -2507,11 +2528,11 @@ int _uam_core_service_add_device(const char *svc_name, const char *device_id, tech_info = __uam_core_get_dev_tech_info(device_id, tech_type); retv_if(NULL == tech_info, UAM_ERROR_INVALID_PARAMETER); - l = g_slist_find_custom(tech_info->svc_list, svc_name, __compare_svc_name); + l = __search_service(tech_info->svc_list, svc_name, app_num); retv_if(NULL != l, UAM_ERROR_ALREADY_REGISTERED); /* Retrieve service from list */ - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); service = l->data; @@ -2557,13 +2578,13 @@ int _uam_core_service_remove_device(const char *svc_name, retv_if(UAM_TECH_TYPE_MAX <= tech_type, UAM_ERROR_INVALID_PARAMETER); /* Retrieve service from list */ - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); tech_info = __uam_core_get_dev_tech_info(device_id, tech_type); retv_if(NULL == tech_info, UAM_ERROR_INVALID_PARAMETER); - l = g_slist_find_custom(tech_info->svc_list, svc_name, __compare_svc_name); + l = __search_service(tech_info->svc_list, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_NOT_REGISTERED); __remove_service_to_dev_tech_mapping(tech_info, (uam_db_service_info_t *)l->data); @@ -2600,7 +2621,7 @@ int _uam_core_service_set_device_discriminant(const char *svc_name, retv_if(NULL == tech_info, UAM_ERROR_INVALID_PARAMETER); /* Retrieve service from list */ - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); service = l->data; @@ -2672,7 +2693,7 @@ int _uam_core_set_service_detection_cycle(const char *svc_name, unsigned int new retv_if(UAM_DETECTION_CYCLE_MIN > new_cycle, UAM_ERROR_INVALID_PARAMETER); retv_if(0 != (new_cycle % UAM_DETECTION_CYCLE_MIN), UAM_ERROR_INVALID_PARAMETER); - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); service = l->data; @@ -2704,7 +2725,7 @@ int _uam_core_get_service_detection_cycle(const char *svc_name, unsigned int *cy retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER); retv_if(NULL == cycle, UAM_ERROR_INVALID_PARAMETER); - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); service = l->data; @@ -2797,7 +2818,7 @@ done: } static int __uam_core_start_detection(int detection_type, - const char *svc_name, char *sender, unsigned int sensors) + const char *svc_name, char *sender, unsigned int sensors, int app_num) { FUNC_ENTRY; uam_monitor_info_t *monitor; @@ -2808,7 +2829,7 @@ static int __uam_core_start_detection(int detection_type, retv_if(NULL == sender, UAM_ERROR_INVALID_PARAMETER); retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER); - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); if (!l) UAM_ERR("Service not found"); @@ -2816,7 +2837,7 @@ static int __uam_core_start_detection(int detection_type, retv_if(NULL == l->data, UAM_ERROR_INTERNAL); service = l->data; - monitor = __uam_find_monitor(monitors, sender, svc_name, detection_type); + monitor = __uam_find_monitor(monitors, sender, svc_name, detection_type, app_num); if (!monitor) { monitor = g_malloc0(sizeof(uam_monitor_info_t)); if (monitor) { @@ -2830,7 +2851,8 @@ static int __uam_core_start_detection(int detection_type, } } - UAM_DBG("Name: %s, Service: %s, Mode: %d", monitor->name, svc_name, monitor->mode); + UAM_DBG("Name: %s, Service: %s, Mode: %d, App_num: %d", monitor->name, svc_name, + monitor->mode, app_num); monitor->sensors |= sensors; if (!is_monitor_added) { @@ -2851,7 +2873,7 @@ static int __uam_core_start_detection(int detection_type, } static int __uam_core_stop_detection(int detection_type, - const char *svc_name, char *sender, unsigned int sensors) + const char *svc_name, char *sender, unsigned int sensors, int app_num) { FUNC_ENTRY; int ret = UAM_ERROR_NONE; @@ -2863,7 +2885,7 @@ static int __uam_core_stop_detection(int detection_type, retv_if(NULL == sender, UAM_ERROR_INVALID_PARAMETER); retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER); - monitor = __uam_find_monitor(monitors, sender, svc_name, detection_type); + monitor = __uam_find_monitor(monitors, sender, svc_name, detection_type, app_num); retv_if(NULL == monitor, UAM_ERROR_NOT_IN_OPERATION); service = monitor->service; retv_if(0 != g_strcmp0(service->name, svc_name), UAM_ERROR_NOT_IN_OPERATION); @@ -2917,45 +2939,53 @@ static int __uam_core_stop_detection(int detection_type, return ret; } -int _uam_core_start_presence_detection(const char *svc_name, char *sender, unsigned int sensors) +int _uam_core_start_presence_detection(const char *svc_name, char *sender, + unsigned int sensors, int app_num) { FUNC_ENTRY; int ret; - ret = __uam_core_start_detection(UAM_DETECT_PRESENCE, svc_name, sender, sensors); + ret = __uam_core_start_detection(UAM_DETECT_PRESENCE, svc_name, + sender, sensors, app_num); FUNC_EXIT; return ret; } -int _uam_core_stop_presence_detection(const char *svc_name, char *sender, unsigned int sensors) +int _uam_core_stop_presence_detection(const char *svc_name, char *sender, + unsigned int sensors, int app_num) { FUNC_ENTRY; int ret; - ret = __uam_core_stop_detection(UAM_DETECT_PRESENCE, svc_name, sender, sensors); + ret = __uam_core_stop_detection(UAM_DETECT_PRESENCE, svc_name, + sender, sensors, app_num); FUNC_EXIT; return ret; } -int _uam_core_start_absence_detection(const char *svc_name, char *sender, unsigned int sensors) +int _uam_core_start_absence_detection(const char *svc_name, char *sender, + unsigned int sensors, int app_num) { FUNC_ENTRY; int ret; - ret = __uam_core_start_detection(UAM_DETECT_ABSENCE, svc_name, sender, sensors); + ret = __uam_core_start_detection(UAM_DETECT_ABSENCE, svc_name, sender, + sensors, app_num); FUNC_EXIT; return ret; } -int _uam_core_stop_absence_detection(const char *svc_name, char *sender, unsigned int sensors) +int _uam_core_stop_absence_detection(const char *svc_name, char *sender, + unsigned int sensors, int app_num) { FUNC_ENTRY; int ret; - ret = __uam_core_stop_detection(UAM_DETECT_ABSENCE, svc_name, sender, sensors); + ret = __uam_core_stop_detection(UAM_DETECT_ABSENCE, svc_name, sender, + sensors, app_num); FUNC_EXIT; return ret; @@ -3431,7 +3461,7 @@ int _uam_core_handle_device_added(int status, /* Get default service */ __get_default_service_name(dev_info->app_num, &default_service_name); - l = g_slist_find_custom(services, default_service_name, __compare_svc_name); + l = __search_service(services, default_service_name, dev_info->app_num); if (!l) UAM_WARN("Default service not found"); else @@ -4130,7 +4160,7 @@ void _uam_core_cleanup_monitor(char *name) * and free the monitor structure in the memory. */ UAM_INFO("clear %s's monitor info.", monitor->name); __uam_core_stop_detection(monitor->mode, - monitor->service->name, name, monitor->sensors); + monitor->service->name, name, monitor->sensors, monitor->service->app_num); } } @@ -4445,7 +4475,10 @@ int _uam_core_register_service(uam_service_info_s *svc, const int app_num) retv_if(NULL == svc->name, UAM_ERROR_INVALID_PARAMETER); /* Retrieve service from list */ - l = g_slist_find_custom(services, svc->name, __compare_svc_name); + UAM_INFO("Registering for : service name->[%s] and app_num->[%d]", + svc->name, app_num); + + l = __search_service(services, svc->name, app_num); retv_if((NULL != l) && (l->data != NULL), UAM_ERROR_ALREADY_REGISTERED); service = g_new0(uam_db_service_info_t, 1); @@ -4482,7 +4515,7 @@ int _uam_core_update_service(uam_service_info_s *svc) retv_if(NULL == svc->name, UAM_ERROR_INVALID_PARAMETER); /* Retrieve service from list */ - l = g_slist_find_custom(services, svc->name, __compare_svc_name); + l = __search_service(services, svc->name, svc->app_num); retv_if((NULL == l) || (l->data == NULL), UAM_ERROR_NOT_REGISTERED); service = l->data; @@ -4515,7 +4548,7 @@ int _uam_core_get_default_service(uam_service_info_s *service_info, __get_default_service_name(app_num, &default_service_name); UAM_DBG("default_service_name is [%s]", default_service_name); - l = g_slist_find_custom(services, default_service_name, __compare_svc_name); + l = __search_service(services, default_service_name, app_num); if (NULL == l) { /* Register default service */ memset(service_info, 0x00, sizeof(uam_service_info_s)); @@ -4550,7 +4583,7 @@ int _uam_core_unregister_service(const char *svc_name, const int app_num) retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER); /* Retrieve service from list */ - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if((NULL == l), UAM_ERROR_NOT_REGISTERED); service = l->data; @@ -4660,7 +4693,7 @@ int _uam_core_get_service_devices(const char *svc_name, GSList *l; int ret = UAM_ERROR_NONE; - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); service = l->data; @@ -4863,7 +4896,7 @@ int _uam_core_service_add_payload(uam_ble_payload_s *payload, retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER); /* Retrieve service from list */ - l = g_slist_find_custom(services, svc_name, __compare_svc_name); + l = __search_service(services, svc_name, app_num); retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER); service = l->data; diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index e15b65b..9a6cc7b 100755 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -679,7 +679,7 @@ static int __uam_manager_sync_request_handler( &sensors, sizeof(unsigned int)); svc_name = (char *)g_variant_get_data(in_param2); - result = _uam_core_start_presence_detection(svc_name, sender, sensors); + result = _uam_core_start_presence_detection(svc_name, sender, sensors, app_num); break; } case UAM_REQUEST_STOP_PRESENCE_DETECTION: { @@ -690,7 +690,7 @@ static int __uam_manager_sync_request_handler( &sensors, sizeof(unsigned int)); svc_name = (char *)g_variant_get_data(in_param2); - result = _uam_core_stop_presence_detection(svc_name, sender, sensors); + result = _uam_core_stop_presence_detection(svc_name, sender, sensors, app_num); break; } case UAM_REQUEST_START_ABSENCE_DETECTION: { @@ -701,7 +701,7 @@ static int __uam_manager_sync_request_handler( &sensors, sizeof(unsigned int)); svc_name = (char *)g_variant_get_data(in_param2); - result = _uam_core_start_absence_detection(svc_name, sender, sensors); + result = _uam_core_start_absence_detection(svc_name, sender, sensors, app_num); break; } case UAM_REQUEST_STOP_ABSENCE_DETECTION: { @@ -712,7 +712,7 @@ static int __uam_manager_sync_request_handler( &sensors, sizeof(unsigned int)); svc_name = (char *)g_variant_get_data(in_param2); - result = _uam_core_stop_absence_detection(svc_name, sender, sensors); + result = _uam_core_stop_absence_detection(svc_name, sender, sensors, app_num); break; } case UAM_REQUEST_SET_LOW_POWER_MODE: { -- 2.7.4 From 9d0094dbd287330f8b3f5eadb533861740b7f0e0 Mon Sep 17 00:00:00 2001 From: Abhay Agarwal Date: Wed, 6 Jan 2021 15:18:46 +0530 Subject: [PATCH 15/16] Add wifi location plugin support This patch updates the enums, convert functions to support wifi-location plugin. Change-Id: I7f8d398708d5d6c4559d7f4d4c0fedd7ca6af6ee Signed-off-by: Abhay Agarwal --- include/ua-api.h | 4 +++- ua-daemon/src/pm/ua-plugin-handler.c | 3 ++- ua-daemon/src/pm/ua-plugin-manager.c | 11 ++++++---- ua-daemon/src/pm/ua-pm-util.c | 42 ++++++++++++++++++++++-------------- ua-daemon/src/ua-manager-core.c | 8 ++++++- ua-plugins/include/ua-plugin.h | 1 + 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index 8ac4301..25323e0 100755 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -39,7 +39,8 @@ typedef enum { UAM_SENSOR_BITMASK_WIFI = 0x00000004, /**< Bitmask for Wi-Fi */ UAM_SENSOR_BITMASK_MOTION = 0x00000008, /**< Bitmask for motion */ UAM_SENSOR_BITMASK_LIGHT = 0x00000010, /**< Bitmask for light */ - UAM_SENSOR_BITMASK_AUDIO = 0x00000020, /**< Bitmask for autio */ + UAM_SENSOR_BITMASK_AUDIO = 0x00000020, /**< Bitmask for audio */ + UAM_SENSOR_BITMASK_WIFI_LOCATION = 0x00000040, /**< Bitmask for wifi location */ UAM_SENSOR_ALL = 0xFFFFFFFF, /**< Bitmask for all sensors */ } uam_sensor_bitmask_e; @@ -489,6 +490,7 @@ typedef enum { UAM_TECH_TYPE_BLE = 0x02, /**< BLE */ UAM_TECH_TYPE_WIFI = 0x04, /**< Wi-Fi */ UAM_TECH_TYPE_P2P = 0x08, /**< Wi-Fi p2p */ + UAM_TECH_TYPE_WIFI_LOCATION = 0x10, /**< Wi-Fi location */ UAM_TECH_TYPE_MAX /**< Max. connectivity type */ } uam_tech_type_e; diff --git a/ua-daemon/src/pm/ua-plugin-handler.c b/ua-daemon/src/pm/ua-plugin-handler.c index a5151ad..47acfa1 100644 --- a/ua-daemon/src/pm/ua-plugin-handler.c +++ b/ua-daemon/src/pm/ua-plugin-handler.c @@ -135,6 +135,7 @@ static void device_detected_callback(int id, dev_info = _pm_util_uas_dev_info_to_uam_dev_info(device); ret_if(NULL == dev_info); + dev_info->type = _pm_util_uas_plugin_id_to_tech_type(id); if (device->payload) { payload = g_new0(uam_ble_payload_s, 1); @@ -210,7 +211,7 @@ static void device_active_scan_callback(int id, dev_info = _pm_util_uas_dev_info_to_uam_dev_info(device); ret_if(NULL == dev_info); - dev_info->type = UAM_TECH_TYPE_WIFI; + dev_info->type = _pm_util_uas_plugin_id_to_tech_type(id); } event_info = _pm_util_uas_scan_event_to_uam_scan_event(event); diff --git a/ua-daemon/src/pm/ua-plugin-manager.c b/ua-daemon/src/pm/ua-plugin-manager.c index 1eb9240..8af601b 100644 --- a/ua-daemon/src/pm/ua-plugin-manager.c +++ b/ua-daemon/src/pm/ua-plugin-manager.c @@ -483,26 +483,29 @@ int _uam_pm_set_registered_devices(GSList *devices, unsigned int bitmask) { FUNC_ENTRY; int id; - uas_device_info_t *dev_list = NULL; - int num_devices = 0; for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) { + uas_device_info_t *dev_list = NULL; + int num_devices = 0; uam_sensor_plugin_info_t *plugin = plugins[id]; unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id); if (!(sensor & bitmask)) continue; - if (!plugin || !plugin->api) + if (!plugin || !plugin->api || !plugin->api->set_registered_devices) continue; if (UAS_SUPPORT_USER != plugin->capability) continue; dev_list = __get_uas_device_list(id, devices, &num_devices); - if (!dev_list) + if (!dev_list) { UAM_INFO("No devices for Plugin %d", id); + continue; + } + UAM_INFO("set registered devices"); if (UAS_STATUS_SUCCESS != plugin->api->set_registered_devices( num_devices, dev_list)) UAM_ERR("plugin->set_registered_devices() failed for %d", id); diff --git a/ua-daemon/src/pm/ua-pm-util.c b/ua-daemon/src/pm/ua-pm-util.c index 0db6427..3a107e8 100644 --- a/ua-daemon/src/pm/ua-pm-util.c +++ b/ua-daemon/src/pm/ua-pm-util.c @@ -48,6 +48,8 @@ unsigned int _pm_util_uas_plugin_id_to_sensor_bitmask(uas_plugin_id_e id) return UAM_SENSOR_BITMASK_LIGHT; case UAS_PLUGIN_ID_MOTION: return UAM_SENSOR_BITMASK_MOTION; + case UAS_PLUGIN_ID_WIFI_LOCATION: + return UAM_SENSOR_BITMASK_WIFI_LOCATION; default: UAM_WARN("Unknown Plugin id 0x%8.8X", id); return 0; @@ -61,6 +63,8 @@ unsigned int _pm_util_uam_tech_type_to_plugin_id(uam_tech_type_e type) return UAS_PLUGIN_ID_BLE; case UAM_TECH_TYPE_WIFI: return UAS_PLUGIN_ID_WIFI; + case UAM_TECH_TYPE_WIFI_LOCATION: + return UAS_PLUGIN_ID_WIFI_LOCATION; default: UAM_WARN("Unknown type 0x%8.8X", type); return UAS_PLUGIN_ID_MAX; @@ -74,6 +78,8 @@ unsigned int _pm_util_uas_plugin_id_to_tech_type(uas_plugin_id_e id) return UAM_TECH_TYPE_BLE; case UAS_PLUGIN_ID_WIFI: return UAM_TECH_TYPE_WIFI; + case UAS_PLUGIN_ID_WIFI_LOCATION: + return UAM_TECH_TYPE_WIFI_LOCATION; default: UAM_WARN("Unknown Plugin id 0x%8.8X", id); return UAM_TECH_TYPE_NONE; @@ -131,6 +137,25 @@ uas_address_type_e _pm_util_uam_addr_type_to_uas_addr_type(uam_addr_type_e type) } } +uas_address_type_e _pm_util_uam_tech_type_to_uas_addr_type(uam_tech_type_e type) +{ + switch (type) { + case UAM_TECH_TYPE_BT: + return UAS_ADDR_TYPE_BT; + case UAM_TECH_TYPE_BLE: + return UAS_ADDR_TYPE_BLE; + case UAM_TECH_TYPE_P2P: + return UAS_ADDR_TYPE_P2P; + case UAM_TECH_TYPE_WIFI: + return UAS_ADDR_TYPE_WIFI; + case UAM_TECH_TYPE_WIFI_LOCATION: + return UAS_ADDR_TYPE_WIFI; + default: + UAM_WARN("Unknown type 0x%8.8X", type); + return UAS_PLUGIN_ID_MAX; + } +} + void _pm_util_uam_db_payload_to_uas_payload( uas_payload_info_t *dst_payload, uam_db_payload_info_t *src_payload) { @@ -303,22 +328,7 @@ uas_device_info_t *_pm_util_uam_dev_info_to_uas_dev_info(const uam_device_info_s device->discriminant = dev->discriminant; if (0 < strlen(dev->mac)) { - switch (dev->type) { - case UAM_TECH_TYPE_BLE: - type = UAS_ADDR_TYPE_BLE; - break; - case UAM_TECH_TYPE_BT: - type = UAS_ADDR_TYPE_BT; - break; - case UAM_TECH_TYPE_P2P: - type = UAS_ADDR_TYPE_P2P; - break; - case UAM_TECH_TYPE_WIFI: - type = UAS_ADDR_TYPE_WIFI; - break; - default: - UAM_ERR("Unknown tech type: %d", dev->type); - } + type = _pm_util_uam_tech_type_to_uas_addr_type(dev->type); if (UAS_ADDR_TYPE_INVALID != type) { mac = g_strdup(dev->mac); diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 75d1685..39f179b 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -733,6 +733,8 @@ static unsigned int __uam_core_tech_type_to_addr_type(uam_tech_type_e tech_type) return UAM_ADDR_TYPE_P2P; case UAM_TECH_TYPE_WIFI: return UAM_ADDR_TYPE_WIFI; + case UAM_TECH_TYPE_WIFI_LOCATION: + return UAM_ADDR_TYPE_WIFI; default: UAM_ERR("Unknown tech type: %d", tech_type); return 0; @@ -746,6 +748,8 @@ static unsigned int __uam_core_sensor_to_tech_type(unsigned int sensor) return UAM_TECH_TYPE_BLE; case UAM_SENSOR_BITMASK_WIFI: return UAM_TECH_TYPE_WIFI; + case UAM_SENSOR_BITMASK_WIFI_LOCATION: + return UAM_TECH_TYPE_WIFI_LOCATION; default: UAM_ERR("Unknown sensor: %d", sensor); return 0; @@ -759,6 +763,8 @@ static unsigned int __uam_core_tech_type_to_sensor(unsigned int tech_type) return UAM_SENSOR_BITMASK_BLE; case UAM_TECH_TYPE_WIFI: return UAM_SENSOR_BITMASK_WIFI; + case UAM_TECH_TYPE_WIFI_LOCATION: + return UAM_SENSOR_BITMASK_WIFI_LOCATION; default: UAM_ERR("Unknown tech type: %d", tech_type); return 0; @@ -1405,7 +1411,7 @@ static void __uam_core_add_dev_to_list( /* Add tech info to tech list */ device->tech_list = g_slist_append(device->tech_list, tech); device->supported_techs |= tech->tech_type; - UAM_INFO("device->supported_techs: %8.8X", device->supported_techs); + UAM_INFO("device->supported_techs: 0x%8.8X", device->supported_techs); if (0 < strlen(dev_info->mac)) { uam_db_address_info_t *addr; diff --git a/ua-plugins/include/ua-plugin.h b/ua-plugins/include/ua-plugin.h index b36fa16..ffe04a7 100644 --- a/ua-plugins/include/ua-plugin.h +++ b/ua-plugins/include/ua-plugin.h @@ -333,6 +333,7 @@ typedef enum { UAS_PLUGIN_ID_WIFI, UAS_PLUGIN_ID_LIGHT, UAS_PLUGIN_ID_MOTION, + UAS_PLUGIN_ID_WIFI_LOCATION, UAS_PLUGIN_ID_MAX } uas_plugin_id_e; -- 2.7.4 From da891e55b6641e6ed731c7b849ea4be23db7ba0f Mon Sep 17 00:00:00 2001 From: Abhay Agarwal Date: Tue, 9 Mar 2021 14:31:12 +0530 Subject: [PATCH 16/16] Add UWB plugin support This patch updates the enums and convert functions to support UWB plugin. Change-Id: I51db435f5bfe4413ddb9e9437dff73f46b1ea22f Signed-off-by: Abhay Agarwal --- include/ua-api.h | 2 ++ ua-daemon/include/ua-manager-core.h | 1 + ua-daemon/src/pm/ua-pm-util.c | 12 ++++++++++++ ua-daemon/src/ua-manager-common.c | 2 ++ ua-daemon/src/ua-manager-core.c | 7 +++++++ ua-plugins/include/ua-plugin.h | 4 +++- 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/ua-api.h b/include/ua-api.h index 25323e0..915ccef 100755 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -41,6 +41,7 @@ typedef enum { UAM_SENSOR_BITMASK_LIGHT = 0x00000010, /**< Bitmask for light */ UAM_SENSOR_BITMASK_AUDIO = 0x00000020, /**< Bitmask for audio */ UAM_SENSOR_BITMASK_WIFI_LOCATION = 0x00000040, /**< Bitmask for wifi location */ + UAM_SENSOR_BITMASK_UWB = 0x00000080, /**< Bitmask for UWB */ UAM_SENSOR_ALL = 0xFFFFFFFF, /**< Bitmask for all sensors */ } uam_sensor_bitmask_e; @@ -491,6 +492,7 @@ typedef enum { UAM_TECH_TYPE_WIFI = 0x04, /**< Wi-Fi */ UAM_TECH_TYPE_P2P = 0x08, /**< Wi-Fi p2p */ UAM_TECH_TYPE_WIFI_LOCATION = 0x10, /**< Wi-Fi location */ + UAM_TECH_TYPE_UWB = 0x20, /**< UWB */ UAM_TECH_TYPE_MAX /**< Max. connectivity type */ } uam_tech_type_e; diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index b3970fd..6339e5e 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -34,6 +34,7 @@ typedef enum { UAM_ADDR_TYPE_P2P, /**< Wi-Fi Direct device address */ UAM_ADDR_TYPE_IPv4, /**< IPv4 Address */ UAM_ADDR_TYPE_IPv6, /**< IPv6 Address */ + UAM_ADDR_TYPE_UWB, /**< UWB device address */ UAM_ADDR_TYPE_MAX } uam_addr_type_e; diff --git a/ua-daemon/src/pm/ua-pm-util.c b/ua-daemon/src/pm/ua-pm-util.c index 3a107e8..16dac8e 100644 --- a/ua-daemon/src/pm/ua-pm-util.c +++ b/ua-daemon/src/pm/ua-pm-util.c @@ -50,6 +50,8 @@ unsigned int _pm_util_uas_plugin_id_to_sensor_bitmask(uas_plugin_id_e id) return UAM_SENSOR_BITMASK_MOTION; case UAS_PLUGIN_ID_WIFI_LOCATION: return UAM_SENSOR_BITMASK_WIFI_LOCATION; + case UAS_PLUGIN_ID_UWB: + return UAM_SENSOR_BITMASK_UWB; default: UAM_WARN("Unknown Plugin id 0x%8.8X", id); return 0; @@ -65,6 +67,8 @@ unsigned int _pm_util_uam_tech_type_to_plugin_id(uam_tech_type_e type) return UAS_PLUGIN_ID_WIFI; case UAM_TECH_TYPE_WIFI_LOCATION: return UAS_PLUGIN_ID_WIFI_LOCATION; + case UAM_TECH_TYPE_UWB: + return UAS_PLUGIN_ID_UWB; default: UAM_WARN("Unknown type 0x%8.8X", type); return UAS_PLUGIN_ID_MAX; @@ -80,6 +84,8 @@ unsigned int _pm_util_uas_plugin_id_to_tech_type(uas_plugin_id_e id) return UAM_TECH_TYPE_WIFI; case UAS_PLUGIN_ID_WIFI_LOCATION: return UAM_TECH_TYPE_WIFI_LOCATION; + case UAS_PLUGIN_ID_UWB: + return UAM_TECH_TYPE_UWB; default: UAM_WARN("Unknown Plugin id 0x%8.8X", id); return UAM_TECH_TYPE_NONE; @@ -150,6 +156,8 @@ uas_address_type_e _pm_util_uam_tech_type_to_uas_addr_type(uam_tech_type_e type) return UAS_ADDR_TYPE_WIFI; case UAM_TECH_TYPE_WIFI_LOCATION: return UAS_ADDR_TYPE_WIFI; + case UAM_TECH_TYPE_UWB: + return UAS_ADDR_TYPE_UWB; default: UAM_WARN("Unknown type 0x%8.8X", type); return UAS_PLUGIN_ID_MAX; @@ -405,6 +413,10 @@ uam_device_info_s *_pm_util_uas_dev_info_to_uam_dev_info(const uas_device_info_t g_strlcpy(device->ipv4_addr, dev->addr_list[i].address, UAM_IP_ADDRESS_MAX_STRING_LEN); break; + case UAS_ADDR_TYPE_UWB: + g_strlcpy(device->mac, dev->addr_list[i].address, + UAM_MAC_ADDRESS_STRING_LEN); + break; case UAS_ADDR_TYPE_IPv6: default: UAM_ERR("Unsupported address type: %d", dev->addr_list[i].type); diff --git a/ua-daemon/src/ua-manager-common.c b/ua-daemon/src/ua-manager-common.c index 0edf391..1de7fa9 100644 --- a/ua-daemon/src/ua-manager-common.c +++ b/ua-daemon/src/ua-manager-common.c @@ -189,6 +189,8 @@ const char *_uam_get_sensor_str(uas_plugin_id_e ids) CASE_TO_STR(UAS_PLUGIN_ID_WIFI) CASE_TO_STR(UAS_PLUGIN_ID_LIGHT) CASE_TO_STR(UAS_PLUGIN_ID_MOTION) + CASE_TO_STR(UAS_PLUGIN_ID_WIFI_LOCATION) + CASE_TO_STR(UAS_PLUGIN_ID_UWB) CASE_TO_STR(UAS_PLUGIN_ID_MAX) default: return "UNKNOWN SENSOR"; diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 39f179b..7f57132 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -666,6 +666,7 @@ static gboolean __is_mac_addr(uam_addr_type_e addr_type) if (addr_type == UAM_ADDR_TYPE_BT || addr_type == UAM_ADDR_TYPE_BLE || addr_type == UAM_ADDR_TYPE_WIFI || + addr_type == UAM_ADDR_TYPE_UWB || addr_type == UAM_ADDR_TYPE_P2P) return 1; return 0; @@ -735,6 +736,8 @@ static unsigned int __uam_core_tech_type_to_addr_type(uam_tech_type_e tech_type) return UAM_ADDR_TYPE_WIFI; case UAM_TECH_TYPE_WIFI_LOCATION: return UAM_ADDR_TYPE_WIFI; + case UAM_TECH_TYPE_UWB: + return UAM_ADDR_TYPE_UWB; default: UAM_ERR("Unknown tech type: %d", tech_type); return 0; @@ -750,6 +753,8 @@ static unsigned int __uam_core_sensor_to_tech_type(unsigned int sensor) return UAM_TECH_TYPE_WIFI; case UAM_SENSOR_BITMASK_WIFI_LOCATION: return UAM_TECH_TYPE_WIFI_LOCATION; + case UAM_SENSOR_BITMASK_UWB: + return UAM_TECH_TYPE_UWB; default: UAM_ERR("Unknown sensor: %d", sensor); return 0; @@ -765,6 +770,8 @@ static unsigned int __uam_core_tech_type_to_sensor(unsigned int tech_type) return UAM_SENSOR_BITMASK_WIFI; case UAM_TECH_TYPE_WIFI_LOCATION: return UAM_SENSOR_BITMASK_WIFI_LOCATION; + case UAM_TECH_TYPE_UWB: + return UAM_SENSOR_BITMASK_UWB; default: UAM_ERR("Unknown tech type: %d", tech_type); return 0; diff --git a/ua-plugins/include/ua-plugin.h b/ua-plugins/include/ua-plugin.h index ffe04a7..d96951a 100644 --- a/ua-plugins/include/ua-plugin.h +++ b/ua-plugins/include/ua-plugin.h @@ -64,6 +64,7 @@ typedef enum { UAS_ADDR_TYPE_P2P, UAS_ADDR_TYPE_IPv4, UAS_ADDR_TYPE_IPv6, + UAS_ADDR_TYPE_UWB, UAS_ADDR_TYPE_INVALID } uas_address_type_e; @@ -106,7 +107,7 @@ typedef struct { char *address; /**< Address data */ } uas_address_info_t; -/* Device ble payload information structure */ +/* Device payload information structure */ typedef struct { char primary_key; /** Primary Key */ char device_type; /** Device type */ @@ -334,6 +335,7 @@ typedef enum { UAS_PLUGIN_ID_LIGHT, UAS_PLUGIN_ID_MOTION, UAS_PLUGIN_ID_WIFI_LOCATION, + UAS_PLUGIN_ID_UWB, UAS_PLUGIN_ID_MAX } uas_plugin_id_e; -- 2.7.4