diff options
author | Anupam Roy <anupam.r@samsung.com> | 2020-07-27 14:07:48 +0530 |
---|---|---|
committer | Anupam Roy <anupam.r@samsung.com> | 2020-07-27 08:45:55 +0000 |
commit | 840e9382ddf478b9ff7a1c00c67527619ca8fb6f (patch) | |
tree | 790b946876b272db489e7004eeaa63bcc2cc8ca6 /src/bluetooth-mesh.c | |
parent | d05d1aca8085597b47f4754191e3e5e6d436efe7 (diff) | |
download | bluetooth-840e9382ddf478b9ff7a1c00c67527619ca8fb6f.tar.gz bluetooth-840e9382ddf478b9ff7a1c00c67527619ca8fb6f.tar.bz2 bluetooth-840e9382ddf478b9ff7a1c00c67527619ca8fb6f.zip |
Mesh: Apply stabilization fixes in CAPI
Some of the notable changes are following-
1. Add 'Model Configure AppKey event handling'
2. Fix bug in fetching model from element
[Fixed wrong handling og GSLists]
3. Apply exception handling in deleting NetKey from a node
[Application crash in case of invalid NetKey handle]
4. Fix bug in handling appkeys bound to a NetKey of a node
[Return AppKey(s) bound to NetKey, instead of reurning ALL AppKeys]
5. Fix application crash due to double free
[Double Free of Model AppKey List items]
Change-Id: Icea2e305d5cd2059b2db35d80aa269b9d547b176
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Diffstat (limited to 'src/bluetooth-mesh.c')
-rw-r--r-- | src/bluetooth-mesh.c | 88 |
1 files changed, 40 insertions, 48 deletions
diff --git a/src/bluetooth-mesh.c b/src/bluetooth-mesh.c index a848b26..7eb0b8f 100644 --- a/src/bluetooth-mesh.c +++ b/src/bluetooth-mesh.c @@ -442,21 +442,21 @@ bt_mesh_model_s *_bt_mesh_get_node_get_model_from_element( if (!l) return NULL; - network_s = l->data; + network_s = (bt_mesh_network_s*) l->data; l1 = g_slist_find_custom(network_s->nodes, GUINT_TO_POINTER(unicast), (GCompareFunc)__compare_node_primary_unicast); if (!l1) return NULL; - node_s = l1->data; + node_s = (bt_mesh_node_s*) l1->data; l2 = g_slist_find_custom(node_s->elements, GUINT_TO_POINTER(elem_idx), (GCompareFunc)__compare_node_element_index); if (!l2) return NULL; - element_s = (bt_mesh_element_s*) l->data; + element_s = (bt_mesh_element_s*) l2->data; l3 = g_slist_find_custom(element_s->models, GUINT_TO_POINTER(model), @@ -464,7 +464,7 @@ bt_mesh_model_s *_bt_mesh_get_node_get_model_from_element( if (!l3) return NULL; - return (bt_mesh_model_s*) l->data; + return (bt_mesh_model_s*) l3->data; } bt_mesh_element_s * _bt_mesh_get_node_get_element_from_index(char *net_uuid, @@ -1408,10 +1408,9 @@ int bt_mesh_netkey_update(bt_mesh_netkey_h netkey) BT_CHECK_INPUT_PARAMETER(netkey); netkey_s = (bt_mesh_netkey_s*)netkey; + BT_MESH_VALIDATE_HANDLE(netkey_s, netkey_list); network_s = netkey_s->parent; - BT_MESH_VALIDATE_HANDLE(network_s, networks); - BT_MESH_VALIDATE_HANDLE(netkey_s, netkey_list); memset(&net, 0x00, sizeof(bluetooth_mesh_network_t)); @@ -1440,13 +1439,13 @@ int bt_mesh_netkey_delete(bt_mesh_netkey_h netkey) FUNC_ENTRY; BT_CHECK_MESH_SUPPORT(); BT_CHECK_MESH_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(netkey); netkey_s = (bt_mesh_netkey_s*)netkey; + BT_MESH_VALIDATE_HANDLE(netkey_s, netkey_list); network_s = netkey_s->parent; - BT_MESH_VALIDATE_HANDLE(network_s, networks); - BT_MESH_VALIDATE_HANDLE(netkey_s, netkey_list); memset(&net, 0x00, sizeof(bluetooth_mesh_network_t)); @@ -1481,14 +1480,14 @@ int bt_mesh_netkey_add_appkey(bt_mesh_netkey_h netkey, FUNC_ENTRY; BT_CHECK_MESH_SUPPORT(); BT_CHECK_MESH_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(netkey); BT_CHECK_INPUT_PARAMETER(appkey); netkey_s = (bt_mesh_netkey_s*)netkey; + BT_MESH_VALIDATE_HANDLE(netkey_s, netkey_list); network_s = netkey_s->parent; - BT_MESH_VALIDATE_HANDLE(network_s, networks); - BT_MESH_VALIDATE_HANDLE(netkey_s, netkey_list); memset(&net, 0x00, sizeof(bluetooth_mesh_network_t)); @@ -1529,10 +1528,11 @@ int bt_mesh_appkey_update(bt_mesh_appkey_h appkey) BT_CHECK_INPUT_PARAMETER(appkey); appkey_s = (bt_mesh_appkey_s*)appkey; + BT_MESH_VALIDATE_HANDLE(appkey_s, appkey_list); netkey_s = appkey_s->parent; + BT_MESH_VALIDATE_HANDLE(netkey_s, netkey_list); network_s = netkey_s->parent; - - BT_MESH_VALIDATE_HANDLE(appkey_s, appkey_list); + BT_MESH_VALIDATE_HANDLE(network_s, networks); memset(&net, 0x00, sizeof(bluetooth_mesh_network_t)); @@ -1565,10 +1565,11 @@ int bt_mesh_appkey_delete(bt_mesh_appkey_h appkey) BT_CHECK_INPUT_PARAMETER(appkey); appkey_s = (bt_mesh_appkey_s*)appkey; + BT_MESH_VALIDATE_HANDLE(appkey_s, appkey_list); netkey_s = appkey_s->parent; + BT_MESH_VALIDATE_HANDLE(netkey_s, netkey_list); network_s = netkey_s->parent; - - BT_MESH_VALIDATE_HANDLE(appkey_s, appkey_list); + BT_MESH_VALIDATE_HANDLE(network_s, networks); memset(&net, 0x00, sizeof(bluetooth_mesh_network_t)); @@ -2260,11 +2261,6 @@ int bt_mesh_node_configure_appkey(bt_mesh_node_h node, bt_mesh_node_key_configur if (netkey_s->parent != network_s) return BT_ERROR_INVALID_PARAMETER; - /* Return Already done, if appkey is present in the node */ - if (g_slist_find_custom(node_s->appkeys,(gconstpointer) appkey_s, - (GCompareFunc)__simple_compare)) - return BT_ERROR_ALREADY_DONE; - memset(&req, 0x00, sizeof(bluetooth_mesh_key_configure_t)); g_strlcpy(req.net_uuid, network_s->uuid, 33); @@ -2511,8 +2507,10 @@ int bt_mesh_node_foreach_netkeys(bt_mesh_node_h node, bt_mesh_node_netkey_info_c } } - g_ptr_array_foreach(netkeys, (GFunc)g_free, NULL); - g_ptr_array_free(netkeys, TRUE); + if (netkeys) { + g_ptr_array_foreach(netkeys, (GFunc)g_free, NULL); + g_ptr_array_free(netkeys, TRUE); + } FUNC_EXIT; return error_code; @@ -2522,10 +2520,8 @@ int bt_mesh_node_foreach_appkeys(bt_mesh_node_h node, bt_mesh_netkey_h netkey, bt_mesh_node_appkey_info_cb callback, void *user_data) { GPtrArray *appkeys = NULL; - GSList *l; int error_code = BT_ERROR_NONE; int i; - int total; bluetooth_mesh_node_discover_t req; uint16_t *appkey_idx = NULL; bt_mesh_network_s *network_s; @@ -2602,6 +2598,12 @@ int bt_mesh_node_foreach_appkeys(bt_mesh_node_h node, bt_mesh_netkey_h netkey, BT_INFO("Mesh: AppKey is already added in node"); } } + /* Send CallBack */ + if (!callback(BT_ERROR_NONE, (bt_mesh_node_h)node_s, appkeys->len, + (bt_mesh_netkey_h) netkey, (bt_mesh_appkey_h) appkey_local, + appkey_local->appkey_index, user_data)) { + break; + } } else { BT_ERR("Mesh: OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); @@ -2610,26 +2612,16 @@ int bt_mesh_node_foreach_appkeys(bt_mesh_node_h node, bt_mesh_netkey_h netkey, } } - total = g_slist_length(node_s->appkeys); - if (total == 0) { - BT_ERR("Mesh:Possible: No appkey added in node!!"); - callback(BT_ERROR_NONE, (bt_mesh_node_h)node_s, total, + if (appkeys->len == 0) { + BT_ERR("Mesh: No appkey configured for the bound netkey Idx [%d]", + req.netkey_idx); + callback(BT_ERROR_NONE, (bt_mesh_node_h)node_s, 0, (bt_mesh_netkey_h) netkey_s, NULL, 0xFFFF, user_data); } - for (l = node_s->appkeys; l != NULL; l = g_slist_next(l)) { - bt_mesh_appkey_s *appkey_s; - appkey_s = l->data; - - if (!callback(BT_ERROR_NONE, (bt_mesh_node_h)node_s, total, - (bt_mesh_netkey_h) netkey, (bt_mesh_appkey_h) appkey_s, - appkey_s->appkey_index, user_data)) { - break; - } + if (appkeys) { + g_ptr_array_foreach(appkeys, (GFunc)g_free, NULL); + g_ptr_array_free(appkeys, TRUE); } - - g_ptr_array_foreach(appkeys, (GFunc)g_free, NULL); - g_ptr_array_free(appkeys, TRUE); - FUNC_EXIT; return error_code; } @@ -2760,18 +2752,18 @@ int bt_mesh_model_get_appkey_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 */ |