_bt_mesh_event_cb(BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED,
result, info,
event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_MESH_MODEL_APPKEY_CONFIGURED) == 0) {
+ int result;
+ GVariant *param = NULL;
+ GArray *dbus_data = NULL;
+ bluetooth_mesh_model_configure_t *info = NULL;
+
+ g_variant_get(parameters, "(iv)", &result, ¶m);
+ dbus_data = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+ __bt_fill_garray_from_variant(param, dbus_data);
+ g_variant_unref(param);
+
+ info = &g_array_index(dbus_data, bluetooth_mesh_model_configure_t, 0);
+
+ _bt_mesh_event_cb(BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND,
+ result, info,
+ event_info->cb, event_info->user_data);
} else if (strcasecmp(signal_name, BT_MESH_MODEL_APPKEY_LIST) == 0) {
int result;
GVariantIter *iter = NULL;
uint16_t appkey_idx;
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));
info.elem_index = elem_idx;
info.model = model;
info.appkeylist_count = total;
-
+ BT_INFO("Mesh: Total appkeys bound to model [%d]", total);
if (total) {
info.appkey_list = (uint16_t**)g_malloc0(sizeof(uint16_t*) * total);
result, &info,
event_info->cb, event_info->user_data);
- if (total) {
- for (i = 0; i < total; i++)
- g_free(info.appkey_list[i]);
+ for (i = 0; i < total; i++)
+ g_free(info.appkey_list[i]);
+ if (info.appkey_list) {
+ g_free(info.appkey_list);
g_variant_iter_free(iter);
}
+
} else if (strcasecmp(signal_name, BT_MESH_MODEL_SUB_LIST) == 0) {
int result;
GVariantIter *iter = NULL;
break;
case BT_MESH_MODEL_CONFIGURE_APPKEY:
*event_type = BT_MESH_EVENT;
- *event = BLUETOOTH_EVENT_MESH_NODE_MODEL_APPKEY_BIND;
+ *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND;
ret_if(output == NULL);
*param_data = &g_array_index(output,
bluetooth_mesh_model_configure_t, 0);
case BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED:
signal = BT_MESH_NODE_TTL_CONFIGURED;
break;
- case BLUETOOTH_EVENT_MESH_NODE_MODEL_APPKEY_BIND:
+ case BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND:
signal = BT_MESH_MODEL_APPKEY_CONFIGURED;
break;
case BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST:
uint16_t unicast, GArray **out);
bool _bt_mesh_node_get_all_appkeys(uint8_t net_uuid[],
- uint16_t unicast, GArray **out);
+ uint16_t unicast, uint16_t netkey_idx, GArray **out);
#ifdef __cplusplus
}
{
GVariant *param = NULL;
GVariantBuilder *builder = NULL;
+ char *net_uuid;
int i;
if (BLUETOOTH_ERROR_NONE == result) {
-
- if (evt->appkeylist_count) {
- builder = g_variant_builder_new(G_VARIANT_TYPE("aq"));
- for (i = 0; i < evt->appkeylist_count; i++)
- g_variant_builder_add(builder, "q", *evt->appkey_list[i]);
-
- param = g_variant_new("(isqiui(aq))", result, evt->net_uuid,
- evt->primary_unicast, evt->elem_index, evt->model,
- evt->appkeylist_count, builder);
-
- g_variant_builder_unref(builder);
- }
+ builder = g_variant_builder_new(G_VARIANT_TYPE("aq"));
+ BT_INFO("Mesh: Total AppKeys bound to model [%d]",
+ evt->appkeylist_count);
+ BT_INFO("Mesh: Network [%s]", evt->net_uuid);
+ for (i = 0; i < evt->appkeylist_count; i++)
+ g_variant_builder_add(builder, "q", *evt->appkey_list[i]);
+ 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->appkeylist_count, builder);
+
+ g_variant_builder_unref(builder);
/* Send event */
_bt_send_event(BT_MESH_EVENT,
param);
if (evt->appkeylist_count) {
- /* Free List data */
for (int i = 0; i < evt->appkeylist_count; i++)
g_free(evt->appkey_list[i]);
+
g_free(evt->appkey_list);
}
+ /* Free List data */
+ g_free(net_uuid);
}
}
param = g_variant_new("(iv)", result, out_var);
_bt_send_event(BT_MESH_EVENT,
- BLUETOOTH_EVENT_MESH_NODE_MODEL_APPKEY_BIND,
+ BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND,
param);
}
}
BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
BT_INFO("Node %4.4x: Model App status %s\n", event->source,
__mesh_status_to_string(data[0]));
+
+ if (data[0] != MESH_STATUS_SUCCESS)
+ result = BLUETOOTH_ERROR_INTERNAL;
+
elem_addr = l_get_le16(data + 1);
app_idx = l_get_le16(data + 3);
BT_INFO("\tNetKey %u (0x%3.3x)", net_idx, net_idx);
if (data[0] != 0)
- break;
+ result = BLUETOOTH_ERROR_INTERNAL;
if (!cmd)
break;
param.netkey_idx = net_idx;
param.is_netkey = true;
+ BT_INFO("Mesh: Resp recvd from node unicast [0x%4.4x]", event->source);
if (cmd->opcode == MESH_OPCODE_NETKEY_ADD) {
BT_INFO("Mesh: Resp recvd: MESH_OPCODE_NETKEY_ADD");
- if (!_bt_mesh_network_save_remote_node_netkey(
- event->net_uuid.uuid, event->source, net_idx)) {
- result = BLUETOOTH_ERROR_INTERNAL;
- BT_INFO("Failed to save node Netkey!");
+ if (result == BLUETOOTH_ERROR_NONE) {
+ if (!_bt_mesh_network_save_remote_node_netkey(
+ event->net_uuid.uuid, event->source, net_idx)) {
+ result = BLUETOOTH_ERROR_INTERNAL;
+ BT_INFO("Failed to save node Netkey!");
+ }
}
param.op = BLUETOOTH_MESH_NODE_KEY_ADD;
} else if (cmd->opcode == MESH_OPCODE_NETKEY_DELETE) {
- if (!_bt_mesh_network_delete_remote_node_netkey(
- event->net_uuid.uuid, event->source, net_idx)) {
- result = BLUETOOTH_ERROR_INTERNAL;
- BT_INFO("Failed to delete node Netkey!");
+ BT_INFO("Mesh: Resp recvd: MESH_OPCODE_NETKEY_DELETE");
+ if (result == BLUETOOTH_ERROR_NONE) {
+ if (!_bt_mesh_network_delete_remote_node_netkey(
+ event->net_uuid.uuid, event->source, net_idx)) {
+ result = BLUETOOTH_ERROR_INTERNAL;
+ BT_INFO("Failed to delete node Netkey!");
+ }
}
param.op = BLUETOOTH_MESH_NODE_KEY_DELETE;
} else if (cmd->opcode == MESH_OPCODE_NETKEY_UPDATE) {
BT_INFO("AppKey\t%u (0x%3.3x)\n", app_idx, app_idx);
if (data[0] != MESH_STATUS_SUCCESS)
- break;
+ result = BLUETOOTH_ERROR_INTERNAL;
if (!cmd)
break;
if (cmd->opcode == MESH_OPCODE_APPKEY_ADD) {
BT_INFO("Mesh: Resp recvd: MESH_OPCODE_APPKEY_ADD");
- if (!_bt_mesh_network_save_remote_node_appkey(
- event->net_uuid.uuid, event->source,
- net_idx, app_idx)) {
- result = BLUETOOTH_ERROR_INTERNAL;
- BT_INFO("Failed to save node Appkey!");
+ if (result == BLUETOOTH_ERROR_NONE) {
+ if (!_bt_mesh_network_save_remote_node_appkey(
+ event->net_uuid.uuid, event->source,
+ net_idx, app_idx)) {
+ result = BLUETOOTH_ERROR_INTERNAL;
+ BT_INFO("Failed to save node Appkey!");
+ }
}
param.op = BLUETOOTH_MESH_NODE_KEY_ADD;
} else if (cmd->opcode == MESH_OPCODE_APPKEY_DELETE) {
BT_INFO("Mesh: Resp recvd: MESH_OPCODE_APPKEY_DELETE");
- if (!_bt_mesh_network_delete_remote_node_appkey(
- event->net_uuid.uuid, event->source,
- net_idx, app_idx)) {
- result = BLUETOOTH_ERROR_INTERNAL;
- BT_INFO("Failed to delete node Appkey!");
+ if (result == BLUETOOTH_ERROR_NONE) {
+ if (!_bt_mesh_network_delete_remote_node_appkey(
+ event->net_uuid.uuid, event->source,
+ net_idx, app_idx)) {
+ result = BLUETOOTH_ERROR_INTERNAL;
+ BT_INFO("Failed to delete node Appkey!");
+ }
}
param.op = BLUETOOTH_MESH_NODE_KEY_DELETE;
} else if (cmd->opcode == MESH_OPCODE_APPKEY_UPDATE) {
cdb_cfg = (_bt_mesh_cdb_t*)l->data;
if (_bt_mesh_node_get_all_appkeys(cdb_cfg->uuid,
- node->unicast, out_param))
+ node->unicast, node->netkey_idx, out_param))
return BLUETOOTH_ERROR_NONE;
else
return BLUETOOTH_ERROR_INTERNAL;
GSList *l;
_bt_mesh_cdb_t *cdb_cfg = NULL;
+ BT_INFO("Mesh: Add Appkey [0x%2.2x] to node", appkey_idx);
/* Find CDB */
l = g_slist_find_custom(cdb_list, net_uuid,
__mesh_compare_app_network_uuid);
cdb_cfg = (_bt_mesh_cdb_t*)l->data;
if (_bt_mesh_node_is_appkey_exists(net_uuid,
- remote_unicast, netkey_idx)) {
+ remote_unicast, appkey_idx)) {
BT_INFO("Mesh: AppKey is already added to Node");
return true;
}
if (_bt_mesh_node_add_app_key(net_uuid,
- remote_unicast, appkey_idx))
+ remote_unicast, appkey_idx)) {
+ BT_INFO("Mesh: Add App Key Idx [0x%2.2x] in CDB", appkey_idx);
return _bt_mesh_conf_node_insert_application_key(cdb_cfg,
remote_unicast, appkey_idx);
+ }
+ BT_INFO("Mesh: AppKey idx [0x%2.2x] Failed to add in Node", appkey_idx);
return false;
}
{
GSList *l;
_bt_mesh_cdb_t *cdb_cfg = NULL;
+ bool is_deleted = false;
+ BT_INFO("Mesh: Delete Appkey Idx[0x%2.2x]from Node Unicast [0x%2.2x]",
+ appkey_idx, remote_unicast);
/* Find CDB */
l = g_slist_find_custom(cdb_list, net_uuid,
__mesh_compare_app_network_uuid);
cdb_cfg = (_bt_mesh_cdb_t*)l->data;
- if (_bt_mesh_node_del_net_key(cdb_cfg,
- net_uuid, remote_unicast, appkey_idx))
- return _bt_mesh_conf_node_delete_application_key(cdb_cfg,
+ if (_bt_mesh_node_del_app_key(net_uuid,
+ remote_unicast, appkey_idx)) {
+ BT_INFO("Mesh: Removed Appkey from node");
+ is_deleted = _bt_mesh_conf_node_delete_application_key(cdb_cfg,
remote_unicast, appkey_idx);
+ if (is_deleted)
+ BT_INFO("Mesh: AppKey removed from CDB Node Entry");
+ else
+ BT_INFO("Mesh: AppKey could not be removed from CDB Node Entry");
+ }
- return false;
+ return is_deleted;
}
bool _bt_mesh_network_save_remote_node_ttl(
}
bool _bt_mesh_node_get_all_appkeys(uint8_t net_uuid[],
- uint16_t unicast, GArray **out)
+ uint16_t unicast, uint16_t netkey, GArray **out)
{
struct mesh_network_t *network;
const struct l_queue_entry *entry;
entry = l_queue_get_entries(rmt->app_keys);
for (; entry; entry = entry->next) {
-
+ uint16_t net_idx;
uint16_t app_idx = L_PTR_TO_UINT(entry->data);
-
- g_array_append_vals(*out, &app_idx, sizeof(uint16_t));
+ net_idx = _bt_mesh_keys_get_bound_key(net_uuid, app_idx);
+ if (net_idx == netkey)
+ g_array_append_vals(*out, &app_idx, sizeof(uint16_t));
}
return true;
}
return false;
l_queue_push_tail(rmt->app_keys, L_UINT_TO_PTR(app_idx));
+ BT_INFO("Mesh: Total appkeys present in node [%d]",
+ l_queue_length(rmt->app_keys));
return true;
}
network = l_queue_find(networks,
__mesh_net_uuid_match, net_uuid);
- if (!network)
+ if (!network) {
+ BT_INFO("Mesh: Could not find Network");
return false;
+ }
rmt = l_queue_find(network->nodes,
__mesh_match_node_addr, L_UINT_TO_PTR(addr));
- if (!rmt)
+ if (!rmt) {
+ BT_INFO("Mesh: Remote Node not found!");
return false;
+ }
+ BT_INFO("Mesh: Total appkeys present in node [%d]",
+ l_queue_length(rmt->app_keys));
+ BT_INFO("Mesh: To be deleted AppKey Idx [0x%2.2x]", app_idx);
return l_queue_remove(rmt->app_keys, L_UINT_TO_PTR(app_idx));
}
BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES,
BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED,
BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED,
- BLUETOOTH_EVENT_MESH_NODE_MODEL_APPKEY_BIND,
+ BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND,
BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST,
BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST,
BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED,