Skip to contentSkip to conversation

mesh: rework incoming advertisement filtering

PATCH Superseded Brian Gix 1 participant 1 message Feb 23, 2020 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Brian Gix

author
#0 lore raw

PATCH 1/1 mesh: rework incoming advertisement filtering

Future versions of Mesh will introduce new advertising packets, which do not fit in the limited and rigid filtering currently used. This minor rewrite allows registering and receiving of *any* AD types, including the filtering on multiple octets of the incoming AD parts.

---
 mesh/manager.c         |   5 +-
 mesh/mesh-io-api.h     |  12 ++--
 mesh/mesh-io-generic.c | 139 +++++++++++++++++++++++------------------
 mesh/mesh-io.c         |  36 +++--------
 mesh/mesh-io.h         |  25 +++-----
 mesh/mesh.c            |  10 ++-
 mesh/net.c             |  13 ++--
 7 files changed, 120 insertions(+), 120 deletions(-)
mesh/manager.c +3 -2
index e4a7deaeb..0909c7e16 100644
@@ -52,6 +52,7 @@ static uint8_t scan_uuid[16];
 static struct mesh_node *scan_node;
 static struct l_timeout *scan_timeout;
 static struct add_data *add_pending;
+static const uint8_t prvb[2] = {MESH_AD_TYPE_BEACON, 0x00};
 
 static void scan_cancel(struct l_timeout *timeout, void *user_data)
 {
@@ -66,7 +67,7 @@ static void scan_cancel(struct l_timeout *timeout, void *user_data)
 
 	net = node_get_net(node);
 	io = mesh_net_get_io(net);
-	mesh_io_deregister_recv_cb(io, MESH_IO_FILTER_PROV_BEACON);
+	mesh_io_deregister_recv_cb(io, prvb, sizeof(prvb));
 	scan_node = NULL;
 	scan_timeout = NULL;
 }
