Merge "Mesh: Save vendor & model info post net create" into tizen
authorPyun DoHyun <dh79.pyun@samsung.com>
Thu, 27 Aug 2020 04:56:05 +0000 (04:56 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 27 Aug 2020 04:56:05 +0000 (04:56 +0000)
bt-oal/bluez_hal/src/bt-hal-gatt-client.c
bt-service/services/mesh/bt-service-mesh-config-client.c
bt-service/services/mesh/bt-service-mesh-main.c
bt-service/services/mesh/bt-service-mesh-model.c

index 2ce0c67..219e80b 100644 (file)
@@ -3712,7 +3712,6 @@ static bt_status_t _bt_hold_current_advertising()
 
        if (_bt_hal_is_support_multi_adv() == TRUE) {
                DBG("VSC adv used");
-               return BT_STATUS_SUCCESS;
        }
 
        /* Dependent on Kernel operation. Hold adv to prevent stopping adv on kernel  */
index 28f5afd..d005d1f 100644 (file)
@@ -320,6 +320,28 @@ static void __bt_mesh_wait_response_timeout(
                                BT_MESH_MODEL_CONFIG_GROUP_SUB, req->data,
                                        sizeof(bluetooth_mesh_model_configure_t));
                break;
+       case MESH_OPCODE_CONFIG_MODEL_PUB_GET:
+               /* Send event with timeout */
+               __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_GET_PUBLICATION, req->data,
+                               sizeof(bluetooth_mesh_model_configure_t));
+               break;
+       case MESH_OPCODE_CONFIG_MODEL_PUB_SET:
+               /* Send event with timeout */
+               __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_SET_PUBLICATION, req->data,
+                               sizeof(bluetooth_mesh_model_configure_t));
+               break;
+       case MESH_OPCODE_MODEL_APP_BIND:
+       case MESH_OPCODE_MODEL_APP_UNBIND:
+               /* Send event with timeout */
+               __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_CONFIGURE_APPKEY, req->data,
+                               sizeof(bluetooth_mesh_model_configure_t));
+               break;
        default:
                break;
        }
index bb98162..bc4afcf 100644 (file)
 
 static guint launch_timer = 0;
 static guint mesh_app_ref_count;
+struct l_timeout *wait_timer;
 
 static GSList *apps;
 
