Fix the coverity issues
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / services / mesh / bt-service-mesh-config-client.c
index d005d1f..9b57173 100644 (file)
@@ -1156,13 +1156,13 @@ void _bt_mesh_config_client_devkey_msg_handler(
        int n;
        struct mesh_pending_request *req;
 
-       if (_bt_mesh_util_opcode_get(data, data_len, &opcode, &n)) {
-               BT_INFO("Mesh: Opcode of response data [0x%2.2x], actual data len [%d]", opcode, n);
-               data_len -= n;
-               data += n;
-       } else
+       if (_bt_mesh_util_opcode_get(data, data_len, &opcode, &n) == false)
                return;
 
+       BT_INFO("Mesh: Opcode of response data [0x%2.2x], actual data len [%d]", opcode, n);
+       data_len -= n;
+       data += n;
+
        BT_INFO("Mesh: Received %s (len %u) opcode [0x%2.2x]",
                __mesh_get_opcode_string(opcode), data_len, opcode);
 
@@ -1171,10 +1171,11 @@ void _bt_mesh_config_client_devkey_msg_handler(
        if (req) {
                BT_INFO("Mesh: Got Config Request");
                cmd = req->cmd;
-               __mesh_request_remove(req);
                l_queue_remove(pending_requests, req);
-       } else
+               __mesh_request_remove(req);
+       } else {
                cmd = NULL;
+       }
 
 
        switch (opcode & ~MESH_OPCODE_UNRELIABLE) {
@@ -1285,6 +1286,43 @@ void _bt_mesh_config_client_devkey_msg_handler(
                BT_INFO("Subscr Addr\t%4.4x\n", addr);
                BT_INFO("Model ID\t%4.4x\n", mod_id);
 
+               if (data[0] == MESH_STATUS_SUCCESS) {
+                       /* Update cdb */
+                       switch (cmd->opcode) {
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_ADD:
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_ADD:
+                               if (!_bt_mesh_network_add_model_subscription(
+                                       event->net_uuid.uuid, event->source,
+                                       ele_addr - event->source, mod_id, addr)) {
+                                       BT_INFO("Failed to add model subscription!");
+                               }
+                       break;
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE:
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_DELETE:
+                               if (!_bt_mesh_network_delete_model_subscription(
+                                       event->net_uuid.uuid, event->source,
+                                       ele_addr - event->source, mod_id, addr)) {
+                                       BT_INFO("Failed to delete model subscription!");
+                               }
+                       break;
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL:
+                               if (!_bt_mesh_network_delete_all_model_subscription(
+                                       event->net_uuid.uuid, event->source,
+                                       ele_addr - event->source, mod_id)) {
+                                       BT_INFO("Failed to delete all model subscription!");
+                               }
+                       break;
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_OVERWRITE:
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_OVERWRITE:
+                               if (!_bt_mesh_network_overwrite_model_subscription(
+                                       event->net_uuid.uuid, event->source,
+                                       ele_addr - event->source, mod_id, addr)) {
+                                       BT_INFO("Failed to overwrite model subscription!");
+                               }
+                       break;
+                       }
+               }
+
                if (cmd)
                        __mesh_handle_model_subscription_event(result, &param, cmd);
 
@@ -1458,6 +1496,9 @@ void _bt_mesh_config_client_devkey_msg_handler(
                                *param.sub_list[k] = l_get_le16(data + i);
                        }
                }
+
+               /* <TO-DO> Update model sub in cdb */
+
                __bt_mesh_handle_pending_dev_config_request_info(result,
                        BT_MESH_MODEL_GET_SUBSCRIPTION_LIST, &param,
                                sizeof(bluetooth_mesh_model_configure_t));