--- mesh/net.c | 4 ++ mesh/net.h | 1 + mesh/node.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/mesh/net.c b/mesh/net.c index 7c4049e0e..2785039db 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -3945,3 +3945,7 @@ void mesh_net_set_prov(struct mesh_net *net, struct mesh_prov *prov) net->prov = prov; } +uint32_t mesh_net_get_instant(struct mesh_net *net) +{ + return net->instant; +} diff --git a/mesh/net.h b/mesh/net.h index 55e89ca72..150240ff8 100644 --- a/mesh/net.h +++ b/mesh/net.h @@ -359,3 +359,4 @@ void mesh_net_transmit_params_get(struct mesh_net *net, uint8_t *count, uint16_t *interval); struct mesh_prov *mesh_net_get_prov(struct mesh_net *net); void mesh_net_set_prov(struct mesh_net *net, struct mesh_prov *prov); +uint32_t mesh_net_get_instant(struct mesh_net *net); diff --git a/mesh/node.c b/mesh/node.c index 0d7e45c90..3d9ded3b1 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE #include <dirent.h> #include <stdio.h> +#include <sys/time.h> #include <ell/ell.h> @@ -2103,6 +2104,100 @@ static struct l_dbus_message *vendor_publish_call(struct l_dbus *dbus, return l_dbus_message_new_method_return(msg); } +static bool features_getter(struct l_dbus *dbus, struct l_dbus_message *msg, + struct l_dbus_message_builder *builder, + void *user_data) +{ + struct mesh_node *node = user_data; + uint8_t friend = node_friend_mode_get(node); + uint8_t lpn = node_lpn_mode_get(node); + uint8_t proxy = node_proxy_mode_get(node); + uint8_t count; + uint16_t interval; + uint8_t relay = node_relay_mode_get(node, &count, &interval); + + l_dbus_message_builder_enter_array(builder, "{sv}"); + + if (friend != MESH_MODE_UNSUPPORTED) + dbus_append_dict_entry_basic(builder, "Friend", "b", &friend); + + if (lpn != MESH_MODE_UNSUPPORTED) + dbus_append_dict_entry_basic(builder, "LowPower", "b", &lpn); + + if (proxy != MESH_MODE_UNSUPPORTED) + dbus_append_dict_entry_basic(builder, "Proxy", "b", &proxy); + + if (relay != MESH_MODE_UNSUPPORTED) + dbus_append_dict_entry_basic(builder, "Relay", "b", &relay); + + l_dbus_message_builder_leave_array(builder); + + return true; +} + +static bool beacon_getter(struct l_dbus *dbus, struct l_dbus_message *msg, + struct l_dbus_message_builder *builder, + void *user_data) +{ + struct mesh_node *node = user_data; + bool beacon_mode = node_beacon_mode_get(node) == MESH_MODE_ENABLED; + + l_dbus_message_builder_append_basic(builder, 'b', &beacon_mode); + + return true; +} + +static bool beaconflags_getter(struct l_dbus *dbus, struct l_dbus_message *msg, + struct l_dbus_message_builder *builder, + void *user_data) +{ + struct mesh_node *node = user_data; + struct mesh_net *net = node_get_net(node); + uint8_t flags; + uint32_t iv_index; + + mesh_net_get_snb_state(net, &flags, &iv_index); + + l_dbus_message_builder_append_basic(builder, 'y', &flags); + + return true; +} + +static bool ivindex_getter(struct l_dbus *dbus, struct l_dbus_message *msg, + struct l_dbus_message_builder *builder, + void *user_data) +{ + struct mesh_node *node = user_data; + struct mesh_net *net = node_get_net(node); + uint8_t flags; + uint32_t iv_index; + + mesh_net_get_snb_state(net, &flags, &iv_index); + + l_dbus_message_builder_append_basic(builder, 'u', &iv_index); + + return true; +} + +static bool lastheard_getter(struct l_dbus *dbus, struct l_dbus_message *msg, + struct l_dbus_message_builder *builder, + void *user_data) +{ + struct mesh_node *node = user_data; + struct mesh_net *net = node_get_net(node); + struct timeval now; + uint32_t last_heard; + + gettimeofday(&now, NULL); + + last_heard = now.tv_sec - mesh_net_get_instant(net); + + l_dbus_message_builder_append_basic(builder, 'u', &last_heard); + + return true; + +} + static void setup_node_interface(struct l_dbus_interface *iface) { l_dbus_interface_method(iface, "Send", 0, send_call, "", "oqqay", @@ -2118,7 +2213,15 @@ static void setup_node_interface(struct l_dbus_interface *iface) "", "oqqay", "element_path", "vendor", "model_id", "data"); - /* TODO: Properties */ + l_dbus_interface_property(iface, "Features", 0, "a{sv}", features_getter, + NULL); + l_dbus_interface_property(iface, "Beacon", 0, "b", beacon_getter, NULL); + l_dbus_interface_property(iface, "BeaconFlags", 0, "b", + beaconflags_getter, NULL); + l_dbus_interface_property(iface, "IvIndex", 0, "u", ivindex_getter, + NULL); + l_dbus_interface_property(iface, "SecondsSinceLastHeard", 0, "u", + lastheard_getter, NULL); } bool node_dbus_init(struct l_dbus *bus) -- 2.19.1