linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ v2 0/2] mesh: Implement org.bluez.mesh.Node1 properties
@ 2019-08-28  7:52 Michał Lowas-Rzechonek
  2019-08-28  7:52 ` [PATCH BlueZ v2 1/2] mesh: Implement properties on org.bluez.mesh.Node1 interface Michał Lowas-Rzechonek
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-08-28  7:52 UTC (permalink / raw)
  To: linux-bluetooth

This patch-set implements previously defined properties on Node1
interface and adds an additional read-only property with list of unicast
addresses claimed by the node.

Michał Lowas-Rzechonek (2):
  mesh: Implement properties on org.bluez.mesh.Node1 interface
  mesh: Add org.bluez.mesh.Node1.Addresses property

 doc/mesh-api.txt |   4 ++
 mesh/net.c       |   4 ++
 mesh/net.h       |   1 +
 mesh/node.c      | 129 ++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 137 insertions(+), 1 deletion(-)

-- 
2.19.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH BlueZ v2 1/2] mesh: Implement properties on org.bluez.mesh.Node1 interface
  2019-08-28  7:52 [PATCH BlueZ v2 0/2] mesh: Implement org.bluez.mesh.Node1 properties Michał Lowas-Rzechonek
@ 2019-08-28  7:52 ` Michał Lowas-Rzechonek
  2019-08-28  7:52 ` [PATCH BlueZ v2 2/2] mesh: Add org.bluez.mesh.Node1.Addresses property Michał Lowas-Rzechonek
  2019-08-28 16:45 ` [PATCH BlueZ v2 0/2] mesh: Implement org.bluez.mesh.Node1 properties Gix, Brian
  2 siblings, 0 replies; 4+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-08-28  7:52 UTC (permalink / raw)
  To: linux-bluetooth

---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH BlueZ v2 2/2] mesh: Add org.bluez.mesh.Node1.Addresses property
  2019-08-28  7:52 [PATCH BlueZ v2 0/2] mesh: Implement org.bluez.mesh.Node1 properties Michał Lowas-Rzechonek
  2019-08-28  7:52 ` [PATCH BlueZ v2 1/2] mesh: Implement properties on org.bluez.mesh.Node1 interface Michał Lowas-Rzechonek
@ 2019-08-28  7:52 ` Michał Lowas-Rzechonek
  2019-08-28 16:45 ` [PATCH BlueZ v2 0/2] mesh: Implement org.bluez.mesh.Node1 properties Gix, Brian
  2 siblings, 0 replies; 4+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-08-28  7:52 UTC (permalink / raw)
  To: linux-bluetooth

To enable applications to talk to the local node's internal models, it's
useful to know its unicast addresses. They are known after CreateNetwork
and Import, but after Join, the allocated address is only known to the
provisioner.

This patch enables read only access to list of allocated unicast
addresses.
---
 doc/mesh-api.txt |  4 ++++
 mesh/node.c      | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/doc/mesh-api.txt b/doc/mesh-api.txt
index 255104ab6..470751f7a 100644
--- a/doc/mesh-api.txt
+++ b/doc/mesh-api.txt
@@ -423,6 +423,10 @@ Properties:
 		seconds since mesh network layer traffic was last detected on
 		this node's network.
 
+	array{uint16} Addresses [read-only]
+
+		This property contains unicast addresses of node's elements.
+
 Mesh Provisioning Hierarchy
 ============================
 Service		org.bluez.mesh
diff --git a/mesh/node.c b/mesh/node.c
index 3d9ded3b1..b6824f505 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -2198,6 +2198,28 @@ static bool lastheard_getter(struct l_dbus *dbus, struct l_dbus_message *msg,
 
 }
 
+static bool addresses_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;
+	const struct l_queue_entry *entry;
+
+	l_dbus_message_builder_enter_array(builder, "q");
+
+	entry = l_queue_get_entries(node->elements);
+	for (; entry; entry = entry->next) {
+		const struct node_element *ele = entry->data;
+		uint16_t address = node->primary + ele->idx;
+
+		l_dbus_message_builder_append_basic(builder, 'q', &address);
+	}
+
+	l_dbus_message_builder_leave_array(builder);
+
+	return true;
+}
+
 static void setup_node_interface(struct l_dbus_interface *iface)
 {
 	l_dbus_interface_method(iface, "Send", 0, send_call, "", "oqqay",
@@ -2222,6 +2244,8 @@ static void setup_node_interface(struct l_dbus_interface *iface)
 									NULL);
 	l_dbus_interface_property(iface, "SecondsSinceLastHeard", 0, "u",
 					lastheard_getter, NULL);
+	l_dbus_interface_property(iface, "Addresses", 0, "aq", addresses_getter,
+									NULL);
 }
 
 bool node_dbus_init(struct l_dbus *bus)
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH BlueZ v2 0/2] mesh: Implement org.bluez.mesh.Node1 properties
  2019-08-28  7:52 [PATCH BlueZ v2 0/2] mesh: Implement org.bluez.mesh.Node1 properties Michał Lowas-Rzechonek
  2019-08-28  7:52 ` [PATCH BlueZ v2 1/2] mesh: Implement properties on org.bluez.mesh.Node1 interface Michał Lowas-Rzechonek
  2019-08-28  7:52 ` [PATCH BlueZ v2 2/2] mesh: Add org.bluez.mesh.Node1.Addresses property Michał Lowas-Rzechonek
@ 2019-08-28 16:45 ` Gix, Brian
  2 siblings, 0 replies; 4+ messages in thread
From: Gix, Brian @ 2019-08-28 16:45 UTC (permalink / raw)
  To: michal.lowas-rzechonek, linux-bluetooth

Applied

On Wed, 2019-08-28 at 09:52 +0200, Michał Lowas-Rzechonek wrote:
> This patch-set implements previously defined properties on Node1
> interface and adds an additional read-only property with list of unicast
> addresses claimed by the node.
> 
> Michał Lowas-Rzechonek (2):
>   mesh: Implement properties on org.bluez.mesh.Node1 interface
>   mesh: Add org.bluez.mesh.Node1.Addresses property
> 
>  doc/mesh-api.txt |   4 ++
>  mesh/net.c       |   4 ++
>  mesh/net.h       |   1 +
>  mesh/node.c      | 129 ++++++++++++++++++++++++++++++++++++++++++++++-
>  4 files changed, 137 insertions(+), 1 deletion(-)
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-28 16:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-28  7:52 [PATCH BlueZ v2 0/2] mesh: Implement org.bluez.mesh.Node1 properties Michał Lowas-Rzechonek
2019-08-28  7:52 ` [PATCH BlueZ v2 1/2] mesh: Implement properties on org.bluez.mesh.Node1 interface Michał Lowas-Rzechonek
2019-08-28  7:52 ` [PATCH BlueZ v2 2/2] mesh: Add org.bluez.mesh.Node1.Addresses property Michał Lowas-Rzechonek
2019-08-28 16:45 ` [PATCH BlueZ v2 0/2] mesh: Implement org.bluez.mesh.Node1 properties Gix, Brian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).