Mesh: Refactor Model Get & Set publication codes 82/240582/3
authorAnupam Roy <anupam.r@samsung.com>
Fri, 7 Aug 2020 14:41:30 +0000 (20:11 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Sat, 8 Aug 2020 05:25:22 +0000 (10:55 +0530)
This patch adds some exception handling in the
CAPI for invalid model & group handles by application.
It also does some minor refactoring.

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

index 94bad7e..44f06fe 100644 (file)
@@ -3986,8 +3986,6 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                BT_INFO("BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS");
                bluetooth_mesh_model_configure_t *res = NULL;
                bt_mesh_network_s *network_s = NULL;
-               bt_mesh_node_s *node_s = NULL;
-               bt_mesh_element_s *element_s = NULL;
                bt_mesh_group_s *group_s = NULL;
                bt_mesh_appkey_s *appkey_s = NULL;
                bt_mesh_model_s *model_s = NULL;
@@ -4002,35 +4000,37 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                else
                        BT_INFO("Mesh: Model Publication Status: FAILED");
 
+               BT_INFO("Mesh: AppKey Index [0x%2.2x]", res->appkey_idx);
+               BT_INFO("Mesh: Model ID[0x%4.4x]", res->model);
+
                appkey_s = _bt_mesh_network_get_appkey_from_index(network_s, res->appkey_idx);
                if (!appkey_s)
                        break;
-               node_s = _bt_mesh_get_node_from_unicast(res->net_uuid, res->primary_unicast);
-               if (!node_s)
-                       break;
-               element_s = _bt_mesh_get_node_get_element_from_index(res->net_uuid,
-                               res->primary_unicast, res->elem_index);
-               if (!element_s)
-                       break;
+
                model_s = _bt_mesh_get_node_get_model_from_element(res->net_uuid,
                                res->primary_unicast, res->elem_index, res->model);
                if (!model_s)
                        break;
-               group_s = _bt_mesh_network_get_group(network_s, res->sub_addr);
+               model_s->pub_addr = res->pub_addr;
+               BT_INFO("Mesh: Model Publication address [0x%2.2x]", model_s->pub_addr);
+               group_s = _bt_mesh_network_get_group(network_s, res->pub_addr);
 
                /* Exception is Unassigned address */
-               if (!group_s &&  res->sub_addr == 0x0000)
+               if (!group_s &&  res->pub_addr == 0x0000) {
+                       BT_INFO("Mesh: Model Publication Group is set to Unassigned");
                        ((bt_mesh_model_publication_status_cb)
-                               bt_event_slot_container[event_index].callback)
-                                       (_bt_get_error_code(param->result), (bt_mesh_model_h) model_s,
-                                         NULL, (bt_mesh_appkey_h) appkey_s,
-                                        bt_event_slot_container[event_index].user_data);
-               else
+                        bt_event_slot_container[event_index].callback)
+                               (_bt_get_error_code(param->result), (bt_mesh_model_h) model_s,
+                                NULL, (bt_mesh_appkey_h) appkey_s,
+                                bt_event_slot_container[event_index].user_data);
+               } else {
+                       BT_INFO("Mesh: Send Model Publication Status event");
                        ((bt_mesh_model_publication_status_cb)
-                               bt_event_slot_container[event_index].callback)
-                                       (_bt_get_error_code(param->result), (bt_mesh_model_h) model_s,
-                                         (bt_mesh_group_h) group_s, (bt_mesh_appkey_h) appkey_s,
-                                        bt_event_slot_container[event_index].user_data);
+                        bt_event_slot_container[event_index].callback)
+                               (_bt_get_error_code(param->result), (bt_mesh_model_h) model_s,
+                                (bt_mesh_group_h) group_s, (bt_mesh_appkey_h) appkey_s,
+                                bt_event_slot_container[event_index].user_data);
+               }
                break;
        }
        case BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST : {
index 5f52a58..8742cc9 100644 (file)
@@ -3392,11 +3392,25 @@ int bt_mesh_model_set_publication(bt_mesh_model_h model, bt_mesh_appkey_h appkey
        BT_CHECK_INPUT_PARAMETER(callback);
 
        model_s = (bt_mesh_model_s*) model;
+       BT_MESH_VALIDATE_HANDLE(model_s, model_list);
+
        appkey_s = (bt_mesh_appkey_s*) appkey;
+       BT_MESH_VALIDATE_HANDLE(appkey_s, appkey_list);
+
        group_s = (bt_mesh_group_s*) group;
+       BT_MESH_VALIDATE_HANDLE(group_s, group_list);
+
        element_s = (bt_mesh_element_s*) model_s->parent;
+       BT_CHECK_INPUT_PARAMETER(element_s);
+       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);
 
        if (group_s->parent != network_s)
                return BT_ERROR_INVALID_PARAMETER;
@@ -3408,17 +3422,6 @@ int bt_mesh_model_set_publication(bt_mesh_model_h model, bt_mesh_appkey_h appkey
        if (params->retrans_step > BT_MESH_MAX_PUBISH_RETRANSMIT_INTERVAL_STEPS)
                return BT_ERROR_INVALID_PARAMETER;
 
-       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);
-       BT_MESH_VALIDATE_HANDLE(node_s, node_list);
-       BT_MESH_VALIDATE_HANDLE(network_s, networks);
-       BT_MESH_VALIDATE_HANDLE(appkey_s, appkey_list);
-       BT_MESH_VALIDATE_HANDLE(group_s, group_list);
-
        /* Return error, if node is not attached */
        if (!node_s->is_attached)
                return BT_ERROR_INVALID_PARAMETER;
@@ -3468,18 +3471,18 @@ int bt_mesh_model_get_publication(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 */