+static int __bt_meshd_launch()
+{
+       int ret = UNIT_CONTROL_OK;
+       BT_INFO("Mesh: Launch Meshd");
+       ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
+                               MESH_SYSTEMD_SERVICE_NAME, 5000);
+
+       if (ret != UNIT_CONTROL_OK) {
+               BT_ERR("Failed to call systemact service: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       BT_INFO("Mesh: Launch Meshd successful");
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+static void __bt_meshd_terminate()
+{
+       int ret = UNIT_CONTROL_OK;
+       BT_INFO("Mesh: Stop Meshd");
+
+       ret = actd_stop_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
+                               MESH_SYSTEMD_SERVICE_NAME, 5000);
+       if (ret != UNIT_CONTROL_OK) {
+               BT_ERR("Failed to call systemact service: %d", ret);
+               return;
+       }
+
+       BT_INFO("Mesh: Meshd stop successful");
+}
+
+static void __bt_mesh_terminate()
+{
+       oal_status_t status = OAL_STATUS_SUCCESS;
+
+       /* Terminate bluetooth-meshd */
+       __bt_meshd_terminate();
+
+       /* Reset states */
+       _bt_mesh_set_scanning_state(false);
+       _bt_mesh_set_provisioning_state(false);
+
+       status = mesh_disable();
+       if (OAL_STATUS_SUCCESS != status) {
+               BT_ERR("Mesh: Failed to de-initialize Mesh profile, status: %d",
+                               status);
+               return;
+       }
+
+       /* Un-Register Mesh event handler */
+       _bt_service_unregister_event_handler_callback(BT_MESH_MODULE);
+}
+
 /* Event handlers */
 static void __bt_mesh_handle_pending_request_info(int result,
                int service_function, void *param,
@@ -85,6 +139,10 @@ static void __bt_mesh_handle_pending_request_info(int result,
 
                                /* Increase mesh app ref count */
                                mesh_app_ref_count++;
+                               l_timeout_remove(wait_timer);
+                       } else {
+                               /* Init failed - Terminate bluetooth-mesh */
+                               __bt_mesh_terminate();
                        }
 
                        out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
@@ -795,22 +853,6 @@ static void __handle_mesh_events(int event_type,
        }
 }
 
-static int __bt_meshd_launch()
-{
-       int ret = UNIT_CONTROL_OK;
-       BT_INFO("Mesh: Launch Meshd");
-       ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
-                               MESH_SYSTEMD_SERVICE_NAME, 5000);
-
-       if (ret != UNIT_CONTROL_OK) {
-               BT_ERR("Failed to call systemact service: %d", ret);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-       BT_INFO("Mesh: Launch Meshd successful");
-
-       return BLUETOOTH_ERROR_NONE;
-}
-
 static int __bt_mesh_enable()
 {
        oal_status_t status = OAL_STATUS_SUCCESS;
@@ -849,6 +891,19 @@ static gboolean __bt_mesh_launch_timer_expired_cb(gpointer data)
        return FALSE;
 }
 
+static void __bt_mesh_init_wait_response_timeout(
+                struct l_timeout *timeout, void *user_data)
+{
+       int result = BLUETOOTH_ERROR_TIMEOUT;
+
+       /* Handle DBUS Context return */
+       BT_INFO("Mesh: Handle DBUS Context return");
+       __bt_mesh_handle_pending_request_info(result,
+                       BT_MESH_INIT,
+                       NULL, 0);
+       l_timeout_remove(wait_timer);
+}
+
 int _bt_mesh_init(const char *sender)
 {
        int ret = BLUETOOTH_ERROR_NONE;
@@ -887,8 +942,12 @@ int _bt_mesh_init(const char *sender)
        launch_timer = g_timeout_add(MESH_LAUNCH_DELAY,
                                (GSourceFunc)__bt_mesh_launch_timer_expired_cb,
                                                                        NULL);
-
        BT_INFO("Mesh: Timer ID [%u]", launch_timer);
+
+       /* Add mesh init request timeout */
+       wait_timer = l_timeout_create(MESH_DEFAULT_RESPONSE_TIMEOUT,
+                       __bt_mesh_init_wait_response_timeout, NULL, NULL);
+
        return ret;
 }
 
@@ -904,8 +963,6 @@ int _bt_mesh_deinit(const char *sender)
 {
        GSList *l = NULL;
        char *owner = NULL;
-       oal_status_t status = OAL_STATUS_SUCCESS;
-       int ret = UNIT_CONTROL_OK;
 
        BT_INFO("Mesh: Deinit Request from App [%s]", sender);
        BT_INFO("Mesh: Total Apps available in list [%d]",
@@ -931,22 +988,9 @@ int _bt_mesh_deinit(const char *sender)
 
        if (mesh_app_ref_count == 1) {
                BT_INFO("Mesh: Only one app using Mesh Stack: Unload & reduce ref count");
-               /* Terminate bluetooth-meshd */
-               ret = actd_stop_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
-                               MESH_SYSTEMD_SERVICE_NAME, 5000);
-
-               if (ret != UNIT_CONTROL_OK)
-                       BT_ERR("Failed to call systemact service: %d", ret);
-
-               status = mesh_disable();
-               if (OAL_STATUS_SUCCESS != status) {
-                       BT_ERR("Mesh: Failed to de-initialize Mesh profile, status: %d",
-                                       status);
-                       return BLUETOOTH_ERROR_INTERNAL;
-               }
 
-               /* Un-Register Mesh event handler */
-               _bt_service_unregister_event_handler_callback(BT_MESH_MODULE);
+               /* Terminate bluetooth-mesh */
+               __bt_mesh_terminate();
        }
 
        /* Decrease mesh app ref count */
index d38db10..1e191b3 100644 (file)
@@ -196,7 +196,6 @@ static struct mesh_pending_request *__bt_mesh_get_request_by_response(
        for (; entry; entry = entry->next) {
                struct mesh_pending_request *req = entry->data;
 
-               /* Test */
                BT_INFO("Mesh: Req addr [0x%4.4x] req opcode [0x%4.4x] res [0x%4.4x]", req->addr, req->cmd->opcode, req->cmd->response);
                BT_INFO("Mesh: Current req addr [0x%4.4x] res [0x%4.4x]", addr, response);
                _bt_mesh_util_convert_hex_to_string((uint8_t *) net_uuid, 16, uuid_str,
@@ -206,8 +205,8 @@ static struct mesh_pending_request *__bt_mesh_get_request_by_response(
                _bt_mesh_util_convert_hex_to_string((uint8_t *) req->net_uuid, 16, uuid_str1,
                                BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
                BT_INFO("Mesh: Net UUID1[%s]", uuid_str1);
+               /* Do not compare addr - In case of group message address may not match */
                if (!memcmp(net_uuid, req->net_uuid, 16) &&
-                               req->addr == addr &&
                                req->cmd->response == response)
                        return req;
        }
@@ -279,8 +278,7 @@ static void __bt_mesh_handle_pending_msg_request_info(int result,
 
                        BT_DBG("Request Sender: [%s]", req_info->sender);
                        /* Match Network and Remote Node unicast*/
-                       if (!g_strcmp0(event->net_uuid, req->net_uuid) &&
-                               event->primary_unicast == req->primary_unicast) {
+                       if (!g_strcmp0(event->net_uuid, req->net_uuid)) {
                                event->elem_index = req->elem_index;
 
                                /* Send Event */