@@ -397,7 +398,7 @@ static struct l_dbus_message *start_scan_call(struct l_dbus *dbus,
 	net = node_get_net(node);
 	io = mesh_net_get_io(net);
 	scan_node = node;
-	mesh_io_register_recv_cb(io, MESH_IO_FILTER_PROV_BEACON,
+	mesh_io_register_recv_cb(io, prvb, sizeof(prvb),
 						prov_beacon_recv, node);
 
 	if (duration)
mesh/mesh-io-api.h +5 -7
index 75b881800..7a5b49c60 100644
@@ -26,12 +26,11 @@ typedef bool (*mesh_io_caps_t)(struct mesh_io *io, struct mesh_io_caps *caps);
 typedef bool (*mesh_io_send_t)(struct mesh_io *io,
 					struct mesh_io_send_info *info,
 					const uint8_t *data, uint16_t len);
-typedef bool (*mesh_io_register_t)(struct mesh_io *io, uint8_t filter_id,
-				mesh_io_recv_func_t cb, void *user_data);
-typedef bool (*mesh_io_deregister_t)(struct mesh_io *io, uint8_t filter_id);
-typedef bool (*mesh_io_filter_set_t)(struct mesh_io *io,
-			uint8_t filter_id, const uint8_t *data, uint8_t len,
-			mesh_io_status_func_t callback, void *user_data);
+typedef bool (*mesh_io_register_t)(struct mesh_io *io, const uint8_t *filter,
+					uint8_t len, mesh_io_recv_func_t cb,
+					void *user_data);
+typedef bool (*mesh_io_deregister_t)(struct mesh_io *io, const uint8_t *filter,
+								uint8_t len);
 typedef bool (*mesh_io_tx_cancel_t)(struct mesh_io *io, const uint8_t *pattern,
 								uint8_t len);
 
@@ -42,7 +41,6 @@ struct mesh_io_api {
 	mesh_io_send_t		send;
 	mesh_io_register_t	reg;
 	mesh_io_deregister_t	dereg;
-	mesh_io_filter_set_t	set;
 	mesh_io_tx_cancel_t	cancel;
 };
 
mesh/mesh-io-generic.c +79 -60

257 lines not on this page · raw message

mesh/mesh-io.c +7 -29
index 1ab173d9c..c4eaecefd 100644
@@ -85,18 +85,6 @@ struct mesh_io *mesh_io_new(enum mesh_io_type type, void *opts,
 	if (!io_list)
 		io_list = l_queue_new();
 
-	if (api->set) {
-		uint8_t pkt = MESH_AD_TYPE_NETWORK;
-		uint8_t prv = MESH_AD_TYPE_PROVISION;
-		uint8_t snb[2] = {MESH_AD_TYPE_BEACON, 0x01};
-		uint8_t prvb[2] = {MESH_AD_TYPE_BEACON, 0x00};
-
-		api->set(io, 1, snb, sizeof(snb), NULL, NULL);
-		api->set(io, 2, &prv, 1, NULL, NULL);
-		api->set(io, 3, &pkt, 1, NULL, NULL);
-		api->set(io, 4, prvb, sizeof(prvb), NULL, NULL);
-	}
-
 	if (l_queue_push_head(io_list, io))
 		return io;
 
@@ -133,35 +121,25 @@ bool mesh_io_get_caps(struct mesh_io *io, struct mesh_io_caps *caps)
 	return false;
 }
 
-bool mesh_io_register_recv_cb(struct mesh_io *io, uint8_t filter_id,
-				mesh_io_recv_func_t cb, void *user_data)
+bool mesh_io_register_recv_cb(struct mesh_io *io, const uint8_t *filter,
+				uint8_t len, mesh_io_recv_func_t cb,
+				void *user_data)
 {
 	io = l_queue_find(io_list, match_by_io, io);
 
 	if (io && io->api && io->api->reg)
-		return io->api->reg(io, filter_id, cb, user_data);
+		return io->api->reg(io, filter, len, cb, user_data);
 
 	return false;
 }
 
-bool mesh_io_deregister_recv_cb(struct mesh_io *io, uint8_t filter_id)
+bool mesh_io_deregister_recv_cb(struct mesh_io *io, const uint8_t *filter,
+								uint8_t len)
 {
 	io = l_queue_find(io_list, match_by_io, io);
 
 	if (io && io->api && io->api->dereg)
-		return io->api->dereg(io, filter_id);
-
-	return false;
-}
-
-bool mesh_set_filter(struct mesh_io *io, uint8_t filter_id,
-				const uint8_t *data, uint8_t len,
-				mesh_io_status_func_t cb, void *user_data)
-{
-	io = l_queue_find(io_list, match_by_io, io);
-
-	if (io && io->api && io->api->set)
-		return io->api->set(io, filter_id, data, len, cb, user_data);
+		return io->api->dereg(io, filter, len);
 
 	return false;
 }
mesh/mesh-io.h +10 -15
index 45ff00a3c..fc0422020 100644
@@ -19,11 +19,6 @@
 
 struct mesh_io;
 
-#define MESH_IO_FILTER_BEACON		1
-#define MESH_IO_FILTER_PROV		2
-#define MESH_IO_FILTER_NET		3
-#define MESH_IO_FILTER_PROV_BEACON	4
-
 #define MESH_IO_TX_COUNT_UNLIMITED	0
 
 enum mesh_io_type {
@@ -38,6 +33,7 @@ enum mesh_io_timing_type {
 };
 
 struct mesh_io_recv_info {
+	const uint8_t *addr;
 	uint32_t instant;
 	uint8_t chan;
 	int8_t rssi;
@@ -78,26 +74,25 @@ typedef void (*mesh_io_recv_func_t)(void *user_data,
 					struct mesh_io_recv_info *info,
 					const uint8_t *data, uint16_t len);
 
-typedef void (*mesh_io_status_func_t)(void *user_data, int status,
-							uint8_t filter_id);
+typedef void (*mesh_io_recv_ext_func_t)(void *user_data,
+					struct mesh_io_recv_info *info,
+					const uint8_t *data, uint16_t len,
+					const uint8_t *addr);
 
 typedef void (*mesh_io_ready_func_t)(void *user_data, bool result);
 
-
 struct mesh_io *mesh_io_new(enum mesh_io_type type, void *opts,
 				mesh_io_ready_func_t cb, void *user_data);
 void mesh_io_destroy(struct mesh_io *io);
 
 bool mesh_io_get_caps(struct mesh_io *io, struct mesh_io_caps *caps);
 
-bool mesh_io_register_recv_cb(struct mesh_io *io, uint8_t filter_id,
-				mesh_io_recv_func_t cb, void *user_data);
+bool mesh_io_register_recv_cb(struct mesh_io *io, const uint8_t *filter,
+					uint8_t len, mesh_io_recv_func_t cb,
+					void *user_data);
 
-bool mesh_io_deregister_recv_cb(struct mesh_io *io, uint8_t filter_id);
-
-bool mesh_set_filter(struct mesh_io *io, uint8_t filter_id,
-				const uint8_t *data, uint8_t len,
-				mesh_io_status_func_t cb, void *user_data);
+bool mesh_io_deregister_recv_cb(struct mesh_io *io, const uint8_t *filter,
+								uint8_t len);
 
 bool mesh_io_send(struct mesh_io *io, struct mesh_io_send_info *info,
 					const uint8_t *data, uint16_t len);
mesh/mesh.c +7 -3
index 6d2f86b6d..247c3c9be 100644
@@ -141,24 +141,28 @@ static void prov_rx(void *user_data, struct mesh_io_recv_info *info,
 
 bool mesh_reg_prov_rx(prov_rx_cb_t cb, void *user_data)
 {
+	uint8_t prov_filter[] = {MESH_AD_TYPE_PROVISION};
+
 	if (mesh.prov_rx && mesh.prov_rx != cb)
 		return false;
 
 	mesh.prov_rx = cb;
 	mesh.prov_data = user_data;
 
-	return mesh_io_register_recv_cb(mesh.io, MESH_IO_FILTER_PROV,
-							prov_rx, &mesh);
+	return mesh_io_register_recv_cb(mesh.io, prov_filter,
+					sizeof(prov_filter), prov_rx, &mesh);
 }
 
 void mesh_unreg_prov_rx(prov_rx_cb_t cb)
 {
+	uint8_t prov_filter[] = {MESH_AD_TYPE_PROVISION};
+
 	if (mesh.prov_rx != cb)
 		return;
 
 	mesh.prov_rx = NULL;
 	mesh.prov_data = NULL;
-	mesh_io_deregister_recv_cb(mesh.io, MESH_IO_FILTER_PROV);
+	mesh_io_deregister_recv_cb(mesh.io, prov_filter, sizeof(prov_filter));
 }
 
 static void io_ready_callback(void *user_data, bool result)
mesh/net.c +9 -4
index ec05b6be9..5cf358fbd 100644
@@ -2884,6 +2884,9 @@ bool mesh_net_attach(struct mesh_net *net, struct mesh_io *io)
 
 	first = l_queue_isempty(nets);
 	if (first) {
+		uint8_t snb[] = {MESH_AD_TYPE_BEACON, 0x01};
+		uint8_t pkt[] = {MESH_AD_TYPE_NETWORK};
+
 		if (!nets)
 			nets = l_queue_new();
 
@@ -2891,9 +2894,9 @@ bool mesh_net_attach(struct mesh_net *net, struct mesh_io *io)
 			fast_cache = l_queue_new();
 
 		l_info("Register io cb");
-		mesh_io_register_recv_cb(io, MESH_IO_FILTER_BEACON,
+		mesh_io_register_recv_cb(io, snb, sizeof(snb),
 							beacon_recv, NULL);
-		mesh_io_register_recv_cb(io, MESH_IO_FILTER_NET,
+		mesh_io_register_recv_cb(io, pkt, sizeof(pkt),
 							net_msg_recv, NULL);
 	}
 
@@ -2909,6 +2912,8 @@ bool mesh_net_attach(struct mesh_net *net, struct mesh_io *io)
 
 struct mesh_io *mesh_net_detach(struct mesh_net *net)
 {
+	uint8_t snb[] = {MESH_AD_TYPE_BEACON, 0x01};
+	uint8_t pkt[] = {MESH_AD_TYPE_NETWORK};
 	struct mesh_io *io;
 	uint8_t type = 0;
 
@@ -2918,8 +2923,8 @@ struct mesh_io *mesh_net_detach(struct mesh_net *net)
 	io = net->io;
 
 	mesh_io_send_cancel(net->io, &type, 1);
-	mesh_io_deregister_recv_cb(io, MESH_IO_FILTER_BEACON);
-	mesh_io_deregister_recv_cb(io, MESH_IO_FILTER_NET);
+	mesh_io_deregister_recv_cb(io, snb, sizeof(snb));
+	mesh_io_deregister_recv_cb(io, pkt, sizeof(pkt));
 
 	net->io = NULL;
 	l_queue_remove(nets, net);
Signature · 1 line
2.21.1