--- mesh/model.c | 7 +++++++ mesh/node.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/mesh/model.c b/mesh/model.c index 6cd630aa9..f46cce7c1 100644 --- a/mesh/model.c +++ b/mesh/model.c @@ -956,6 +956,7 @@ bool mesh_model_send(struct mesh_node *node, uint16_t src, uint16_t target, const void *msg, uint16_t msg_len) { uint8_t key_id; + uint8_t dev_key[16]; const uint8_t *key; /* print_packet("Mod Tx", msg, msg_len); */ @@ -976,6 +977,12 @@ bool mesh_model_send(struct mesh_node *node, uint16_t src, uint16_t target, l_debug("(%x)", app_idx); key_id = APP_ID_DEV; + } else if (app_idx == APP_IDX_DEV_REMOTE) { + if (!keyring_get_remote_dev_key(node, target, dev_key)) + return false; + + key_id = APP_ID_DEV; + key = dev_key; } else { key = appkey_get_key(node_get_net(node), app_idx, &key_id); if (!key) { diff --git a/mesh/node.c b/mesh/node.c index a2ac747a1..5733cd4ff 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -1969,6 +1969,52 @@ static struct l_dbus_message *send_call(struct l_dbus *dbus, return reply; } +static struct l_dbus_message *dev_key_send_call(struct l_dbus *dbus, + struct l_dbus_message *msg, + void *user_data) +{ + struct mesh_node *node = user_data; + const char *sender, *ele_path; + struct l_dbus_message_iter iter_data; + struct node_element *ele; + uint16_t dst, net_idx, src; + uint8_t *data; + uint32_t len; + struct l_dbus_message *reply; + + l_debug("DevKeySend"); + + sender = l_dbus_message_get_sender(msg); + + if (strcmp(sender, node->owner)) + return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL); + + if (!l_dbus_message_get_arguments(msg, "oqqay", &ele_path, &dst, + &net_idx, &iter_data)) + return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL); + + ele = l_queue_find(node->elements, match_element_path, ele_path); + if (!ele) + return dbus_error(msg, MESH_ERROR_NOT_FOUND, + "Element not found"); + + src = node_get_primary(node) + ele->idx; + + if (!l_dbus_message_iter_get_fixed_array(&iter_data, &data, &len) || + !len || len > MESH_MAX_ACCESS_PAYLOAD) + return dbus_error(msg, MESH_ERROR_INVALID_ARGS, + "Incorrect data"); + + if (!mesh_model_send(node, src, dst, APP_IDX_DEV_REMOTE, + mesh_net_get_default_ttl(node->net), data, len)) + return dbus_error(msg, MESH_ERROR_FAILED, NULL); + + reply = l_dbus_message_new_method_return(msg); + l_dbus_message_set_arguments(reply, ""); + + return reply; +} + static struct l_dbus_message *publish_call(struct l_dbus *dbus, struct l_dbus_message *msg, void *user_data) @@ -2075,6 +2121,9 @@ static void setup_node_interface(struct l_dbus_interface *iface) l_dbus_interface_method(iface, "Send", 0, send_call, "", "oqqay", "element_path", "destination", "key", "data"); + l_dbus_interface_method(iface, "DevKeySend", 0, dev_key_send_call, + "", "oqqay", "element_path", + "destination", "net", "data"); l_dbus_interface_method(iface, "Publish", 0, publish_call, "", "oqay", "element_path", "model_id", "data"); l_dbus_interface_method(iface, "VendorPublish", 0, vendor_publish_call, -- 2.19.1