Mesh: Apply fix in Model Subscripton List CAPI 18/240018/1
authorAnupam Roy <anupam.r@samsung.com>
Fri, 31 Jul 2020 11:05:10 +0000 (16:35 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Fri, 31 Jul 2020 11:05:10 +0000 (16:35 +0530)
This patch handles following issues
- Remove double free of Subscription list
- Fix Wrong sync event index for Model List Callback
- Minor code refactoring in Model Subscription List API

Change-Id: I9a6dbf5d34f7ecb387eda7a2868ee788dc4fd215
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
src/bluetooth-common.c
src/bluetooth-mesh.c

index f9a73e9..6a42f35 100644 (file)
@@ -1425,6 +1425,7 @@ static bool __bt_need_to_handle(int event)
        case BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED:
        case BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED:
        case BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST:
+       case BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST:
        case BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND:
        case BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED:
        case BLUETOOTH_EVENT_MESH_MODEL_VIRTUAL_SUBSCRIPTION_CONFGURED:
@@ -4083,6 +4084,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                bluetooth_mesh_model_configure_t *res = NULL;
                bt_mesh_network_s *network_s = NULL;
                bt_mesh_node_s *node_s = NULL;
+               bt_mesh_model_s *model_s;
+               bt_mesh_element_s *element_s;
                GSList *sublist = NULL;
                int total = 0;
                res = (bluetooth_mesh_model_configure_t *)(param->param_data);
@@ -4100,8 +4103,6 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                                res->primary_unicast);
                if (!node_s)
                        break;
-               bt_mesh_model_s *model_s;
-               bt_mesh_element_s *element_s;
 
                element_s = _bt_mesh_get_element_from_index(node_s, res->elem_index);
                if (!element_s)
@@ -4110,12 +4111,16 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                if (!model_s)
                        break;
                total = res->sublist_count;
+               BT_INFO("Total Subscription in the model [%d]", total);
 
                for (int i = 0; i < total; i++) {
                        bt_mesh_group_s *group_s;
                        group_s = _bt_mesh_network_get_group(network_s, *res->sub_list[i]);
+                       if (!group_s) {
+                               BT_INFO("Mesh: Subscription address [0x%2.2x]",  *res->sub_list[i]);
+                               break;
+                       }
                        sublist = g_slist_append(sublist, group_s);
-                       g_free(res->sub_list[i]);
                }
                ((bt_mesh_model_subscription_list_cb)
                        bt_event_slot_container[event_index].callback)
index 243e206..d0175a2 100644 (file)
@@ -262,6 +262,9 @@ bt_mesh_group_s* _bt_mesh_network_get_group(
        l = g_slist_find_custom(network_s->groups, GUINT_TO_POINTER(group_addr),
                        (GCompareFunc) __compare_network_group_address);
        if (!l) {
+
+               BT_INFO("Mesh: Group not available in Network: Addr[0x%2.2x]",
+                       group_addr);
                group_s = g_malloc0(sizeof(bt_mesh_group_s));
                group_s->addr = group_addr;
                if (!BT_MESH_IS_GROUP(group_addr))
@@ -3100,7 +3103,6 @@ int bt_mesh_network_create_group(bt_mesh_network_h network,
        return error_code;
 }
 
-
 int bt_mesh_model_configure_group_subscription(bt_mesh_model_subscription_op_e model_op,
                bt_mesh_model_h model, bt_mesh_group_h group,
                        bt_mesh_model_subscription_op_cb callback, void *user_data)
@@ -3259,18 +3261,18 @@ int bt_mesh_model_get_subscription_list(bt_mesh_model_h model,
        BT_CHECK_INPUT_PARAMETER(callback);
 
        model_s = (bt_mesh_model_s*) model;
-       element_s = (bt_mesh_element_s*) model_s->parent;
-       node_s = (bt_mesh_node_s*) element_s->parent;
-       network_s = (bt_mesh_network_s*) node_s->parent;
+       BT_MESH_VALIDATE_HANDLE(model_s, model_list);
 
-       BT_CHECK_INPUT_PARAMETER(model_s);
+       element_s = (bt_mesh_element_s*) model_s->parent;
        BT_CHECK_INPUT_PARAMETER(element_s);
-       BT_CHECK_INPUT_PARAMETER(node_s);
-       BT_CHECK_INPUT_PARAMETER(network_s);
-
-       BT_MESH_VALIDATE_HANDLE(model_s, model_list);
        BT_MESH_VALIDATE_HANDLE(element_s, element_list);
+
+       node_s = (bt_mesh_node_s*) element_s->parent;
+       BT_CHECK_INPUT_PARAMETER(node_s);
        BT_MESH_VALIDATE_HANDLE(node_s, node_list);
+
+       network_s = (bt_mesh_network_s*) node_s->parent;
+       BT_CHECK_INPUT_PARAMETER(network_s);
        BT_MESH_VALIDATE_HANDLE(network_s, networks);
 
        /* Return error, if node is not attached */
@@ -3291,7 +3293,7 @@ int bt_mesh_model_get_subscription_list(bt_mesh_model_h model,
        }
 
        FUNC_EXIT;
-       _bt_set_cb(BT_EVENT_MESH_NODE_MODEL_APPKEY_LIST, callback, user_data);
+       _bt_set_cb(BT_EVENT_MESH_NODE_MODEL_SUB_LIST, callback, user_data);
        return error_code;
 }