From cba0d7df9a4a75ccd43b52d3af070b3e74b596fe Mon Sep 17 00:00:00 2001 From: Anupam Roy Date: Fri, 31 Jul 2020 16:28:48 +0530 Subject: [PATCH] Mesh: Fix issues in Mesh Model Subscrition This patch fixes issues in following operations - Get Mesh BT SIG & Vendor Model Subscription List - Add missing Command timeout handling - Fix gdbus data format for sending Model list - Add missing privilege for Model Subscription List API Change-Id: I671b3f109ae1b2c752115d30dcb26783e7133e1d Signed-off-by: Anupam Roy --- bt-api/bt-event-handler.c | 11 ++- bt-service/services/bt-request-handler.c | 1 + .../services/mesh/bt-service-mesh-config-client.c | 93 ++++++++++++++++------ 3 files changed, 77 insertions(+), 28 deletions(-) diff --git a/bt-api/bt-event-handler.c b/bt-api/bt-event-handler.c index abdecd3..aacef10 100644 --- a/bt-api/bt-event-handler.c +++ b/bt-api/bt-event-handler.c @@ -630,7 +630,7 @@ static void __bt_mesh_event_filter(GDBusConnection *connection, uint16_t sub_addr; int i; - g_variant_get(parameters, "(i&sqiui(ay))", &result, &net_uuid, + g_variant_get(parameters, "(i&sqiui(aq))", &result, &net_uuid, &node_unicast, &elem_idx, &model, &total, &iter); memset(&info, 0x00, sizeof(bluetooth_mesh_model_configure_t)); @@ -640,11 +640,13 @@ static void __bt_mesh_event_filter(GDBusConnection *connection, info.model = model; info.sublist_count = total; + BT_INFO("Mesh: Total Subscriptions Bound to model [%d]", total); if (total) { info.sub_list = (uint16_t**)g_malloc0(sizeof(uint16_t*) * total); for (i = 0; i < total && g_variant_iter_loop(iter, "q", &sub_addr); ++i) { info.sub_list[i] = g_malloc0(sizeof(uint16_t)); *info.sub_list[i] = sub_addr; + BT_INFO("Mesh: Subscription Address [0x%2.2x]", sub_addr); } } @@ -652,9 +654,10 @@ static void __bt_mesh_event_filter(GDBusConnection *connection, result, &info, event_info->cb, event_info->user_data); - if (total) { - for (i = 0; i < total; i++) - g_free(info.sub_list[i]); + for (i = 0; i < total; i++) + g_free(info.sub_list[i]); + if (info.appkey_list) { + g_free(info.sub_list); g_variant_iter_free(iter); } } else if (strcasecmp(signal_name, BT_MESH_NODE_TTL_CONFIGURED) == 0) { diff --git a/bt-service/services/bt-request-handler.c b/bt-service/services/bt-request-handler.c index 91418a8..843b2f7 100644 --- a/bt-service/services/bt-request-handler.c +++ b/bt-service/services/bt-request-handler.c @@ -5105,6 +5105,7 @@ gboolean __bt_service_check_privilege(int function_name, case BT_MESH_NETWORK_REMOVE_GROUP: case BT_MESH_MODEL_CONFIG_GROUP_SUB: case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB: + case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST: case BT_MESH_MODEL_SET_PUBLICATION: case BT_MESH_MODEL_GET_PUBLICATION: case BT_MESH_NETWORK_GET_GROUPS: diff --git a/bt-service/services/mesh/bt-service-mesh-config-client.c b/bt-service/services/mesh/bt-service-mesh-config-client.c index d1ca68c..7dd440a 100644 --- a/bt-service/services/mesh/bt-service-mesh-config-client.c +++ b/bt-service/services/mesh/bt-service-mesh-config-client.c @@ -261,6 +261,15 @@ static void __bt_mesh_wait_response_timeout( g_free(event); break; } + case MESH_OPCODE_CONFIG_MODEL_SUB_GET: + case MESH_OPCODE_CONFIG_VEND_MODEL_SUB_GET: + BT_INFO("Mesh: Command TimedOut: Model Subscription list get"); + /* Send event with timeout */ + __bt_mesh_handle_pending_dev_config_request_info( + BLUETOOTH_ERROR_TIMEOUT, + BT_MESH_MODEL_GET_SUBSCRIPTION_LIST, req->data, + sizeof(bluetooth_mesh_model_configure_t)); + break; case MESH_OPCODE_NETKEY_ADD: case MESH_OPCODE_NETKEY_UPDATE: case MESH_OPCODE_NETKEY_DELETE: @@ -283,7 +292,6 @@ static void __bt_mesh_wait_response_timeout( 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( @@ -300,6 +308,18 @@ static void __bt_mesh_wait_response_timeout( BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, req->data, sizeof(bluetooth_mesh_model_configure_t)); break; + case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL: + /* 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)); + /* 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; default: break; } @@ -524,19 +544,26 @@ static void __bt_mesh_send_model_get_subscription_list_event( GVariant *param = NULL; GVariantBuilder *builder = NULL; int i; + char *net_uuid; if (BLUETOOTH_ERROR_NONE == result) { - if (evt->sublist_count) { - builder = g_variant_builder_new(G_VARIANT_TYPE("aq")); - for (i = 0; i < evt->sublist_count; i++) - g_variant_builder_add(builder, "q", *evt->sub_list[i]); + BT_INFO("Mesh: Total Subscriptions bound to model [%d]", + evt->sublist_count); + BT_INFO("Mesh: Network [%s]", evt->net_uuid); + builder = g_variant_builder_new(G_VARIANT_TYPE("aq")); + for (i = 0; i < evt->sublist_count; i++) { + BT_INFO("Mesh: Subscription Address [0x%2.2x]", + *evt->sub_list[i]); + g_variant_builder_add(builder, "q", *evt->sub_list[i]); + } - param = g_variant_new("(isqiui(aq))", result, evt->net_uuid, - evt->primary_unicast, evt->elem_index, evt->model, - evt->sublist_count, builder); + net_uuid = g_strdup(evt->net_uuid); + param = g_variant_new("(isqiui(aq))", result, net_uuid, + evt->primary_unicast, evt->elem_index, evt->model, + evt->sublist_count, builder); + + g_variant_builder_unref(builder); - g_variant_builder_unref(builder); - } /* Send event */ _bt_send_event(BT_MESH_EVENT, BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST, @@ -548,6 +575,8 @@ static void __bt_mesh_send_model_get_subscription_list_event( g_free(evt->sub_list[i]); g_free(evt->sub_list); } + g_free(net_uuid); + BT_INFO("freed net uuid"); } } @@ -883,6 +912,7 @@ static void __bt_mesh_handle_pending_dev_config_request_info(int result, bluetooth_mesh_model_configure_t *event; bluetooth_mesh_model_configure_t *req; + BT_INFO("Mesh: Handle event for BT_MESH_MODEL_GET_SUBSCRIPTION_LIST"); event = (bluetooth_mesh_model_configure_t*) param; req = (bluetooth_mesh_model_configure_t*)req_info->user_data; @@ -1053,7 +1083,6 @@ static void __mesh_handle_model_subscription_event(int result, case MESH_OPCODE_CONFIG_MODEL_SUB_ADD: case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE: 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, @@ -1068,6 +1097,15 @@ static void __mesh_handle_model_subscription_event(int result, BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, param, sizeof(bluetooth_mesh_model_configure_t)); break; + case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL: + BT_INFO("Mesh: Handle Event for Request: MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL"); + __bt_mesh_handle_pending_dev_config_request_info(result, + BT_MESH_MODEL_CONFIG_GROUP_SUB, param, + sizeof(bluetooth_mesh_model_configure_t)); + __bt_mesh_handle_pending_dev_config_request_info(result, + BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, param, + sizeof(bluetooth_mesh_model_configure_t)); + break; default: break; } @@ -1372,17 +1410,18 @@ void _bt_mesh_config_client_devkey_msg_handler( param.primary_unicast = event->source; param.elem_index = elem_addr - event->source; param.model = mod_id; - - total = data_len - 5; + BT_INFO("Mesh: Data length of All Models Together [%d]", data_len - 5); + total = (data_len - 5)/2; param.sublist_count = total; + BT_INFO("Mesh: Total Number of subscriptions [%d]", total); if (total) { param.sub_list = (uint16_t **)g_malloc0(sizeof(uint16_t*) * total); i = 5; - for (; i < data_len; i += 2) { - BT_INFO("Subscription Addr \t\t%4.4x\n ", l_get_le16(data + i)); - param.sub_list[i] = g_malloc(sizeof(uint16_t)); - *param.sub_list[i] = l_get_le16(data + i); + for (int k = 0; i < data_len; k++, i += 2) { + BT_INFO("Mesh: Subscription Addr \t\t%4.4x\n ", l_get_le16(data + i)); + param.sub_list[k] = g_malloc(sizeof(uint16_t)); + *param.sub_list[k] = l_get_le16(data + i); } } __bt_mesh_handle_pending_dev_config_request_info(result, @@ -1402,7 +1441,7 @@ void _bt_mesh_config_client_devkey_msg_handler( (uint8_t *) event->net_uuid.uuid, 16, param.net_uuid, BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1); - BT_INFO("\nNode %4.4x BT SIG Model Subscription List status %s\n", + BT_INFO("\nNode %4.4x Vendor Model Subscription List status %s\n", event->source, __mesh_status_to_string(data[0])); BT_INFO("Element Addr\t%4.4x\n", l_get_le16(data + 1)); @@ -1418,16 +1457,19 @@ void _bt_mesh_config_client_devkey_msg_handler( param.elem_index = elem_addr - event->source; param.model = mod_id; - total = data_len - 7; + BT_INFO("Mesh: Data length of All Models Together [%d]", data_len - 7); + total = (data_len - 7)/2; param.sublist_count = total; + + BT_INFO("Mesh: Total Number of subscriptions [%d]", total); if (total) { param.sub_list = (uint16_t **)g_malloc0(sizeof(uint16_t*) * total); i = 7; - for (; i < data_len; i += 2) { - BT_INFO("Subscription Addr \t\t%4.4x\n ", l_get_le16(data + i)); - param.sub_list[i] = g_malloc(sizeof(uint16_t)); - *param.sub_list[i] = l_get_le16(data + i); + for (int k = 0; i < data_len; k++, i += 2) { + BT_INFO("Mesh: Subscription Addr \t\t%4.4x\n ", l_get_le16(data + i)); + param.sub_list[k] = g_malloc(sizeof(uint16_t)); + *param.sub_list[k] = l_get_le16(data + i); } } __bt_mesh_handle_pending_dev_config_request_info(result, @@ -1878,6 +1920,8 @@ int _bt_mesh_model_configure_virtual_group_subscription( opcode = MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_DELETE; else if (req->op == BLUETOOTH_MESH_MODEL_SUB_OVERWRITE) opcode = MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_OVERWRITE; + else if (req->op == BLUETOOTH_MESH_MODEL_SUB_DELETE_ALL) + opcode = MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL; /* Check pending request */ if (_bt_mesh_check_pending_request(opcode, @@ -2153,13 +2197,14 @@ int _bt_mesh_node_model_get_subscription_list(const char *app_cred, const char * l_put_le16((req->primary_unicast + req->elem_index), buffer + data_len); data_len += 2; - /* Insert Model ID */ if (opcode == MESH_OPCODE_CONFIG_MODEL_SUB_GET) { + BT_INFO("Mesh: Get Subscription List for BT SIG Model"); /* 1st 2 octet Company ID is 0xFFFF means, it is BT SIG Model*/ l_put_le16(req->model & 0x0000FFFF, buffer + data_len); data_len += 2; } else { + BT_INFO("Mesh: Get Subscription List for Vendor Model"); /* Vendor Model, 1st 2 octetes: Company ID, next 2 octets: Vendor Model ID */ l_put_le16(req->model & 0xFFFF0000, buffer + data_len); data_len += 2; -- 2.7.4