Mesh: Fix & Refactor Mesh Model Subscription codes 26/239826/2
authorAnupam Roy <anupam.r@samsung.com>
Thu, 30 Jul 2020 05:23:37 +0000 (10:53 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Thu, 30 Jul 2020 06:29:47 +0000 (11:59 +0530)
This patch handles following
- Handle Timeout of Model Subscription Commands
 [bt-service should send error event and clear pending
 request in queue]
- Fix improper handling of Model Subscription status handling
- Add DEBUG prints

Change-Id: I811bc570df8091ce948595c05ebc9856ffd51be2
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-api/bt-mesh.c
bt-service/services/mesh/bt-service-mesh-cdb.c
bt-service/services/mesh/bt-service-mesh-config-client.c
bt-service/services/mesh/bt-service-mesh-nodes.c

index f168369..8ac40ac 100644 (file)
@@ -526,7 +526,8 @@ BT_EXPORT_API int bluetooth_mesh_element_get_all_models(
                        BT_ERR("Mesh: out_param is NULL");
                        result = BLUETOOTH_ERROR_INTERNAL;
                } else {
-                       size = (out_param->len) / sizeof(guint16);
+                       size = (out_param->len) / sizeof(guint32);
+                       BT_INFO("Mesh: Total Models found in Element [%d]", size);
 
                        for (i = 0; i < size; i++) {
                                uint32_t model_obj;
index ce9c3af..2648190 100644 (file)
@@ -1296,6 +1296,8 @@ static bool __mesh_load_composition(_bt_mesh_cdb_t *cfg,
                        return false;
 
                mod_cnt = json_object_array_length(jmods);
+               BT_INFO("Mesh: Total Model count in element Index [%d] is [%d]",
+                       index, mod_cnt);
 
                for (k = 0; k < mod_cnt; ++k) {
                        json_object *jmod, *jid;
index d04b3f6..aa3b38e 100644 (file)
@@ -266,6 +266,25 @@ static void __bt_mesh_wait_response_timeout(
                                BT_MESH_NODE_TTL_EXECUTE, req->data,
                                        sizeof(bluetooth_mesh_node_ttl_info_t));
                break;
+       case MESH_OPCODE_CONFIG_MODEL_SUB_ADD:
+       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE:
+       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL:
+       case MESH_OPCODE_CONFIG_MODEL_SUB_OVERWRITE:
+               /* Send event with timeout */
+                __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_CONFIG_GROUP_SUB, req->data,
+                                       sizeof(bluetooth_mesh_model_configure_t));
+               break;
+       case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_ADD:
+       case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_DELETE:
+       case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_OVERWRITE:
+               /* Send event with timeout */
+                __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, req->data,
+                                       sizeof(bluetooth_mesh_model_configure_t));
+               break;
        default:
                break;
        }
@@ -871,11 +890,17 @@ static void __bt_mesh_handle_pending_dev_config_request_info(int result,
 
                        event = (bluetooth_mesh_model_configure_t*) param;
                        req = (bluetooth_mesh_model_configure_t*)req_info->user_data;
+                       BT_INFO("Mesh: Event Network [%s] Req Network [%s]",
+                               event->net_uuid, req->net_uuid);
+
+                       BT_INFO("Mesh: Event Unicast [0x%4.4x] Req Unicast [0x%4.4x]",
+                               event->primary_unicast, req->primary_unicast);
 
                        if (!g_strcmp0(req->net_uuid, event->net_uuid) &&
                                req->primary_unicast == event->primary_unicast) {
 
                                req->sub_addr = event->sub_addr;
+                               BT_INFO("Mesh: Send event for Model Subscription");
                                /* Send Event */
                                __bt_mesh_send_model_subscription_configure_event(
                                        BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED,
@@ -897,7 +922,11 @@ static void __bt_mesh_handle_pending_dev_config_request_info(int result,
 
                        event = (bluetooth_mesh_model_configure_t*) param;
                        req = (bluetooth_mesh_model_configure_t*)req_info->user_data;
+                       BT_INFO("Mesh: Event Network [%s] Req Network [%s]",
+                               event->net_uuid, req->net_uuid);
 
+                       BT_INFO("Mesh: Event Unicast [0x%4.4x] Req Unicast [0x%4.4x]",
+                               event->primary_unicast, req->primary_unicast);
                        if (!g_strcmp0(req->net_uuid, event->net_uuid) &&
                                req->primary_unicast == event->primary_unicast) {
                                /* Send Event */
@@ -1001,6 +1030,7 @@ static void __mesh_handle_model_subscription_event(int result,
                bluetooth_mesh_model_configure_t *param,
                        const struct mesh_config_cmd *cmd)
 {
+       BT_INFO("Mesh: Model Subscription Event: Request [%d]", cmd->opcode);
        switch (cmd->opcode) {
        /* Fall through */
        case MESH_OPCODE_CONFIG_MODEL_SUB_ADD:
@@ -1008,15 +1038,17 @@ static void __mesh_handle_model_subscription_event(int result,
        case MESH_OPCODE_CONFIG_MODEL_SUB_OVERWRITE:
        case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL:
                /* Model Bind/UnBind Event */
+       BT_INFO("Mesh: Handle Event for Request: BT_MESH_MODEL_CONFIG_GROUP_SUB");
        __bt_mesh_handle_pending_dev_config_request_info(result,
-                       BT_MESH_MODEL_CONFIG_GROUP_SUB, &param,
+                       BT_MESH_MODEL_CONFIG_GROUP_SUB, param,
                                sizeof(bluetooth_mesh_model_configure_t));
                break;
        case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_ADD:
        case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_DELETE:
        case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_OVERWRITE:
+       BT_INFO("Mesh: Handle Event for Request: BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB");
        __bt_mesh_handle_pending_dev_config_request_info(result,
-                       BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, &param,
+                       BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, param,
                                sizeof(bluetooth_mesh_model_configure_t));
                break;
        default:
@@ -1133,9 +1165,18 @@ void _bt_mesh_config_client_devkey_msg_handler(
                BT_INFO("\nNode %4.4x Subscription status %s\n",
                                event->source, __mesh_status_to_string(data[0]));
 
+               if (data[0] != MESH_STATUS_SUCCESS)
+                       result = BLUETOOTH_ERROR_INTERNAL;
+
+               if (!cmd) {
+                       BT_INFO("Mesh: Command not found!!");
+                       break;
+               }
+
                ele_addr = l_get_le16(data + 1);
                addr = l_get_le16(data + 3);
                BT_INFO("Element Addr\t%4.4x\n", ele_addr);
+               BT_INFO("Message Source Addr\t%4.4x\n", event->source);
 
                if (data_len == 9) {
                        /* vendor Model */
@@ -1153,6 +1194,7 @@ void _bt_mesh_config_client_devkey_msg_handler(
                param.sub_addr = addr;
                param.model = mod_id;
                BT_INFO("Subscr Addr\t%4.4x\n", addr);
+               BT_INFO("Model ID\t%4.4x\n", mod_id);
 
                if (cmd)
                        __mesh_handle_model_subscription_event(result, &param, cmd);
@@ -1682,25 +1724,28 @@ int _bt_mesh_model_configure_group_subscription(const char *app_cred,
                return BLUETOOTH_ERROR_DEVICE_BUSY;
        }
 
+       BT_INFO("Mesh: group Subscription Req: [%d]", req->op);
        if (req->op != BLUETOOTH_MESH_MODEL_SUB_DELETE_ALL) {
+               BT_INFO("Mesh: group Subscription Addr [0x%2.2x]", req->sub_addr);
+
                /* Subscriptio address sanity check */
-               if ((!MESH_IS_GROUP(req->sub_addr) ||
-                       MESH_IS_ALL_NODES(req->sub_addr)) ||
+               if (!MESH_IS_GROUP(req->sub_addr) ||
                                MESH_IS_VIRTUAL(req->sub_addr)) {
-                       BT_ERR("Mesh: Bad subscription address %x\n",
+                       BT_ERR("Mesh: Bad subscription address [0x%2.2x\n]",
                                req->sub_addr);
                        return BLUETOOTH_ERROR_INVALID_PARAM;
                }
-       }
+       } else
+               BT_INFO("Mesh: group Subscription Req: Delete All");
 
+       _bt_mesh_util_convert_string_to_hex(req->net_uuid,
+               strlen(req->net_uuid), net_uuid.uuid, 16);
        /* Get Subnet index of the remote node for TX encryption */
        netkey_idx = _bt_mesh_node_get_subnet_idx(net_uuid.uuid,
                                req->primary_unicast);
        if (netkey_idx == MESH_NET_IDX_INVALID)
                return BLUETOOTH_ERROR_INTERNAL;
 
-       _bt_mesh_util_convert_string_to_hex(req->net_uuid,
-               strlen(req->net_uuid), net_uuid.uuid, 16);
 
        if (req->op == BLUETOOTH_MESH_MODEL_SUB_ADD)
                opcode = MESH_OPCODE_CONFIG_MODEL_SUB_ADD;
@@ -1720,6 +1765,8 @@ int _bt_mesh_model_configure_group_subscription(const char *app_cred,
 
        data_len = _bt_mesh_util_opcode_set(opcode, buffer);
 
+       BT_INFO("Mesh: Group Subscription Primary unicast [0x%2.2x]",
+                       req->primary_unicast);
        /* Element Address */
        l_put_le16((req->primary_unicast + req->elem_index),
                        buffer + data_len);
@@ -1731,6 +1778,7 @@ int _bt_mesh_model_configure_group_subscription(const char *app_cred,
                data_len += 2;
        }
 
+       BT_INFO("Mesh: Group Subscription Model ID [0x%4.4x]", req->model);
        /* Insert Model ID */
         if (req->model >= 0xFFFF0000) {
                /* 1st 2 octet Company ID is 0xFFFF means, it is BT SIG Model*/
@@ -1752,6 +1800,7 @@ int _bt_mesh_model_configure_group_subscription(const char *app_cred,
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
+       BT_INFO("Mesh: Group Subscription Command sent successfully");
        /* Queue the request with timeout */
        __bt_mesh_add_request(opcode, req->primary_unicast,
                net_uuid.uuid,
@@ -1781,16 +1830,19 @@ int _bt_mesh_model_configure_virtual_group_subscription(
        _bt_mesh_util_convert_string_to_hex(req->net_uuid,
                strlen(req->net_uuid), net_uuid.uuid, 16);
 
+       BT_INFO("Mesh: Virtual Group Subscription Req: [%d] Group Addr [0x%2.2x]",
+                       req->op, req->sub_addr);
+
        if (req->op != BLUETOOTH_MESH_MODEL_SUB_DELETE_ALL) {
                /* Subscription address sanity check */
-               if ((MESH_IS_GROUP(req->sub_addr) ||
-                       MESH_IS_ALL_NODES(req->sub_addr)) ||
+               if (MESH_IS_GROUP(req->sub_addr) ||
                                !(MESH_IS_VIRTUAL(req->sub_addr))) {
-                       BT_ERR("Mesh: Bad Virtual subscription address %x\n",
+                       BT_ERR("Mesh: Bad Virtual Group subscription address [0x%2.2x\n]",
                                req->sub_addr);
                        return BLUETOOTH_ERROR_INVALID_PARAM;
                }
-       }
+       } else
+               BT_INFO("Mesh: Virtual Group Subscription Req: Delete All");
 
        /* Get Subnet index of the remote node for TX encryption */
        netkey_idx = _bt_mesh_node_get_subnet_idx(net_uuid.uuid,
@@ -1799,13 +1851,11 @@ int _bt_mesh_model_configure_virtual_group_subscription(
                return BLUETOOTH_ERROR_INTERNAL;
 
        if (req->op == BLUETOOTH_MESH_MODEL_SUB_ADD)
-               opcode = MESH_OPCODE_CONFIG_MODEL_SUB_ADD;
+               opcode = MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_ADD;
        else if (req->op == BLUETOOTH_MESH_MODEL_SUB_DELETE)
-               opcode = MESH_OPCODE_CONFIG_MODEL_SUB_DELETE;
-       else if (req->op == BLUETOOTH_MESH_MODEL_SUB_DELETE_ALL)
-               opcode = MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL;
+               opcode = MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_DELETE;
        else if (req->op == BLUETOOTH_MESH_MODEL_SUB_OVERWRITE)
-               opcode = MESH_OPCODE_CONFIG_MODEL_SUB_OVERWRITE;
+               opcode = MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_OVERWRITE;
 
        /* Check pending request */
        if (_bt_mesh_check_pending_request(opcode,
@@ -1832,6 +1882,7 @@ int _bt_mesh_model_configure_virtual_group_subscription(
                data_len += 16;
        }
 
+       BT_INFO("Mesh: Virtual Group Subscription Model ID [0x%4.4x]", req->model);
        /* Insert Model ID */
         if (req->model >= 0xFFFF0000) {
                /* 1st 2 octet Company ID is 0xFFFF means, it is BT SIG Model*/
@@ -1854,6 +1905,7 @@ int _bt_mesh_model_configure_virtual_group_subscription(
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
+       BT_INFO("Mesh: Virtual Group Subscription Command sent successfully");
        /* Queue the request with timeout */
        __bt_mesh_add_request(opcode, req->primary_unicast,
                net_uuid.uuid,
index 5173bac..7a90a63 100644 (file)
@@ -298,6 +298,9 @@ bool _bt_mesh_node_get_models(uint8_t net_uuid[],
        struct mesh_network_t *network;
        const struct l_queue_entry *entry;
 
+       BT_INFO("Mesh: Get All Models in an element [0x%4.4x] Index [0x%x]",
+                       unicast, ele_idx);
+
        network = l_queue_find(networks, __mesh_net_uuid_match, net_uuid);
        if (!network)
                return false;
@@ -312,9 +315,12 @@ bool _bt_mesh_node_get_models(uint8_t net_uuid[],
 
        entry = l_queue_get_entries(rmt->els[ele_idx]);
 
+       BT_INFO("Mesh: Total Models in Element [%d]",
+                       l_queue_length(rmt->els[ele_idx]));
        for (; entry; entry = entry->next) {
                uint32_t model = L_PTR_TO_UINT(entry->data);
                g_array_append_vals(*out, &model, sizeof(uint32_t));
+               BT_INFO("Mesh: Appended Model ID [0x%4.4x]", model);
        }
        return true;
 }
@@ -344,9 +350,14 @@ bool _bt_mesh_node_set_model(uint8_t net_uuid[],
        if (!vendor)
                mod_id = MESH_VENDOR_ID_MASK | mod_id;
 
+       BT_INFO("Mesh: Insert Model in Element Index [0x%x]", ele_idx);
+       BT_INFO("Mesh: Insert Model Id [0x%4.4x]", mod_id);
        l_queue_insert(rmt->els[ele_idx], L_UINT_TO_PTR(mod_id),
                        __mesh_compare_mod_id, NULL);
 
+       BT_INFO("Mesh: Current model count after update in element is [%d]",
+                       l_queue_length(rmt->els[ele_idx]));
+
        return true;
 }