linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/5] Mesh clean up
@ 2020-05-29  6:37 Inga Stotland
  2020-05-29  6:37 ` [PATCH BlueZ 1/5] mesh: Make helper packet print depends on debug setting Inga Stotland
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Inga Stotland @ 2020-05-29  6:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

No functional changes: cleaned up debug output so that
hex print is not executed if debug is not enabled.

Style cleanup in net.c. Removed unused functions from net.h/net.c

Inga Stotland (5):
  mesh: Make helper packet print depends on debug setting
  mesh: Debug output clean up
  mesh: Remove debug-only related callback for packet send
  mesh: Clean up style in net.c
  mesh: Remove unused functions from net.c

 mesh/main.c            |   3 +-
 mesh/manager.c         |   6 +-
 mesh/mesh-io-generic.c |   3 +-
 mesh/model.c           |  53 +---
 mesh/net.c             | 572 +++++++++++------------------------------
 mesh/net.h             |  30 +--
 mesh/pb-adv.c          |   7 +-
 mesh/prov-initiator.c  |   2 +-
 mesh/util.c            |  11 +
 mesh/util.h            |   1 +
 10 files changed, 180 insertions(+), 508 deletions(-)

-- 
2.26.2


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

* [PATCH BlueZ 1/5] mesh: Make helper packet print depends on debug setting
  2020-05-29  6:37 [PATCH BlueZ 0/5] Mesh clean up Inga Stotland
@ 2020-05-29  6:37 ` Inga Stotland
  2020-05-29  6:37 ` [PATCH BlueZ 2/5] mesh: Debug output clean up Inga Stotland
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Inga Stotland @ 2020-05-29  6:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

This changes the utility function print_packet() to check if
daemon is running in debug mode.
---
 mesh/main.c |  3 ++-
 mesh/util.c | 11 +++++++++++
 mesh/util.h |  1 +
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/mesh/main.c b/mesh/main.c
index c6bf1ff41..1a4e6ba76 100644
--- a/mesh/main.c
+++ b/mesh/main.c
@@ -37,6 +37,7 @@
 #include "mesh/crypto.h"
 #include "mesh/dbus.h"
 #include "mesh/mesh-io.h"
+#include "mesh/util.h"
 
 static const char *config_dir;
 static const char *mesh_conf_fname;
@@ -210,7 +211,7 @@ int main(int argc, char *argv[])
 			detached = false;
 			break;
 		case 'd':
-			l_debug_enable("*");
+			enable_debug();
 			break;
 		case 'c':
 			config_dir = optarg;
diff --git a/mesh/util.c b/mesh/util.c
index 43340f159..7d283331a 100644
--- a/mesh/util.c
+++ b/mesh/util.c
@@ -34,10 +34,15 @@
 
 #include "mesh/util.h"
 
+static bool debug_enabled;
+
 void print_packet(const char *label, const void *data, uint16_t size)
 {
 	struct timeval pkt_time;
 
+	if (!debug_enabled)
+		return;
+
 	gettimeofday(&pkt_time, NULL);
 
 	if (size > 0) {
@@ -154,3 +159,9 @@ void del_path(const char *path)
 {
 	nftw(path, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
 }
+
+void enable_debug(void)
+{
+	debug_enabled = true;
+	l_debug_enable("*");
+}
diff --git a/mesh/util.h b/mesh/util.h
index 092d33041..93c2d8687 100644
--- a/mesh/util.h
+++ b/mesh/util.h
@@ -24,3 +24,4 @@ size_t hex2str(uint8_t *in, size_t in_len, char *out, size_t out_len);
 void print_packet(const char *label, const void *data, uint16_t size);
 int create_dir(const char *dir_name);
 void del_path(const char *path);
+void enable_debug(void);
-- 
2.26.2


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

* [PATCH BlueZ 2/5] mesh: Debug output clean up
  2020-05-29  6:37 [PATCH BlueZ 0/5] Mesh clean up Inga Stotland
  2020-05-29  6:37 ` [PATCH BlueZ 1/5] mesh: Make helper packet print depends on debug setting Inga Stotland
@ 2020-05-29  6:37 ` Inga Stotland
  2020-05-29 17:22   ` Gix, Brian
  2020-05-29  6:37 ` [PATCH BlueZ 3/5] mesh: Remove debug-only related callback for packet send Inga Stotland
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Inga Stotland @ 2020-05-29  6:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

This changes l_info() to l_debug() for recurring cases and
removes some excessive debug output.
---
 mesh/manager.c         |   6 +-
 mesh/mesh-io-generic.c |   3 +-
 mesh/model.c           |  28 +-------
 mesh/net.c             | 150 ++++++++++++++---------------------------
 mesh/pb-adv.c          |   7 +-
 mesh/prov-initiator.c  |   2 +-
 6 files changed, 58 insertions(+), 138 deletions(-)

diff --git a/mesh/manager.c b/mesh/manager.c
index a7383e4d5..2be471088 100644
--- a/mesh/manager.c
+++ b/mesh/manager.c
@@ -219,7 +219,7 @@ static void add_start(void *user_data, int err)
 {
 	struct l_dbus_message *reply;
 
-	l_info("Start callback");
+	l_debug("Start callback");
 
 	if (err == MESH_ERROR_NONE)
 		reply = l_dbus_message_new_method_return(add_pending->msg);
@@ -270,8 +270,8 @@ static struct l_dbus_message *add_node_call(struct l_dbus *dbus,
 	add_pending->agent = node_get_agent(node);
 
 	if (!node_is_provisioner(node) || (add_pending->agent == NULL)) {
-		l_info("Provisioner: %d", node_is_provisioner(node));
-		l_info("Agent: %p", add_pending->agent);
+		l_debug("Provisioner: %d", node_is_provisioner(node));
+		l_debug("Agent: %p", add_pending->agent);
 		reply = dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED,
 							"Missing Interfaces");
 		goto fail;
diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c
index 3ad130567..7a4008bd9 100644
--- a/mesh/mesh-io-generic.c
+++ b/mesh/mesh-io-generic.c
@@ -173,7 +173,7 @@ static void event_callback(const void *buf, uint8_t size, void *user_data)
 		break;
 
 	default:
-		l_info("Other Meta Evt - %d", event);
+		l_debug("Other Meta Evt - %d", event);
 	}
 }
 
@@ -804,7 +804,6 @@ static bool recv_register(struct mesh_io *io, const uint8_t *filter,
 	if (!cb || !filter || !len)
 		return false;
 
-	l_info("%s %2.2x", __func__, filter[0]);
 	rx_reg = l_queue_remove_if(pvt->rx_regs, find_by_filter, filter);
 
 	l_free(rx_reg);
diff --git a/mesh/model.c b/mesh/model.c
index 945583324..dc6f28eb8 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -514,15 +514,8 @@ static void cmplt(uint16_t remote, uint8_t status,
 {
 	struct timeval tx_end;
 
-	if (status)
-		l_debug("Tx-->%4.4x (%d octets) Failed (%d)",
-				remote, size, status);
-	else
-		l_debug("Tx-->%4.4x (%d octets) Succeeded", remote, size);
-
-	/* print_packet("Sent Data", data, size); */
-
 	gettimeofday(&tx_end, NULL);
+
 	if (tx_end.tv_sec == tx_start.tv_sec) {
 		l_debug("Duration 0.%6.6lu seconds",
 				tx_end.tv_usec - tx_start.tv_usec);
@@ -580,22 +573,18 @@ static bool msg_send(struct mesh_node *node, bool credential, uint16_t src,
 		net_idx = appkey_net_idx(node_get_net(node), app_idx);
 	}
 
-	l_debug("(%x) %p", app_idx, key);
-	l_debug("net_idx %x", net_idx);
-
 	out = l_malloc(out_len);
 
 	iv_index = mesh_net_get_iv_index(net);
 
 	seq_num = mesh_net_next_seq_num(net);
+
 	if (!mesh_crypto_payload_encrypt(label, msg, out, msg_len, src, dst,
 				key_aid, seq_num, iv_index, szmic, key)) {
 		l_error("Failed to Encrypt Payload");
 		goto done;
 	}
 
-	/* print_packet("Encrypted with", key, 16); */
-
 	ret = mesh_net_app_send(net, credential, src, dst, key_aid, net_idx,
 					ttl, seq_num, iv_index, segmented,
 					szmic, out, out_len, cmplt, NULL);
@@ -647,8 +636,6 @@ static void model_bind_idx(struct mesh_node *node, struct mesh_model *mod,
 
 	l_queue_push_tail(mod->bindings, L_UINT_TO_PTR(idx));
 
-	l_debug("Add %4.4x to model %8.8x", idx, mod->id);
-
 	if (!mod->cbs)
 		/* External model */
 		config_update_model_bindings(node, mod);
@@ -781,7 +768,6 @@ static int add_virt_sub(struct mesh_net *net, struct mesh_model *mod,
 
 		l_queue_push_head(mod->virtuals, virt);
 		mesh_net_dst_reg(net, virt->addr);
-		l_debug("Added virtual sub addr %4.4x", virt->addr);
 	}
 
 	if (dst)
@@ -809,7 +795,6 @@ static int add_sub(struct mesh_net *net, struct mesh_model *mod,
 
 		l_queue_push_tail(mod->subs, L_UINT_TO_PTR(grp));
 		mesh_net_dst_reg(net, grp);
-		l_debug("Added group subscription %4.4x", grp);
 	}
 
 	return MESH_STATUS_SUCCESS;
@@ -929,6 +914,7 @@ bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,
 
 	/* Don't process if already in RPL */
 	crpl = node_get_crpl(node);
+
 	if (net_msg_check_replay_cache(net, src, crpl, seq, iv_index))
 		return false;
 
@@ -1064,8 +1050,6 @@ int mesh_model_publish(struct mesh_node *node, uint32_t mod_id,
 	bool result;
 	int status;
 
-	/* print_packet("Mod Tx", msg, msg_len); */
-
 	if (!net || msg_len > 380)
 		return MESH_ERROR_INVALID_ARGS;
 
@@ -1092,8 +1076,6 @@ int mesh_model_publish(struct mesh_node *node, uint32_t mod_id,
 	if (mod->pub->virt)
 		label = mod->pub->virt->label;
 
-	l_debug("publish dst=%x", mod->pub->addr);
-
 	net_idx = appkey_net_idx(net, mod->pub->idx);
 
 	result = msg_send(node, mod->pub->credential != 0, src,
@@ -1108,8 +1090,6 @@ bool mesh_model_send(struct mesh_node *node, uint16_t src, uint16_t dst,
 					uint8_t ttl, bool segmented,
 					const void *msg, uint16_t msg_len)
 {
-	/* print_packet("Mod Tx", msg, msg_len); */
-
 	/* If SRC is 0, use the Primary Element */
 	if (src == 0)
 		src = node_get_primary(node);
@@ -1279,14 +1259,12 @@ void mesh_model_app_key_delete(struct mesh_node *node, struct l_queue *models,
 int mesh_model_binding_del(struct mesh_node *node, uint16_t addr, uint32_t id,
 						uint16_t app_idx)
 {
-	l_debug("0x%x, 0x%x, %d", addr, id, app_idx);
 	return update_binding(node, addr, id, app_idx, true);
 }
 
 int mesh_model_binding_add(struct mesh_node *node, uint16_t addr, uint32_t id,
 						uint16_t app_idx)
 {
-	l_debug("0x%x, 0x%x, %d", addr, id, app_idx);
 	return update_binding(node, addr, id, app_idx, false);
 }
 
diff --git a/mesh/net.c b/mesh/net.c
index f104be0f9..f9e7bce4c 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -307,7 +307,7 @@ static void trigger_heartbeat(struct mesh_net *net, uint16_t feature,
 {
 	struct mesh_net_heartbeat *hb = &net->heartbeat;
 
-	l_info("%s: %4.4x --> %d", __func__, feature, in_use);
+	l_debug("%s: %4.4x --> %d", __func__, feature, in_use);
 	if (in_use) {
 		if (net->heartbeat.features & feature)
 			return; /* no change */
@@ -371,7 +371,7 @@ static void frnd_kr_phase2(void *a, void *b)
 	 * receives it's first Poll using the new keys (?)
 	 */
 
-	l_info("Use Both KeySet %d && %d for %4.4x",
+	l_debug("Use Both KeySet %d && %d for %4.4x",
 			frnd->net_key_cur, frnd->net_key_upd, frnd->lp_addr);
 }
 
@@ -379,7 +379,7 @@ static void frnd_kr_phase3(void *a, void *b)
 {
 	struct mesh_friend *frnd = a;
 
-	l_info("Replace KeySet %d with %d for %4.4x",
+	l_debug("Replace KeySet %d with %d for %4.4x",
 			frnd->net_key_cur, frnd->net_key_upd, frnd->lp_addr);
 	net_key_unref(frnd->net_key_cur);
 	frnd->net_key_cur = frnd->net_key_upd;
@@ -627,10 +627,6 @@ static void queue_friend_update(struct mesh_net *net)
 		update.u.one[0].data[1] = flags;
 		l_put_be32(net->iv_index, update.u.one[0].data + 2);
 		update.u.one[0].data[6] = 0x01; /* More Data */
-		/* print_packet("Frnd-Beacon-SRC",
-		 *			beacon_data, sizeof(beacon_data));
-		 */
-		/* print_packet("Frnd-Update", update.u.one[0].data, 6); */
 
 		l_queue_foreach(net->friends, enqueue_update, &update);
 	}
@@ -1570,7 +1566,7 @@ static void send_frnd_ack(struct mesh_net *net, uint16_t src, uint16_t dst,
 	l_put_be32(hdr, msg);
 	l_put_be32(flags, msg + 3);
 
-	l_info("Send Friend ACK to Segs: %8.8x", flags);
+	l_debug("Send Friend ACK to Segs: %8.8x", flags);
 
 	if (is_lpn_friend(net, dst)) {
 		/* If we are acking our LPN Friend, queue, don't send */
@@ -1603,7 +1599,7 @@ static void send_net_ack(struct mesh_net *net, struct mesh_sar *sar,
 
 	l_put_be32(hdr, msg);
 	l_put_be32(flags, msg + 3);
-	l_info("Send%s ACK to Segs: %8.8x", sar->frnd ? " Friend" : "", flags);
+	l_debug("Send%s ACK to Segs: %8.8x", sar->frnd ? " Friend" : "", flags);
 
 	if (is_lpn_friend(net, dst)) {
 		/* If we are acking our LPN Friend, queue, don't send */
@@ -1629,7 +1625,7 @@ static void inseg_to(struct l_timeout *seg_timeout, void *user_data)
 		return;
 
 	/* Send NAK */
-	l_info("Timeout %p %3.3x", sar, sar->app_idx);
+	l_debug("Timeout %p %3.3x", sar, sar->app_idx);
 	send_net_ack(net, sar, sar->flags);
 
 	sar->seg_timeout = l_timeout_create(SEG_TO, inseg_to, net, NULL);
@@ -1647,7 +1643,6 @@ static void inmsg_to(struct l_timeout *msg_timeout, void *user_data)
 
 	sar->msg_timeout = NULL;
 
-	/* print_packet("Incoming SAR Timeout", sar->buf, sar->len); */
 	mesh_sar_free(sar);
 }
 
@@ -1668,7 +1663,6 @@ static void outmsg_to(struct l_timeout *msg_timeout, void *user_data)
 				sar->buf, sar->len - 4,
 				sar->user_data);
 
-	/* print_packet("Outgoing SAR Timeout", sar->buf, sar->len); */
 	mesh_sar_free(sar);
 }
 
@@ -1698,13 +1692,13 @@ static void ack_received(struct mesh_net *net, bool timeout,
 	uint32_t ack_copy = ack_flag;
 	uint16_t i;
 
-	l_info("ACK Rxed (%x) (to:%d): %8.8x", seq0, timeout, ack_flag);
+	l_debug("ACK Rxed (%x) (to:%d): %8.8x", seq0, timeout, ack_flag);
 
 	outgoing = l_queue_find(net->sar_out, match_sar_seq0,
 							L_UINT_TO_PTR(seq0));
 
 	if (!outgoing) {
-		l_info("Not Found: %4.4x", seq0);
+		l_debug("Not Found: %4.4x", seq0);
 		return;
 	}
 
@@ -1743,7 +1737,7 @@ static void ack_received(struct mesh_net *net, bool timeout,
 
 		ack_copy |= seg_flag;
 
-		l_info("Resend Seg %d net:%p dst:%x app_idx:%3.3x",
+		l_debug("Resend Seg %d net:%p dst:%x app_idx:%3.3x",
 				i, net, outgoing->remote, outgoing->app_idx);
 
 		send_seg(net, outgoing, i);
@@ -1918,12 +1912,12 @@ static void friend_seg_rxed(struct mesh_net *net,
 	if (segN == segO)
 		frnd_msg->last_len = size;
 
-	l_info("RXed Seg %d, Flags %8.8x (cnt: %d)",
+	l_debug("RXed Seg %d, Flags %8.8x (cnt: %d)",
 						segO, frnd_msg->flags, cnt);
 
 	/* In reality, if one of these is true, then *both* must be true */
 	if ((cnt == segN) || (frnd_msg->flags == expected)) {
-		l_info("Full ACK");
+		l_debug("Full ACK");
 		send_frnd_ack(net, dst, src, hdr, frnd_msg->flags);
 
 		if (frnd_msg->ttl > 1) {
@@ -1943,7 +1937,7 @@ static void friend_seg_rxed(struct mesh_net *net,
 
 	/* Always ACK if this is the largest outstanding segment */
 	if ((largest & frnd_msg->flags) == largest) {
-		l_info("Partial ACK");
+		l_debug("Partial ACK");
 		send_frnd_ack(net, dst, src, hdr, frnd_msg->flags);
 	}
 
@@ -1997,7 +1991,7 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
 	expected = 0xffffffff >> (31 - segN);
 
 	if (sar_in) {
-		l_info("RXed (old: %04x %06x size:%d) %d of %d",
+		l_debug("RXed (old: %04x %06x size:%d) %d of %d",
 					seqZero, seq, size, segO, segN);
 		/* Sanity Check--> certain things must match */
 		if (SEG_MAX(true, sar_in->len) != segN ||
@@ -2012,7 +2006,7 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
 	} else {
 		uint16_t len = MAX_SEG_TO_LEN(segN);
 
-		l_info("RXed (new: %04x %06x size: %d len: %d) %d of %d",
+		l_debug("RXed (new: %04x %06x size: %d len: %d) %d of %d",
 				seqZero, seq, size, len, segO, segN);
 		l_debug("Queue Size: %d", l_queue_length(net->sar_in));
 		sar_in = mesh_sar_new(len);
@@ -2031,7 +2025,6 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
 		l_debug("First Seg %4.4x", sar_in->flags);
 		l_queue_push_head(net->sar_in, sar_in);
 	}
-	/* print_packet("Seg", data, size); */
 
 	seg_off = segO * MAX_SEG_LEN;
 	memcpy(sar_in->buf + seg_off, data, size);
@@ -2044,8 +2037,6 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
 	sar_in->flags |= this_seg_flag;
 	sar_in->ttl = ttl;
 
-	l_debug("Have Frags %4.4x", sar_in->flags);
-
 	/* Msg length only definitive on last segment */
 	if (segO == segN)
 		sar_in->len = segN * MAX_SEG_LEN + size;
@@ -2166,7 +2157,7 @@ static bool ctl_received(struct mesh_net *net, uint16_t key_id,
 				l_queue_find(net->friends,
 					match_by_friend,
 					L_UINT_TO_PTR(l_get_be16(pkt))));
-		l_info("Remaining Friends: %d", l_queue_length(net->friends));
+		l_debug("Remaining Friends: %d", l_queue_length(net->friends));
 		break;
 
 	case NET_OP_PROXY_SUB_ADD:
@@ -2212,7 +2203,7 @@ static bool ctl_received(struct mesh_net *net, uint16_t key_id,
 			if (net->heartbeat.sub_max_hops < hops)
 				net->heartbeat.sub_max_hops = hops;
 
-			l_info("HB: cnt:%4.4x min:%2.2x max:%2.2x",
+			l_debug("HB: cnt:%4.4x min:%2.2x max:%2.2x",
 					net->heartbeat.sub_count,
 					net->heartbeat.sub_min_hops,
 					net->heartbeat.sub_max_hops);
@@ -2381,8 +2372,6 @@ static enum _relay_advice packet_received(void *user_data,
 	if (is_us(net, net_src, true))
 		return RELAY_NONE;
 
-	l_debug("check %08x", cache_cookie);
-
 	/* As a Relay, suppress repeats of last N packets that pass through */
 	/* The "cache_cookie" should be unique part of App message */
 	if (msg_in_cache(net, net_src, net_seq, cache_cookie))
@@ -2394,7 +2383,7 @@ static enum _relay_advice packet_received(void *user_data,
 	if (is_us(net, net_dst, false) ||
 			(net_ctl && net_opcode == NET_OP_HEARTBEAT)) {
 
-		l_info("RX: App 0x%04x -> 0x%04x : TTL 0x%02x : SEQ 0x%06x",
+		l_debug("RX: App 0x%04x -> 0x%04x : TTL 0x%02x : SEQ 0x%06x",
 					net_src, net_dst, net_ttl, net_seq);
 
 		if (net_ctl) {
@@ -2404,7 +2393,6 @@ static enum _relay_advice packet_received(void *user_data,
 				if (net_dst & 0x8000)
 					return RELAY_NONE;
 
-				/* print_packet("Got ACK", msg, app_msg_len); */
 				/* Pedantic check for correct size */
 				if (app_msg_len != 7)
 					return RELAY_NONE;
@@ -2576,7 +2564,7 @@ static void iv_upd_to(struct l_timeout *upd_timeout, void *user_data)
 	case IV_UPD_UPDATING:
 		if (l_queue_length(net->sar_out) ||
 					l_queue_length(net->sar_queue)) {
-			l_info("don't leave IV Update until sar_out empty");
+			l_debug("don't leave IV Update until sar_out empty");
 			l_timeout_modify(net->iv_update_timeout, 10);
 			break;
 		}
@@ -2626,7 +2614,7 @@ static int key_refresh_phase_two(struct mesh_net *net, uint16_t idx)
 	if (!subnet || !subnet->net_key_upd)
 		return MESH_STATUS_INVALID_NETKEY;
 
-	l_info("Key refresh procedure phase 2: start using new net TX keys");
+	l_debug("Key refresh procedure phase 2: start using new net TX keys");
 	subnet->key_refresh = 1;
 	subnet->net_key_tx = subnet->net_key_upd;
 	/* TODO: Provisioner may need to stay in phase three until
@@ -2659,7 +2647,7 @@ static int key_refresh_finish(struct mesh_net *net, uint16_t idx)
 	if (subnet->kr_phase == KEY_REFRESH_PHASE_NONE)
 		return MESH_STATUS_SUCCESS;
 
-	l_info("Key refresh phase 3: use new keys only, discard old ones");
+	l_debug("Key refresh phase 3: use new keys only, discard old ones");
 
 	/* Switch to using new keys, discard old ones */
 	net_key_unref(subnet->net_key_cur);
@@ -2715,12 +2703,12 @@ static void update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index,
 			 * Starting permissive state will allow us maximum
 			 * (96 hours) to resync
 			 */
-			l_info("iv_upd_state = IV_UPD_UPDATING");
+			l_debug("iv_upd_state = IV_UPD_UPDATING");
 			net->iv_upd_state = IV_UPD_UPDATING;
 			net->iv_update_timeout = l_timeout_create(
 				IV_IDX_UPD_MIN, iv_upd_to, net, NULL);
 		} else {
-			l_info("iv_upd_state = IV_UPD_NORMAL");
+			l_debug("iv_upd_state = IV_UPD_NORMAL");
 			net->iv_upd_state = IV_UPD_NORMAL;
 		}
 	} else if (ivu) {
@@ -2736,7 +2724,7 @@ static void update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index,
 			return;
 
 		if (!net->iv_update) {
-			l_info("iv_upd_state = IV_UPD_UPDATING");
+			l_debug("iv_upd_state = IV_UPD_UPDATING");
 			net->iv_upd_state = IV_UPD_UPDATING;
 			net->iv_update_timeout = l_timeout_create(
 					IV_IDX_UPD_MIN, iv_upd_to, net, NULL);
@@ -2937,7 +2925,6 @@ bool mesh_net_attach(struct mesh_net *net, struct mesh_io *io)
 		if (!fast_cache)
 			fast_cache = l_queue_new();
 
-		l_info("Register io cb");
 		mesh_io_register_recv_cb(io, snb, sizeof(snb),
 							beacon_recv, NULL);
 		mesh_io_register_recv_cb(io, pkt, sizeof(pkt),
@@ -2981,7 +2968,7 @@ bool mesh_net_iv_index_update(struct mesh_net *net)
 	if (net->iv_upd_state != IV_UPD_NORMAL)
 		return false;
 
-	l_info("iv_upd_state = IV_UPD_UPDATING");
+	l_debug("iv_upd_state = IV_UPD_UPDATING");
 	mesh_net_flush_msg_queues(net);
 	if (!mesh_config_write_iv_index(node_config_get(net->node),
 						net->iv_index + 1, true))
@@ -3082,23 +3069,18 @@ static bool send_seg(struct mesh_net *net, struct mesh_sar *msg, uint8_t segO)
 		mesh_net_iv_index_update(net);
 
 	l_debug("segN %d segment %d seg_off %d", segN, segO, seg_off);
-	/* print_packet("Sending", msg->buf + seg_off, seg_len); */
-	{
-		/* TODO: Are we RXing on an LPN's behalf? Then set RLY bit */
-
-		if (!mesh_crypto_packet_build(false, msg->ttl,
-					seq_num,
-					msg->src, msg->remote,
-					0,
-					msg->segmented, msg->key_aid,
-					msg->szmic, false, msg->seqZero,
-					segO, segN,
+
+	/* TODO: Are we RXing on an LPN's behalf? Then set RLY bit */
+	if (!mesh_crypto_packet_build(false, msg->ttl, seq_num, msg->src,
+					msg->remote, 0, msg->segmented,
+					msg->key_aid, msg->szmic, false,
+					msg->seqZero, segO, segN,
 					msg->buf + seg_off, seg_len,
 					packet + 1, &packet_len)) {
-			l_error("Failed to build packet");
-			return false;
-		}
+		l_error("Failed to build packet");
+		return false;
 	}
+
 	print_packet("Clr-Net Tx", packet + 1, packet_len);
 
 	subnet = l_queue_find(net->subnets, match_key_index,
@@ -3112,20 +3094,7 @@ static bool send_seg(struct mesh_net *net, struct mesh_sar *msg, uint8_t segO)
 		return false;
 	}
 
-	/* print_packet("Step 4", packet + 1, packet_len); */
-
-	{
-		char *str;
-
-		send_msg_pkt(net, packet, packet_len + 1);
-
-		str = l_util_hexstring(packet + 1, packet_len);
-		l_info("TX: Network %04x -> %04x : %s (%u) : TTL %d : SEQ %06x",
-				msg->src, msg->remote, str,
-				packet_len, msg->ttl,
-				msg->frnd ? msg->seqAuth + segO : seq_num);
-		l_free(str);
-	}
+	send_msg_pkt(net, packet, packet_len + 1);
 
 	msg->last_seg = segO;
 
@@ -3140,7 +3109,6 @@ void mesh_net_send_seg(struct mesh_net *net, uint32_t net_key_id,
 				uint32_t hdr,
 				const void *seg, uint16_t seg_len)
 {
-	char *str;
 	uint8_t packet[30];
 	uint8_t packet_len;
 	bool segmented = !!((hdr >> SEG_HDR_SHIFT) & true);
@@ -3174,14 +3142,12 @@ void mesh_net_send_seg(struct mesh_net *net, uint32_t net_key_id,
 		return;
 	}
 
-	/* print_packet("Step 4", packet + 1, packet_len); */
-
 	send_msg_pkt(net, packet, packet_len + 1);
 
-	str = l_util_hexstring(packet + 1, packet_len);
-	l_info("TX: Friend Seg-%d %04x -> %04x : %s (%u) : TTL %d : SEQ %06x",
-			segO, src, dst, str, packet_len, ttl, seq);
-	l_free(str);
+	l_debug("TX: Friend Seg-%d %04x -> %04x : len %u) : TTL %d : SEQ %06x",
+					segO, src, dst, packet_len, ttl, seq);
+
+	print_packet("TX: Friend", packet + 1, packet_len);
 }
 
 bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
@@ -3222,7 +3188,8 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 				szmic, seq & SEQ_ZERO_MASK,
 				msg, msg_len);
 
-	/* If addressed to a unicast address and successfully enqueued,
+	/*
+	 * If addressed to a unicast address and successfully enqueued,
 	 * or delivered to one of our Unicast addresses we are done
 	 */
 	if ((result && IS_UNICAST(dst)) || src == dst ||
@@ -3243,6 +3210,7 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 	payload->iv_index = mesh_net_get_iv_index(net);
 	payload->seqAuth = seq;
 	payload->segmented = segmented;
+
 	if (segmented) {
 		payload->flags = 0xffffffff >> (31 - seg_max);
 		payload->seqZero = seq & SEQ_ZERO_MASK;
@@ -3256,13 +3224,14 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 			/* Delay sending Outbound SAR unless prior
 			 * SAR to same DST has completed */
 
-			l_info("OB-Queued SeqZero: %4.4x", payload->seqZero);
+			l_debug("OB-Queued SeqZero: %4.4x", payload->seqZero);
 			l_queue_push_tail(net->sar_queue, payload);
 			return true;
 		}
 	}
 
 	result = true;
+
 	if (!IS_UNICAST(dst) && segmented) {
 		int i;
 
@@ -3303,7 +3272,6 @@ void mesh_net_ack_send(struct mesh_net *net, uint32_t key_id,
 	uint8_t data[7];
 	uint8_t pkt_len;
 	uint8_t pkt[30];
-	char *str;
 
 	hdr = NET_OP_SEG_ACKNOWLEDGE << OPCODE_HDR_SHIFT;
 	hdr |= rly << RELAY_HDR_SHIFT;
@@ -3334,14 +3302,11 @@ void mesh_net_ack_send(struct mesh_net *net, uint32_t key_id,
 		return;
 	}
 
-	/* print_packet("Step 4", pkt, pkt_len); */
 	send_msg_pkt(net, pkt, pkt_len + 1);
 
-	str = l_util_hexstring(pkt + 1, pkt_len);
-	l_info("TX: Friend ACK %04x -> %04x : %s (%u) : TTL %d : SEQ %06x",
-			src, dst, str, pkt_len,
-			ttl, seq);
-	l_free(str);
+	l_debug("TX: Friend ACK %04x -> %04x : len %u : TTL %d : SEQ %06x",
+					src, dst, pkt_len, ttl, seq);
+	print_packet("TX: Friend ACK", pkt + 1, pkt_len);
 }
 
 void mesh_net_transport_send(struct mesh_net *net, uint32_t key_id,
@@ -3419,26 +3384,13 @@ void mesh_net_transport_send(struct mesh_net *net, uint32_t key_id,
 				pkt + 1, &pkt_len))
 		return;
 
-	/* print_packet("Step 2", pkt + 1, pkt_len); */
-
 	if (!net_key_encrypt(key_id, iv_index, pkt + 1, pkt_len)) {
 		l_error("Failed to encode packet");
 		return;
 	}
 
-	/* print_packet("Step 4", pkt + 1, pkt_len); */
-
-	if (dst != 0) {
-		char *str;
-
+	if (dst != 0)
 		send_msg_pkt(net, pkt, pkt_len + 1);
-
-		str = l_util_hexstring(pkt + 1, pkt_len);
-		l_info("TX: Network %04x -> %04x : %s (%u) : TTL %d : SEQ %06x",
-				src, dst, str, pkt_len,
-				ttl, use_seq);
-		l_free(str);
-	}
 }
 
 uint8_t mesh_net_key_refresh_phase_set(struct mesh_net *net, uint16_t idx,
@@ -3524,7 +3476,7 @@ int mesh_net_update_key(struct mesh_net *net, uint16_t idx,
 
 	if (subnet->net_key_upd) {
 		net_key_unref(subnet->net_key_upd);
-		l_info("Warning: overwriting new keys");
+		l_debug("Warning: overwriting new keys");
 	}
 
 	/* Preserve starting data */
@@ -3539,7 +3491,7 @@ int mesh_net_update_key(struct mesh_net *net, uint16_t idx,
 	l_queue_foreach(net->friends, frnd_kr_phase1,
 					L_UINT_TO_PTR(subnet->net_key_upd));
 
-	l_info("key refresh phase 1: Key ID %d", subnet->net_key_upd);
+	l_debug("key refresh phase 1: Key ID %d", subnet->net_key_upd);
 
 	if (!mesh_config_net_key_update(node_config_get(net->node), idx, value))
 		return MESH_STATUS_STORAGE_FAIL;
@@ -3812,9 +3764,6 @@ bool net_msg_check_replay_cache(struct mesh_net *net, uint16_t src,
 		rpl_get_list(net->node, net->replay_cache);
 	}
 
-	l_debug("Test Replay src: %4.4x seq: %6.6x iv: %8.8x",
-						src, seq, iv_index);
-
 	rpe = l_queue_find(net->replay_cache, match_replay_cache,
 						L_UINT_TO_PTR(src));
 
@@ -3854,7 +3803,6 @@ void net_msg_add_replay_cache(struct mesh_net *net, uint16_t src, uint32_t seq,
 						L_UINT_TO_PTR(src));
 
 	if (!rpe) {
-		l_debug("New Entry for %4.4x", src);
 		rpe = l_new(struct mesh_rpl, 1);
 		rpe->src = src;
 	}
diff --git a/mesh/pb-adv.c b/mesh/pb-adv.c
index c1316ed1b..ae5b81391 100644
--- a/mesh/pb-adv.c
+++ b/mesh/pb-adv.c
@@ -157,8 +157,6 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
 		init_size = size;
 	}
 
-	/* print_packet("FULL-TX", data, size); */
-
 	l_debug("Sending %u fragments for %u octets", max_seg + 1, size);
 
 	buf[6] = max_seg << 2;
@@ -168,7 +166,6 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
 
 	l_debug("max_seg: %2.2x", max_seg);
 	l_debug("size: %2.2x, CRC: %2.2x", size, buf[9]);
-	/* print_packet("PB-TX", buf + 1, init_size + 9); */
 
 	pb_adv_send(session, MESH_IO_TX_COUNT_UNLIMITED, 200,
 							buf, init_size + 10);
@@ -186,8 +183,6 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
 		buf[6] = (i << 2) | 0x02;
 		memcpy(buf + 7, data + consumed, seg_size);
 
-		/* print_packet("PB-TX", buf + 1, seg_size + 6); */
-
 		pb_adv_send(session, MESH_IO_TX_COUNT_UNLIMITED, 200,
 							buf, seg_size + 7);
 
@@ -225,7 +220,7 @@ static void tx_timeout(struct l_timeout *timeout, void *user_data)
 
 	mesh_send_cancel(filter, sizeof(filter));
 
-	l_info("TX timeout");
+	l_debug("TX timeout");
 	cb = session->close_cb;
 	user_data = session->user_data;
 	cb(user_data, 1);
diff --git a/mesh/prov-initiator.c b/mesh/prov-initiator.c
index 4ef31e95d..4de4df62d 100644
--- a/mesh/prov-initiator.c
+++ b/mesh/prov-initiator.c
@@ -770,7 +770,7 @@ static void int_prov_rx(void *user_data, const uint8_t *data, uint16_t len)
 		break;
 
 	case PROV_COMPLETE: /* Complete */
-		l_info("Provisioning Complete");
+		l_debug("Provisioning Complete");
 		prov->state = INT_PROV_IDLE;
 		int_prov_close(prov, PROV_ERR_SUCCESS);
 		break;
-- 
2.26.2


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

* [PATCH BlueZ 3/5] mesh: Remove debug-only related callback for packet send
  2020-05-29  6:37 [PATCH BlueZ 0/5] Mesh clean up Inga Stotland
  2020-05-29  6:37 ` [PATCH BlueZ 1/5] mesh: Make helper packet print depends on debug setting Inga Stotland
  2020-05-29  6:37 ` [PATCH BlueZ 2/5] mesh: Debug output clean up Inga Stotland
@ 2020-05-29  6:37 ` Inga Stotland
  2020-05-29  6:37 ` [PATCH BlueZ 4/5] mesh: Clean up style in net.c Inga Stotland
  2020-05-29  6:37 ` [PATCH BlueZ 5/5] mesh: Remove unused functions from net.c Inga Stotland
  4 siblings, 0 replies; 8+ messages in thread
From: Inga Stotland @ 2020-05-29  6:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

This removes callback for sending every single access layer packet
since the callback does nothing but print debug satement. This
functionality is mature enough not to require such heavy debugging.
---
 mesh/model.c | 27 ++-------------------------
 mesh/net.c   | 20 +-------------------
 mesh/net.h   |  9 ++-------
 3 files changed, 5 insertions(+), 51 deletions(-)

diff --git a/mesh/model.c b/mesh/model.c
index dc6f28eb8..49e7c50fa 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -508,29 +508,6 @@ static int virt_packet_decrypt(struct mesh_net *net, const uint8_t *data,
 	return -1;
 }
 
-static void cmplt(uint16_t remote, uint8_t status,
-					void *data, uint16_t size,
-					void *user_data)
-{
-	struct timeval tx_end;
-
-	gettimeofday(&tx_end, NULL);
-
-	if (tx_end.tv_sec == tx_start.tv_sec) {
-		l_debug("Duration 0.%6.6lu seconds",
-				tx_end.tv_usec - tx_start.tv_usec);
-	} else {
-		if (tx_start.tv_usec > tx_end.tv_usec)
-			l_debug("Duration %lu.%6.6lu seconds",
-				tx_end.tv_sec - tx_start.tv_sec - 1,
-				tx_end.tv_usec + 1000000 - tx_start.tv_usec);
-		else
-			l_debug("Duration %lu.%6.6lu seconds",
-					tx_end.tv_sec - tx_start.tv_sec,
-					tx_end.tv_usec - tx_start.tv_usec);
-	}
-}
-
 static bool msg_send(struct mesh_node *node, bool credential, uint16_t src,
 		uint32_t dst, uint16_t app_idx, uint16_t net_idx,
 		uint8_t *label, uint8_t ttl, bool segmented,
@@ -585,9 +562,9 @@ static bool msg_send(struct mesh_node *node, bool credential, uint16_t src,
 		goto done;
 	}
 
-	ret = mesh_net_app_send(net, credential, src, dst, key_aid, net_idx,
+	ret =  mesh_net_app_send(net, credential, src, dst, key_aid, net_idx,
 					ttl, seq_num, iv_index, segmented,
-					szmic, out, out_len, cmplt, NULL);
+					szmic, out, out_len);
 done:
 	l_free(out);
 	return ret;
diff --git a/mesh/net.c b/mesh/net.c
index f9e7bce4c..08544ad61 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -171,8 +171,6 @@ struct mesh_sar {
 	unsigned int id;
 	struct l_timeout *seg_timeout;
 	struct l_timeout *msg_timeout;
-	mesh_net_status_func_t status_func;
-	void *user_data;
 	uint32_t flags;
 	uint32_t last_nak;
 	uint32_t iv_index;
@@ -1657,12 +1655,6 @@ static void outmsg_to(struct l_timeout *msg_timeout, void *user_data)
 		return;
 
 	sar->msg_timeout = NULL;
-
-	if (sar->status_func)
-		sar->status_func(sar->remote, 1,
-				sar->buf, sar->len - 4,
-				sar->user_data);
-
 	mesh_sar_free(sar);
 }
 
@@ -1712,10 +1704,6 @@ static void ack_received(struct mesh_net *net, bool timeout,
 		l_debug("ob_sar_removal (%x)", outgoing->flags);
 
 		/* Note: ack_flags == 0x00000000 is a remote Cancel request */
-		if (outgoing->status_func)
-			outgoing->status_func(src, ack_flag ? 0 : 1,
-					outgoing->buf,
-					outgoing->len - 4, outgoing->user_data);
 
 		l_queue_remove(net->sar_out, outgoing);
 		send_queued_sar(net, outgoing->remote);
@@ -3154,9 +3142,7 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 				uint16_t dst, uint8_t key_aid, uint16_t net_idx,
 				uint8_t ttl, uint32_t seq, uint32_t iv_index,
 				bool segmented, bool szmic,
-				const void *msg, uint16_t msg_len,
-				mesh_net_status_func_t status_func,
-				void *user_data)
+				const void *msg, uint16_t msg_len)
 {
 	struct mesh_sar *payload = NULL;
 	uint8_t seg, seg_max;
@@ -3214,8 +3200,6 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 	if (segmented) {
 		payload->flags = 0xffffffff >> (31 - seg_max);
 		payload->seqZero = seq & SEQ_ZERO_MASK;
-		payload->status_func = status_func;
-		payload->user_data = user_data;
 		payload->id = ++net->sar_id_next;
 
 		/* Single thread SAR messages to same Unicast DST */
@@ -3251,8 +3235,6 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 			l_timeout_create(SEG_TO, outseg_to, net, NULL);
 		payload->msg_timeout =
 			l_timeout_create(MSG_TO, outmsg_to, net, NULL);
-		payload->status_func = status_func;
-		payload->user_data = user_data;
 		payload->id = ++net->sar_id_next;
 	} else
 		mesh_sar_free(payload);
diff --git a/mesh/net.h b/mesh/net.h
index 8646d5aef..12808ce38 100644
--- a/mesh/net.h
+++ b/mesh/net.h
@@ -260,9 +260,6 @@ struct mesh_friend_msg {
 };
 
 typedef void (*mesh_status_func_t)(void *user_data, bool result);
-typedef void (*mesh_net_status_func_t)(uint16_t remote, uint8_t status,
-					void *data, uint16_t size,
-					void *user_data);
 
 struct mesh_net *mesh_net_new(struct mesh_node *node);
 void mesh_net_free(void *net);
@@ -313,10 +310,8 @@ void mesh_net_transport_send(struct mesh_net *net, uint32_t key_id,
 bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 				uint16_t dst, uint8_t key_id, uint16_t net_idx,
 				uint8_t ttl, uint32_t seq, uint32_t iv_index,
-				bool segmented, bool szmic,
-				const void *msg, uint16_t msg_len,
-				mesh_net_status_func_t status_func,
-				void *user_data);
+				bool segmented, bool szmic, const void *msg,
+				uint16_t msg_len);
 void mesh_net_ack_send(struct mesh_net *net, uint32_t key_id,
 				uint32_t iv_index, uint8_t ttl, uint32_t seq,
 				uint16_t src, uint16_t dst, bool rly,
-- 
2.26.2


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

* [PATCH BlueZ 4/5] mesh: Clean up style in net.c
  2020-05-29  6:37 [PATCH BlueZ 0/5] Mesh clean up Inga Stotland
                   ` (2 preceding siblings ...)
  2020-05-29  6:37 ` [PATCH BlueZ 3/5] mesh: Remove debug-only related callback for packet send Inga Stotland
@ 2020-05-29  6:37 ` Inga Stotland
  2020-05-29  7:08   ` [BlueZ,4/5] " bluez.test.bot
  2020-05-29  6:37 ` [PATCH BlueZ 5/5] mesh: Remove unused functions from net.c Inga Stotland
  4 siblings, 1 reply; 8+ messages in thread
From: Inga Stotland @ 2020-05-29  6:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

---
 mesh/net.c | 253 +++++++++++++++++++++--------------------------------
 1 file changed, 100 insertions(+), 153 deletions(-)

diff --git a/mesh/net.c b/mesh/net.c
index 08544ad61..af891e5a9 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -520,7 +520,8 @@ uint32_t mesh_net_next_seq_num(struct mesh_net *net)
 {
 	uint32_t seq = net->seq_num++;
 
-	/* Cap out-of-range seq_num max value to +1. Out of range
+	/*
+	 * Cap out-of-range seq_num max value to +1. Out of range
 	 * seq_nums will not be sent as they would violate spec.
 	 * This condition signals a runaway seq_num condition, and
 	 * the node must wait for a completed IV Index update procedure
@@ -539,9 +540,7 @@ static struct mesh_sar *mesh_sar_new(size_t len)
 	struct mesh_sar *sar;
 
 	sar = l_malloc(size);
-
 	memset(sar, 0, size);
-
 	return sar;
 }
 
@@ -1372,20 +1371,18 @@ enqueue:
 			void *old = l_queue_remove_if(frnd->pkt_cache,
 							match_ack, rx);
 
-			if (old) {
-				if (old_head == old) {
-					/*
-					 * If we are discarding head for any
-					 * reason, reset FRND SEQ
-					 */
-					frnd->u.active.last =
-							frnd->u.active.seq;
-				}
-
-				l_free(old);
-			} else
+			if (!old)
 				break;
 
+			if (old_head == old)
+				/*
+				 * If we are discarding head for any
+				 * reason, reset FRND SEQ
+				 */
+				frnd->u.active.last = frnd->u.active.seq;
+
+			l_free(old);
+
 		} while (true);
 	}
 
@@ -1465,6 +1462,7 @@ static bool friend_packet_queue(struct mesh_net *net,
 			data += 12;
 			hdr += (1 << SEGO_HDR_SHIFT);
 		}
+
 		frnd_msg->u.s12[seg_max].seq = seq;
 		frnd_msg->cnt_in = seg_max;
 		frnd_msg->last_len = size % 12;
@@ -1488,6 +1486,7 @@ static bool friend_packet_queue(struct mesh_net *net,
 			memcpy(frnd_msg->u.one[0].data, data, size);
 			frnd_msg->last_len = size;
 		}
+
 		frnd_msg->u.one[0].hdr = hdr;
 		frnd_msg->u.one[0].seq = seq;
 	}
@@ -1640,7 +1639,6 @@ static void inmsg_to(struct l_timeout *msg_timeout, void *user_data)
 		return;
 
 	sar->msg_timeout = NULL;
-
 	mesh_sar_free(sar);
 }
 
@@ -2034,10 +2032,8 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
 		send_net_ack(net, sar_in, expected);
 
 		msg_rxed(net, frnd, iv_index, ttl, seq, net_idx,
-				sar_in->remote, dst,
-				key_aid, true, szmic,
-				sar_in->seqZero,
-				sar_in->buf, sar_in->len);
+				sar_in->remote, dst, key_aid, true, szmic,
+				sar_in->seqZero, sar_in->buf, sar_in->len);
 
 		/* Kill Inter-Seg timeout */
 		l_timeout_remove(sar_in->seg_timeout);
@@ -2080,12 +2076,8 @@ static bool ctl_received(struct mesh_net *net, uint16_t key_id,
 		uint32_t hdr = opcode << OPCODE_HDR_SHIFT;
 		uint8_t frnd_ttl = ttl - 1;
 
-		if (friend_packet_queue(net, iv_index,
-					true, frnd_ttl,
-					seq,
-					src, dst,
-					hdr,
-					pkt, len))
+		if (friend_packet_queue(net, iv_index, true, frnd_ttl, seq,
+						src, dst, hdr, pkt, len))
 			return true;
 	}
 
@@ -2103,10 +2095,8 @@ static bool ctl_received(struct mesh_net *net, uint16_t key_id,
 			return false;
 
 		print_packet("Rx-NET_OP_FRND_POLL", pkt, len);
-		friend_poll(net, src, !!(pkt[0]),
-				l_queue_find(net->friends,
-						match_by_friend,
-						L_UINT_TO_PTR(src)));
+		friend_poll(net, src, !!(pkt[0]), l_queue_find(net->friends,
+					match_by_friend, L_UINT_TO_PTR(src)));
 		break;
 
 	case NET_OP_FRND_REQUEST:
@@ -2142,8 +2132,7 @@ static bool ctl_received(struct mesh_net *net, uint16_t key_id,
 
 		print_packet("Rx-NET_OP_FRND_CLEAR", pkt, len);
 		friend_clear(net, src, l_get_be16(pkt), l_get_be16(pkt + 2),
-				l_queue_find(net->friends,
-					match_by_friend,
+				l_queue_find(net->friends, match_by_friend,
 					L_UINT_TO_PTR(l_get_be16(pkt))));
 		l_debug("Remaining Friends: %d", l_queue_length(net->friends));
 		break;
@@ -2163,9 +2152,8 @@ static bool ctl_received(struct mesh_net *net, uint16_t key_id,
 			return false;
 
 		print_packet("Rx-NET_OP_PROXY_SUB_REMOVE", pkt, len);
-		friend_sub_del(net, l_queue_find(net->friends,
-					match_by_friend, L_UINT_TO_PTR(src)),
-				pkt, len);
+		friend_sub_del(net, l_queue_find(net->friends, match_by_friend,
+						L_UINT_TO_PTR(src)), pkt, len);
 		break;
 
 	case NET_OP_PROXY_SUB_CONFIRM:
@@ -2199,12 +2187,10 @@ static bool ctl_received(struct mesh_net *net, uint16_t key_id,
 		break;
 	}
 
-	if (n) {
-		mesh_net_transport_send(net, 0, 0,
-				mesh_net_get_iv_index(net), rsp_ttl,
-				0, dst & 0x8000 ? 0 : dst, src,
-				msg, n);
-	}
+	if (n)
+		mesh_net_transport_send(net, 0, 0, mesh_net_get_iv_index(net),
+					rsp_ttl, 0, dst & 0x8000 ? 0 : dst,
+					src, msg, n);
 
 	return true;
 }
@@ -2335,17 +2321,12 @@ static enum _relay_advice packet_received(void *user_data,
 
 	print_packet("RX: Network [clr] :", packet + 2, size);
 
-	if (!mesh_crypto_packet_parse(packet + 2, size,
-					&net_ctl, &net_ttl,
-					&net_seq,
-					&net_src, &net_dst,
-					&cache_cookie,
-					&net_opcode,
-					&net_segmented,
-					&net_key_id,
-					&net_szmic, &net_relay, &net_seqZero,
-					&net_segO, &net_segN,
-					&msg, &app_msg_len)) {
+	if (!mesh_crypto_packet_parse(packet + 2, size, &net_ctl, &net_ttl,
+					&net_seq, &net_src, &net_dst,
+					&cache_cookie, &net_opcode,
+					&net_segmented, &net_key_id, &net_szmic,
+					&net_relay, &net_seqZero, &net_segO,
+					&net_segN, &msg, &app_msg_len)) {
 		l_error("Failed to parse packet content");
 		return RELAY_NONE;
 	}
@@ -2360,8 +2341,10 @@ static enum _relay_advice packet_received(void *user_data,
 	if (is_us(net, net_src, true))
 		return RELAY_NONE;
 
-	/* As a Relay, suppress repeats of last N packets that pass through */
-	/* The "cache_cookie" should be unique part of App message */
+	/*
+	 * As a Relay, suppress repeats of last N packets that pass through
+	 * The "cache_cookie" should be unique part of App message.
+	 */
 	if (msg_in_cache(net, net_src, net_seq, cache_cookie))
 		return RELAY_NONE;
 
@@ -2388,57 +2371,48 @@ static enum _relay_advice packet_received(void *user_data,
 				/* If this is an ACK to our friend queue-only */
 				if (is_lpn_friend(net, net_dst))
 					friend_ack_rxed(net, iv_index, net_seq,
-							net_src, net_dst,
-							msg);
+							net_src, net_dst, msg);
 				else
 					ack_received(net, false,
 							net_src, net_dst,
 							net_seqZero,
 							l_get_be32(msg + 3));
 			} else {
-				ctl_received(net, key_id,
-						iv_index,
-						net_ttl, net_seq, net_src,
-						net_dst, net_opcode, rssi,
-						msg, app_msg_len);
+				ctl_received(net, key_id, iv_index, net_ttl,
+						net_seq, net_src, net_dst,
+						net_opcode, rssi, msg,
+								app_msg_len);
 			}
 		} else if (net_segmented) {
-			/* If we accept SAR packets to non-Unicast, then
+			/*
+			 * If we accept SAR packets to non-Unicast, then
 			 * Friend Sar at least needs to be Unicast Only
 			 */
 			if (is_lpn_friend(net, net_dst) &&
 							!(net_dst & 0x8000)) {
-				/* Check TTL >= 2 before accepting segments
+				/*
+				 * Check TTL >= 2 before accepting segments
 				 * for Friends
 				 */
 				if (net_ttl >= 2) {
-					friend_seg_rxed(net, iv_index,
-						net_ttl, net_seq,
-						net_src, net_dst,
+					friend_seg_rxed(net, iv_index, net_ttl,
+						net_seq, net_src, net_dst,
 						l_get_be32(packet + 2 + 9),
 						msg, app_msg_len);
 				}
 			} else {
 				seg_rxed(net, NULL, iv_index, net_ttl,
-						net_seq, net_idx,
-						net_src, net_dst,
-						net_key_id,
-						net_szmic, net_seqZero,
-						net_segO, net_segN,
+						net_seq, net_idx, net_src,
+						net_dst, net_key_id, net_szmic,
+						net_seqZero, net_segO, net_segN,
 						msg, app_msg_len);
 			}
 
 		} else {
-			msg_rxed(net, NULL,
-						iv_index,
-						net_ttl,
-						net_seq,
-						net_idx,
-						net_src, net_dst,
-						net_key_id,
-						false, false,
-						net_seq & SEQ_ZERO_MASK,
-						msg, app_msg_len);
+			msg_rxed(net, NULL, iv_index, net_ttl, net_seq, net_idx,
+					net_src, net_dst, net_key_id, false,
+					false, net_seq & SEQ_ZERO_MASK, msg,
+					app_msg_len);
 		}
 
 		/* If this is one of our Unicast addresses, disallow relay */
@@ -2495,8 +2469,8 @@ static void net_rx(void *net_ptr, void *user_data)
 		rssi = data->info->rssi;
 	}
 
-	relay_advice = packet_received(net, key_id, iv_index,
-							out, out_size, rssi);
+	relay_advice = packet_received(net, key_id, iv_index, out, out_size,
+									rssi);
 	if (relay_advice > data->relay_advice) {
 		data->iv_index = iv_index;
 		data->relay_advice = relay_advice;
@@ -2560,6 +2534,7 @@ static void iv_upd_to(struct l_timeout *upd_timeout, void *user_data)
 		l_debug("iv_upd_state = IV_UPD_NORMAL_HOLD");
 		net->iv_upd_state = IV_UPD_NORMAL_HOLD;
 		l_timeout_modify(net->iv_update_timeout, IV_IDX_UPD_MIN);
+
 		if (net->iv_update)
 			mesh_net_set_seq_num(net, 0);
 
@@ -2578,10 +2553,12 @@ static void iv_upd_to(struct l_timeout *upd_timeout, void *user_data)
 		net->iv_update_timeout = NULL;
 		l_debug("iv_upd_state = IV_UPD_NORMAL");
 		net->iv_upd_state = IV_UPD_NORMAL;
+
 		if (net->iv_update)
 			mesh_net_set_seq_num(net, 0);
 
 		net->iv_update = false;
+
 		if (net->seq_num > IV_UPDATE_SEQ_TRIGGER)
 			mesh_net_iv_index_update(net);
 		break;
@@ -2605,7 +2582,8 @@ static int key_refresh_phase_two(struct mesh_net *net, uint16_t idx)
 	l_debug("Key refresh procedure phase 2: start using new net TX keys");
 	subnet->key_refresh = 1;
 	subnet->net_key_tx = subnet->net_key_upd;
-	/* TODO: Provisioner may need to stay in phase three until
+	/*
+	 * TODO: Provisioner may need to stay in phase three until
 	 * it hears beacons from all the nodes
 	 */
 	subnet->kr_phase = KEY_REFRESH_PHASE_TWO;
@@ -2686,7 +2664,8 @@ static void update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index,
 			if (iv_index == net->iv_index && !net->iv_update)
 				return;
 
-			/* Other devices will be accepting old or new iv_index,
+			/*
+			 * Other devices will be accepting old or new iv_index,
 			 * but we don't know how far through update they are.
 			 * Starting permissive state will allow us maximum
 			 * (96 hours) to resync
@@ -2694,7 +2673,7 @@ static void update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index,
 			l_debug("iv_upd_state = IV_UPD_UPDATING");
 			net->iv_upd_state = IV_UPD_UPDATING;
 			net->iv_update_timeout = l_timeout_create(
-				IV_IDX_UPD_MIN, iv_upd_to, net, NULL);
+					IV_IDX_UPD_MIN, iv_upd_to, net, NULL);
 		} else {
 			l_debug("iv_upd_state = IV_UPD_NORMAL");
 			net->iv_upd_state = IV_UPD_NORMAL;
@@ -2771,8 +2750,8 @@ static void process_beacon(void *net_ptr, void *user_data)
 	 * Ignore the beacon if it doesn't change anything, unless we're
 	 * doing IV Recovery
 	 */
-	if (net->iv_upd_state == IV_UPD_INIT ||
-				ivi != net->iv_index || ivu != net->iv_update)
+	if (net->iv_upd_state == IV_UPD_INIT || ivi != net->iv_index ||
+							ivu != net->iv_update)
 		update_iv_ivu_state(net, ivi, ivu);
 
 	if (kr != local_kr)
@@ -2879,6 +2858,7 @@ bool mesh_net_set_key(struct mesh_net *net, uint16_t idx, const uint8_t *key,
 	if (phase == KEY_REFRESH_PHASE_TWO) {
 		subnet->key_refresh = 1;
 		subnet->net_key_tx = subnet->net_key_upd;
+
 		if (net->beacon_enable) {
 			/* Switch beaconing key */
 			net_key_beacon_disable(subnet->net_key_cur);
@@ -2958,6 +2938,7 @@ bool mesh_net_iv_index_update(struct mesh_net *net)
 
 	l_debug("iv_upd_state = IV_UPD_UPDATING");
 	mesh_net_flush_msg_queues(net);
+
 	if (!mesh_config_write_iv_index(node_config_get(net->node),
 						net->iv_index + 1, true))
 		return false;
@@ -3077,7 +3058,7 @@ static bool send_seg(struct mesh_net *net, struct mesh_sar *msg, uint8_t segO)
 		return false;
 
 	if (!net_key_encrypt(subnet->net_key_tx, msg->iv_index, packet + 1,
-							     packet_len)) {
+								packet_len)) {
 		l_error("Failed to encode packet");
 		return false;
 	}
@@ -3090,12 +3071,9 @@ static bool send_seg(struct mesh_net *net, struct mesh_sar *msg, uint8_t segO)
 }
 
 void mesh_net_send_seg(struct mesh_net *net, uint32_t net_key_id,
-				uint32_t iv_index,
-				uint8_t ttl,
-				uint32_t seq,
-				uint16_t src, uint16_t dst,
-				uint32_t hdr,
-				const void *seg, uint16_t seg_len)
+			uint32_t iv_index, uint8_t ttl, uint32_t seq,
+			uint16_t src, uint16_t dst, uint32_t hdr,
+			const void *seg, uint16_t seg_len)
 {
 	uint8_t packet[30];
 	uint8_t packet_len;
@@ -3112,15 +3090,10 @@ void mesh_net_send_seg(struct mesh_net *net, uint32_t net_key_id,
 	l_debug("SEQ0: %6.6x", seq);
 	l_debug("segO: %d", segO);
 
-	if (!mesh_crypto_packet_build(false, ttl,
-				seq,
-				src, dst,
-				0,
-				segmented, app_key_id,
-				szmic, false, seqZero,
-				segO, segN,
-				seg, seg_len,
-				packet + 1, &packet_len)) {
+	if (!mesh_crypto_packet_build(false, ttl, seq, src, dst, 0,
+					segmented, app_key_id, szmic, false,
+					seqZero, segO, segN, seg, seg_len,
+					packet + 1, &packet_len)) {
 		l_error("Failed to build packet");
 		return;
 	}
@@ -3166,12 +3139,8 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 	segmented |= !!(seg_max);
 
 	/* First enqueue to any Friends and internal models */
-	result = msg_rxed(net, false, iv_index, ttl,
-				seq,
-				net_idx,
-				src, dst,
-				key_aid, segmented,
-				szmic, seq & SEQ_ZERO_MASK,
+	result = msg_rxed(net, false, iv_index, ttl, seq, net_idx, src, dst,
+				key_aid, segmented, szmic, seq & SEQ_ZERO_MASK,
 				msg, msg_len);
 
 	/*
@@ -3203,7 +3172,7 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 		payload->id = ++net->sar_id_next;
 
 		/* Single thread SAR messages to same Unicast DST */
-		if (NULL != l_queue_find(net->sar_out, match_sar_remote,
+		if (l_queue_find(net->sar_out, match_sar_remote,
 							L_UINT_TO_PTR(dst))) {
 			/* Delay sending Outbound SAR unless prior
 			 * SAR to same DST has completed */
@@ -3242,13 +3211,9 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
 	return result;
 }
 
-void mesh_net_ack_send(struct mesh_net *net, uint32_t key_id,
-				uint32_t iv_index,
-				uint8_t ttl,
-				uint32_t seq,
-				uint16_t src, uint16_t dst,
-				bool rly, uint16_t seqZero,
-				uint32_t ack_flags)
+void mesh_net_ack_send(struct mesh_net *net, uint32_t key_id, uint32_t iv_index,
+			uint8_t ttl, uint32_t seq, uint16_t src, uint16_t dst,
+			bool rly, uint16_t seqZero, uint32_t ack_flags)
 {
 	uint32_t hdr;
 	uint8_t data[7];
@@ -3260,18 +3225,13 @@ void mesh_net_ack_send(struct mesh_net *net, uint32_t key_id,
 	hdr |= (seqZero & SEQ_ZERO_MASK) << SEQ_ZERO_HDR_SHIFT;
 	l_put_be32(hdr, data);
 	l_put_be32(ack_flags, data + 3);
-	if (!mesh_crypto_packet_build(true, ttl,
-					seq,
-					src, dst,
-					NET_OP_SEG_ACKNOWLEDGE,
-					false, /* Not Segmented */
-					0,	/* No Key ID associated */
-					false, rly, seqZero,
-					0, 0,	/* no segO or segN */
-					data + 1, 6,
-					pkt + 1, &pkt_len)) {
+
+	/* Not Segmented, no Key ID associated, no segO or segN */
+	if (!mesh_crypto_packet_build(true, ttl, seq, src, dst,
+					NET_OP_SEG_ACKNOWLEDGE, false, 0, false,
+					rly, seqZero, 0, 0, data + 1, 6,
+					pkt + 1, &pkt_len))
 		return;
-	}
 
 	if (!key_id) {
 		struct mesh_subnet *subnet = get_primary_subnet(net);
@@ -3323,24 +3283,17 @@ void mesh_net_transport_send(struct mesh_net *net, uint32_t key_id,
 		uint32_t hdr = msg[0] << OPCODE_HDR_SHIFT;
 		uint8_t frnd_ttl = ttl;
 
-		if (friend_packet_queue(net, iv_index,
-					true, frnd_ttl,
-					mesh_net_next_seq_num(net),
-					src, dst,
-					hdr,
-					msg + 1, msg_len - 1)) {
+		if (friend_packet_queue(net, iv_index, true, frnd_ttl,
+					mesh_net_next_seq_num(net), src, dst,
+					hdr, msg + 1, msg_len - 1))
 			return;
-		}
 	}
 
 	/* Deliver to Local entities if applicable */
-	if (!(dst & 0x8000) && src >= net->src_addr && src <= net->last_addr) {
-		result = ctl_received(net, key_id,
-					iv_index, ttl,
-					mesh_net_next_seq_num(net),
-					src, dst,
+	if (!(dst & 0x8000) && src >= net->src_addr && src <= net->last_addr)
+		result = ctl_received(net, key_id, iv_index, ttl,
+					mesh_net_next_seq_num(net), src, dst,
 					msg[0], 0, msg + 1, msg_len - 1);
-	}
 
 	if (!key_id) {
 		struct mesh_subnet *subnet = l_queue_find(net->subnets,
@@ -3355,15 +3308,9 @@ void mesh_net_transport_send(struct mesh_net *net, uint32_t key_id,
 			return;
 	}
 
-	if (!mesh_crypto_packet_build(true, ttl,
-				use_seq,
-				src, dst,
-				msg[0],
-				false, 0,
-				false, false, 0,
-				0, 0,
-				msg + 1, msg_len - 1,
-				pkt + 1, &pkt_len))
+	if (!mesh_crypto_packet_build(true, ttl, use_seq, src, dst, msg[0],
+				false, 0, false, false, 0, 0, 0, msg + 1,
+				msg_len - 1, pkt + 1, &pkt_len))
 		return;
 
 	if (!net_key_encrypt(key_id, iv_index, pkt + 1, pkt_len)) {
@@ -3517,7 +3464,7 @@ void mesh_net_heartbeat_send(struct mesh_net *net)
 	n += 2;
 
 	mesh_net_transport_send(net, 0, 0, mesh_net_get_iv_index(net),
-				hb->pub_ttl, 0, 0, hb->pub_dst, msg, n);
+					hb->pub_ttl, 0, 0, hb->pub_dst, msg, n);
 }
 
 void mesh_net_heartbeat_init(struct mesh_net *net)
@@ -3575,7 +3522,7 @@ uint16_t mesh_net_get_primary_idx(struct mesh_net *net)
 uint32_t mesh_net_friend_timeout(struct mesh_net *net, uint16_t addr)
 {
 	struct mesh_friend *frnd = l_queue_find(net->friends, match_by_friend,
-						L_UINT_TO_PTR(addr));
+							L_UINT_TO_PTR(addr));
 
 	if (!frnd)
 		return 0;
-- 
2.26.2


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

* [PATCH BlueZ 5/5] mesh: Remove unused functions from net.c
  2020-05-29  6:37 [PATCH BlueZ 0/5] Mesh clean up Inga Stotland
                   ` (3 preceding siblings ...)
  2020-05-29  6:37 ` [PATCH BlueZ 4/5] mesh: Clean up style in net.c Inga Stotland
@ 2020-05-29  6:37 ` Inga Stotland
  4 siblings, 0 replies; 8+ messages in thread
From: Inga Stotland @ 2020-05-29  6:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

The folllowing functionsa are not being used anywhere in the code and
have been removed:
mesh_net_flush()
mesh_net_prov_caps_get()
mesh_net_priv_key_get()
mesh_net_priv_key_set()
mesh_net_prov_rand()
mesh_net_prov_uni()
mesh_net_id_uuid_set()
mesh_net_test_addr()
mesh_net_test_mode()
mesh_net_uni_range_set()
mesh_net_uni_range_get()
mesh_net_set_window_accuracy()
---
 mesh/net.c | 149 ++---------------------------------------------------
 mesh/net.h |  21 --------
 2 files changed, 4 insertions(+), 166 deletions(-)

diff --git a/mesh/net.c b/mesh/net.c
index af891e5a9..07813eec4 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -124,7 +124,6 @@ struct mesh_net {
 	uint8_t chan; /* Channel of recent Rx */
 	uint8_t default_ttl;
 	uint8_t tid;
-	uint8_t window_accuracy;
 
 	struct {
 		bool enable;
@@ -144,21 +143,6 @@ struct mesh_net {
 	struct l_queue *friends;
 	struct l_queue *negotiations;
 	struct l_queue *destinations;
-
-	uint8_t prov_priv_key[32];
-
-	/* Unprovisioned Identity */
-	char id_name[20];
-	uint8_t id_uuid[16];
-
-	/* Provisioner: unicast address range */
-	struct mesh_net_addr_range prov_uni_addr;
-
-	/* Test Data */
-	uint8_t prov_rand[16];
-	uint8_t test_bd_addr[6];
-	struct mesh_net_prov_caps prov_caps;
-	bool test_mode;
 };
 
 struct mesh_msg {
@@ -648,9 +632,6 @@ struct mesh_net *mesh_net_new(struct mesh_node *node)
 	net->seq_num = DEFAULT_SEQUENCE_NUMBER;
 	net->default_ttl = TTL_MASK;
 
-	memset(&net->prov_caps, 0, sizeof(net->prov_caps));
-	net->prov_caps.algorithms = 1;
-
 	net->tx_cnt = DEFAULT_TRANSMIT_COUNT;
 	net->tx_interval = DEFAULT_TRANSMIT_INTERVAL;
 
@@ -829,93 +810,6 @@ bool mesh_net_set_relay_mode(struct mesh_net *net, bool enable,
 	return true;
 }
 
-struct mesh_net_prov_caps *mesh_net_prov_caps_get(struct mesh_net *net)
-{
-	if (net)
-		return &net->prov_caps;
-
-	return NULL;
-}
-
-char *mesh_net_id_name(struct mesh_net *net)
-{
-	if (net && net->id_name[0])
-		return net->id_name;
-
-	return NULL;
-}
-
-bool mesh_net_id_uuid_set(struct mesh_net *net, uint8_t uuid[16])
-{
-	if (!net)
-		return false;
-
-	memcpy(net->id_uuid, uuid, 16);
-
-	return true;
-}
-
-uint8_t *mesh_net_priv_key_get(struct mesh_net *net)
-{
-	if (net)
-		return net->prov_priv_key;
-
-	return NULL;
-}
-
-bool mesh_net_priv_key_set(struct mesh_net *net, uint8_t key[32])
-{
-	if (!net)
-		return false;
-
-	memcpy(net->prov_priv_key, key, 32);
-	return true;
-}
-
-uint8_t *mesh_net_test_addr(struct mesh_net *net)
-{
-	const uint8_t zero_addr[] = {0, 0, 0, 0, 0, 0};
-
-	if (net && memcmp(net->test_bd_addr, zero_addr, 6))
-		return net->test_bd_addr;
-
-	return NULL;
-}
-
-uint8_t *mesh_net_prov_rand(struct mesh_net *net)
-{
-	if (net)
-		return net->prov_rand;
-
-	return NULL;
-}
-
-uint16_t mesh_net_prov_uni(struct mesh_net *net, uint8_t ele_cnt)
-{
-	uint16_t uni;
-	uint16_t next;
-
-	if (!net)
-		return 0;
-
-	next = net->prov_uni_addr.next + ele_cnt;
-	if (next > 0x8000 || next > net->prov_uni_addr.high)
-		return UNASSIGNED_ADDRESS;
-
-	uni = net->prov_uni_addr.next;
-	net->prov_uni_addr.next = next;
-
-	return uni;
-}
-
-bool mesh_net_test_mode(struct mesh_net *net)
-{
-	if (net)
-		return net->test_mode;
-
-	return false;
-}
-
 int mesh_net_get_identity_mode(struct mesh_net *net, uint16_t idx,
 								uint8_t *mode)
 {
@@ -1026,11 +920,6 @@ int mesh_net_add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
 	return MESH_STATUS_SUCCESS;
 }
 
-void mesh_net_flush_msg_queues(struct mesh_net *net)
-{
-	l_queue_clear(net->msg_cache, l_free);
-}
-
 uint32_t mesh_net_get_iv_index(struct mesh_net *net)
 {
 	if (!net)
@@ -2543,7 +2432,7 @@ static void iv_upd_to(struct l_timeout *upd_timeout, void *user_data)
 							net->iv_index, false);
 		l_queue_foreach(net->subnets, refresh_beacon, net);
 		queue_friend_update(net);
-		mesh_net_flush_msg_queues(net);
+		l_queue_clear(net->msg_cache, l_free);
 		break;
 
 	case IV_UPD_INIT:
@@ -2937,7 +2826,7 @@ bool mesh_net_iv_index_update(struct mesh_net *net)
 		return false;
 
 	l_debug("iv_upd_state = IV_UPD_UPDATING");
-	mesh_net_flush_msg_queues(net);
+	l_queue_clear(net->msg_cache, l_free);
 
 	if (!mesh_config_write_iv_index(node_config_get(net->node),
 						net->iv_index + 1, true))
@@ -2999,15 +2888,6 @@ bool mesh_net_dst_unreg(struct mesh_net *net, uint16_t dst)
 	return true;
 }
 
-bool mesh_net_flush(struct mesh_net *net)
-{
-	if (!net)
-		return false;
-
-	/* TODO mesh-io Flush */
-	return true;
-}
-
 static bool send_seg(struct mesh_net *net, struct mesh_sar *msg, uint8_t segO)
 {
 	struct mesh_subnet *subnet;
@@ -3430,7 +3310,7 @@ int mesh_net_update_key(struct mesh_net *net, uint16_t idx,
 	return MESH_STATUS_SUCCESS;
 }
 
-uint16_t mesh_net_get_features(struct mesh_net *net)
+static uint16_t get_features(struct mesh_net *net)
 {
 	uint16_t features = 0;
 
@@ -3473,20 +3353,7 @@ void mesh_net_heartbeat_init(struct mesh_net *net)
 
 	memset(hb, 0, sizeof(struct mesh_net_heartbeat));
 	hb->sub_min_hops = 0xff;
-	hb->features = mesh_net_get_features(net);
-}
-
-void mesh_net_uni_range_set(struct mesh_net *net,
-				struct mesh_net_addr_range *range)
-{
-	net->prov_uni_addr.low = range->low;
-	net->prov_uni_addr.high = range->high;
-	net->prov_uni_addr.next = range->next;
-}
-
-struct mesh_net_addr_range mesh_net_uni_range_get(struct mesh_net *net)
-{
-	return net->prov_uni_addr;
+	hb->features = get_features(net);
 }
 
 void mesh_net_set_iv_index(struct mesh_net *net, uint32_t index, bool update)
@@ -3582,14 +3449,6 @@ bool mesh_net_is_local_address(struct mesh_net *net, uint16_t src,
 			(last >= net->src_addr && last <= net->last_addr);
 }
 
-void mesh_net_set_window_accuracy(struct mesh_net *net, uint8_t accuracy)
-{
-	if (!net)
-		return;
-
-	net->window_accuracy = accuracy;
-}
-
 void mesh_net_transmit_params_set(struct mesh_net *net, uint8_t count,
 							uint16_t interval)
 {
diff --git a/mesh/net.h b/mesh/net.h
index 12808ce38..84e7c1545 100644
--- a/mesh/net.h
+++ b/mesh/net.h
@@ -120,12 +120,6 @@ struct mesh_node;
 #define DEFAULT_MIN_DELAY		0
 #define DEFAULT_MAX_DELAY		25
 
-struct mesh_net_addr_range {
-	uint16_t low;
-	uint16_t high;
-	uint16_t next;
-};
-
 struct mesh_net_prov_caps {
 	uint8_t num_ele;
 	uint16_t algorithms;
@@ -264,7 +258,6 @@ typedef void (*mesh_status_func_t)(void *user_data, bool result);
 struct mesh_net *mesh_net_new(struct mesh_node *node);
 void mesh_net_free(void *net);
 void mesh_net_cleanup(void);
-void mesh_net_flush_msg_queues(struct mesh_net *net);
 void mesh_net_set_iv_index(struct mesh_net *net, uint32_t index, bool update);
 bool mesh_net_iv_index_update(struct mesh_net *net);
 bool mesh_net_set_seq_num(struct mesh_net *net, uint32_t number);
@@ -300,7 +293,6 @@ bool mesh_net_attach(struct mesh_net *net, struct mesh_io *io);
 struct mesh_io *mesh_net_detach(struct mesh_net *net);
 struct l_queue *mesh_net_get_app_keys(struct mesh_net *net);
 
-bool mesh_net_flush(struct mesh_net *net);
 void mesh_net_transport_send(struct mesh_net *net, uint32_t key_id,
 				uint16_t net_idx, uint32_t iv_index,
 				uint8_t ttl, uint32_t seq, uint16_t src,
@@ -316,17 +308,9 @@ void mesh_net_ack_send(struct mesh_net *net, uint32_t key_id,
 				uint32_t iv_index, uint8_t ttl, uint32_t seq,
 				uint16_t src, uint16_t dst, bool rly,
 				uint16_t seqZero, uint32_t ack_flags);
-struct mesh_net_prov_caps *mesh_net_prov_caps_get(struct mesh_net *net);
-uint8_t *mesh_net_priv_key_get(struct mesh_net *net);
-bool mesh_net_priv_key_set(struct mesh_net *net, uint8_t key[32]);
-uint8_t *mesh_net_prov_rand(struct mesh_net *net);
-uint16_t mesh_net_prov_uni(struct mesh_net *net, uint8_t ele_cnt);
-bool mesh_net_id_uuid_set(struct mesh_net *net, uint8_t uuid[16]);
-uint8_t *mesh_net_test_addr(struct mesh_net *net);
 int mesh_net_get_identity_mode(struct mesh_net *net, uint16_t idx,
 								uint8_t *mode);
 char *mesh_net_id_name(struct mesh_net *net);
-bool mesh_net_test_mode(struct mesh_net *net);
 bool mesh_net_dst_reg(struct mesh_net *net, uint16_t dst);
 bool mesh_net_dst_unreg(struct mesh_net *net, uint16_t dst);
 struct mesh_friend *mesh_friend_new(struct mesh_net *net, uint16_t dst,
@@ -348,13 +332,9 @@ void mesh_net_send_seg(struct mesh_net *net, uint32_t key_id,
 				uint32_t iv_index, uint8_t ttl, uint32_t seq,
 				uint16_t src, uint16_t dst, uint32_t hdr,
 				const void *seg, uint16_t seg_len);
-uint16_t mesh_net_get_features(struct mesh_net *net);
 struct mesh_net_heartbeat *mesh_net_heartbeat_get(struct mesh_net *net);
 void mesh_net_heartbeat_init(struct mesh_net *net);
 void mesh_net_heartbeat_send(struct mesh_net *net);
-void mesh_net_uni_range_set(struct mesh_net *net,
-				struct mesh_net_addr_range *range);
-struct mesh_net_addr_range mesh_net_uni_range_get(struct mesh_net *net);
 void mesh_net_provisioner_mode_set(struct mesh_net *net, bool mode);
 bool mesh_net_provisioner_mode_get(struct mesh_net *net);
 bool mesh_net_key_list_get(struct mesh_net *net, uint8_t *buf, uint16_t *count);
@@ -365,7 +345,6 @@ struct mesh_node *mesh_net_node_get(struct mesh_net *net);
 bool mesh_net_have_key(struct mesh_net *net, uint16_t net_idx);
 bool mesh_net_is_local_address(struct mesh_net *net, uint16_t src,
 							uint16_t count);
-void mesh_net_set_window_accuracy(struct mesh_net *net, uint8_t accuracy);
 void mesh_net_transmit_params_set(struct mesh_net *net, uint8_t count,
 							uint16_t interval);
 void mesh_net_transmit_params_get(struct mesh_net *net, uint8_t *count,
-- 
2.26.2


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

* RE: [BlueZ,4/5] mesh: Clean up style in net.c
  2020-05-29  6:37 ` [PATCH BlueZ 4/5] mesh: Clean up style in net.c Inga Stotland
@ 2020-05-29  7:08   ` bluez.test.bot
  0 siblings, 0 replies; 8+ messages in thread
From: bluez.test.bot @ 2020-05-29  7:08 UTC (permalink / raw)
  To: linux-bluetooth, inga.stotland

[-- Attachment #1: Type: text/plain, Size: 350 bytes --]


This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While we are preparing for reviewing the patches, we found the following
issue/warning.

Test Result:
checkgitlint Failed

Outputs:
3: B6 Body message is missing



---
Regards,
Linux Bluetooth

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

* Re: [PATCH BlueZ 2/5] mesh: Debug output clean up
  2020-05-29  6:37 ` [PATCH BlueZ 2/5] mesh: Debug output clean up Inga Stotland
@ 2020-05-29 17:22   ` Gix, Brian
  0 siblings, 0 replies; 8+ messages in thread
From: Gix, Brian @ 2020-05-29 17:22 UTC (permalink / raw)
  To: linux-bluetooth, Stotland, Inga

Hi Inga,

On Thu, 2020-05-28 at 23:37 -0700, Inga Stotland wrote:
> This changes l_info() to l_debug() for recurring cases and
> removes some excessive debug output.
> ---
>  mesh/manager.c         |   6 +-
>  mesh/mesh-io-generic.c |   3 +-
>  mesh/model.c           |  28 +-------
>  mesh/net.c             | 150 ++++++++++++++---------------------------
>  mesh/pb-adv.c          |   7 +-
>  mesh/prov-initiator.c  |   2 +-
>  6 files changed, 58 insertions(+), 138 deletions(-)
> 
> diff --git a/mesh/manager.c b/mesh/manager.c
> index a7383e4d5..2be471088 100644
> --- a/mesh/manager.c
> +++ b/mesh/manager.c
> @@ -219,7 +219,7 @@ static void add_start(void *user_data, int err)
>  {
>  	struct l_dbus_message *reply;
>  
> -	l_info("Start callback");
> +	l_debug("Start callback");
>  
>  	if (err == MESH_ERROR_NONE)
>  		reply = l_dbus_message_new_method_return(add_pending->msg);
> @@ -270,8 +270,8 @@ static struct l_dbus_message *add_node_call(struct l_dbus *dbus,
>  	add_pending->agent = node_get_agent(node);
>  
>  	if (!node_is_provisioner(node) || (add_pending->agent == NULL)) {
> -		l_info("Provisioner: %d", node_is_provisioner(node));
> -		l_info("Agent: %p", add_pending->agent);
> +		l_debug("Provisioner: %d", node_is_provisioner(node));
> +		l_debug("Agent: %p", add_pending->agent);
>  		reply = dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED,
>  							"Missing Interfaces");
>  		goto fail;
> diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c
> index 3ad130567..7a4008bd9 100644
> --- a/mesh/mesh-io-generic.c
> +++ b/mesh/mesh-io-generic.c
> @@ -173,7 +173,7 @@ static void event_callback(const void *buf, uint8_t size, void *user_data)
>  		break;
>  
>  	default:
> -		l_info("Other Meta Evt - %d", event);
> +		l_debug("Other Meta Evt - %d", event);
>  	}
>  }
>  
> @@ -804,7 +804,6 @@ static bool recv_register(struct mesh_io *io, const uint8_t *filter,
>  	if (!cb || !filter || !len)
>  		return false;
>  
> -	l_info("%s %2.2x", __func__, filter[0]);
>  	rx_reg = l_queue_remove_if(pvt->rx_regs, find_by_filter, filter);
>  
>  	l_free(rx_reg);
> diff --git a/mesh/model.c b/mesh/model.c
> index 945583324..dc6f28eb8 100644
> --- a/mesh/model.c
> +++ b/mesh/model.c
> @@ -514,15 +514,8 @@ static void cmplt(uint16_t remote, uint8_t status,
>  {
>  	struct timeval tx_end;
>  
> -	if (status)
> -		l_debug("Tx-->%4.4x (%d octets) Failed (%d)",
> -				remote, size, status);
> -	else
> -		l_debug("Tx-->%4.4x (%d octets) Succeeded", remote, size);
> -
> -	/* print_packet("Sent Data", data, size); */
> -
>  	gettimeofday(&tx_end, NULL);
> +
>  	if (tx_end.tv_sec == tx_start.tv_sec) {
>  		l_debug("Duration 0.%6.6lu seconds",
>  				tx_end.tv_usec - tx_start.tv_usec);
> @@ -580,22 +573,18 @@ static bool msg_send(struct mesh_node *node, bool credential, uint16_t src,
>  		net_idx = appkey_net_idx(node_get_net(node), app_idx);
>  	}
>  
> -	l_debug("(%x) %p", app_idx, key);
> -	l_debug("net_idx %x", net_idx);
> -
>  	out = l_malloc(out_len);
>  
>  	iv_index = mesh_net_get_iv_index(net);
>  
>  	seq_num = mesh_net_next_seq_num(net);
> +
>  	if (!mesh_crypto_payload_encrypt(label, msg, out, msg_len, src, dst,
>  				key_aid, seq_num, iv_index, szmic, key)) {
>  		l_error("Failed to Encrypt Payload");
>  		goto done;
>  	}
>  
> -	/* print_packet("Encrypted with", key, 16); */
> -
>  	ret = mesh_net_app_send(net, credential, src, dst, key_aid, net_idx,
>  					ttl, seq_num, iv_index, segmented,
>  					szmic, out, out_len, cmplt, NULL);
> @@ -647,8 +636,6 @@ static void model_bind_idx(struct mesh_node *node, struct mesh_model *mod,
>  
>  	l_queue_push_tail(mod->bindings, L_UINT_TO_PTR(idx));
>  
> -	l_debug("Add %4.4x to model %8.8x", idx, mod->id);
> -

I would like to preserve debug output (or perhaps "rework" is a better word) most state changing Config Server
commands such as this, and including:

Model Bind
Add/Update App/Net Keys
Set TTL/Beaconing/(othwer features)
Add Pubs/Subs
etc

These should be infrequent enough that they shouldn't be noisy, but they allow developers to make sure internal
daemon functionality states are being set up correctly.

In the case of this one, I might change it to 
	l_debug("Bind key %3.3x to model %8.8x on element %4.4x")


>  	if (!mod->cbs)
>  		/* External model */
>  		config_update_model_bindings(node, mod);
> @@ -781,7 +768,6 @@ static int add_virt_sub(struct mesh_net *net, struct mesh_model *mod,
>  
>  		l_queue_push_head(mod->virtuals, virt);
>  		mesh_net_dst_reg(net, virt->addr);
> -		l_debug("Added virtual sub addr %4.4x", virt->addr);
>  	}
>  
>  	if (dst)
> @@ -809,7 +795,6 @@ static int add_sub(struct mesh_net *net, struct mesh_model *mod,
>  
>  		l_queue_push_tail(mod->subs, L_UINT_TO_PTR(grp));
>  		mesh_net_dst_reg(net, grp);
> -		l_debug("Added group subscription %4.4x", grp);
>  	}
>  
>  	return MESH_STATUS_SUCCESS;
> @@ -929,6 +914,7 @@ bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,
>  
>  	/* Don't process if already in RPL */
>  	crpl = node_get_crpl(node);
> +
>  	if (net_msg_check_replay_cache(net, src, crpl, seq, iv_index))
>  		return false;
>  
> @@ -1064,8 +1050,6 @@ int mesh_model_publish(struct mesh_node *node, uint32_t mod_id,
>  	bool result;
>  	int status;
>  
> -	/* print_packet("Mod Tx", msg, msg_len); */
> -
>  	if (!net || msg_len > 380)
>  		return MESH_ERROR_INVALID_ARGS;
>  
> @@ -1092,8 +1076,6 @@ int mesh_model_publish(struct mesh_node *node, uint32_t mod_id,
>  	if (mod->pub->virt)
>  		label = mod->pub->virt->label;
>  
> -	l_debug("publish dst=%x", mod->pub->addr);
> -
>  	net_idx = appkey_net_idx(net, mod->pub->idx);
>  
>  	result = msg_send(node, mod->pub->credential != 0, src,
> @@ -1108,8 +1090,6 @@ bool mesh_model_send(struct mesh_node *node, uint16_t src, uint16_t dst,
>  					uint8_t ttl, bool segmented,
>  					const void *msg, uint16_t msg_len)
>  {
> -	/* print_packet("Mod Tx", msg, msg_len); */
> -
>  	/* If SRC is 0, use the Primary Element */
>  	if (src == 0)
>  		src = node_get_primary(node);
> @@ -1279,14 +1259,12 @@ void mesh_model_app_key_delete(struct mesh_node *node, struct l_queue *models,
>  int mesh_model_binding_del(struct mesh_node *node, uint16_t addr, uint32_t id,
>  						uint16_t app_idx)
>  {
> -	l_debug("0x%x, 0x%x, %d", addr, id, app_idx);
>  	return update_binding(node, addr, id, app_idx, true);
>  }
>  
>  int mesh_model_binding_add(struct mesh_node *node, uint16_t addr, uint32_t id,
>  						uint16_t app_idx)
>  {
> -	l_debug("0x%x, 0x%x, %d", addr, id, app_idx);
>  	return update_binding(node, addr, id, app_idx, false);
>  }
>  
> diff --git a/mesh/net.c b/mesh/net.c
> index f104be0f9..f9e7bce4c 100644
> --- a/mesh/net.c
> +++ b/mesh/net.c
> @@ -307,7 +307,7 @@ static void trigger_heartbeat(struct mesh_net *net, uint16_t feature,
>  {
>  	struct mesh_net_heartbeat *hb = &net->heartbeat;
>  
> -	l_info("%s: %4.4x --> %d", __func__, feature, in_use);
> +	l_debug("%s: %4.4x --> %d", __func__, feature, in_use);
>  	if (in_use) {
>  		if (net->heartbeat.features & feature)
>  			return; /* no change */
> @@ -371,7 +371,7 @@ static void frnd_kr_phase2(void *a, void *b)
>  	 * receives it's first Poll using the new keys (?)
>  	 */
>  
> -	l_info("Use Both KeySet %d && %d for %4.4x",
> +	l_debug("Use Both KeySet %d && %d for %4.4x",
>  			frnd->net_key_cur, frnd->net_key_upd, frnd->lp_addr);
>  }
>  
> @@ -379,7 +379,7 @@ static void frnd_kr_phase3(void *a, void *b)
>  {
>  	struct mesh_friend *frnd = a;
>  
> -	l_info("Replace KeySet %d with %d for %4.4x",
> +	l_debug("Replace KeySet %d with %d for %4.4x",
>  			frnd->net_key_cur, frnd->net_key_upd, frnd->lp_addr);
>  	net_key_unref(frnd->net_key_cur);
>  	frnd->net_key_cur = frnd->net_key_upd;
> @@ -627,10 +627,6 @@ static void queue_friend_update(struct mesh_net *net)
>  		update.u.one[0].data[1] = flags;
>  		l_put_be32(net->iv_index, update.u.one[0].data + 2);
>  		update.u.one[0].data[6] = 0x01; /* More Data */
> -		/* print_packet("Frnd-Beacon-SRC",
> -		 *			beacon_data, sizeof(beacon_data));
> -		 */
> -		/* print_packet("Frnd-Update", update.u.one[0].data, 6); */
>  
>  		l_queue_foreach(net->friends, enqueue_update, &update);
>  	}
> @@ -1570,7 +1566,7 @@ static void send_frnd_ack(struct mesh_net *net, uint16_t src, uint16_t dst,
>  	l_put_be32(hdr, msg);
>  	l_put_be32(flags, msg + 3);
>  
> -	l_info("Send Friend ACK to Segs: %8.8x", flags);
> +	l_debug("Send Friend ACK to Segs: %8.8x", flags);
>  
>  	if (is_lpn_friend(net, dst)) {
>  		/* If we are acking our LPN Friend, queue, don't send */
> @@ -1603,7 +1599,7 @@ static void send_net_ack(struct mesh_net *net, struct mesh_sar *sar,
>  
>  	l_put_be32(hdr, msg);
>  	l_put_be32(flags, msg + 3);
> -	l_info("Send%s ACK to Segs: %8.8x", sar->frnd ? " Friend" : "", flags);
> +	l_debug("Send%s ACK to Segs: %8.8x", sar->frnd ? " Friend" : "", flags);
>  
>  	if (is_lpn_friend(net, dst)) {
>  		/* If we are acking our LPN Friend, queue, don't send */
> @@ -1629,7 +1625,7 @@ static void inseg_to(struct l_timeout *seg_timeout, void *user_data)
>  		return;
>  
>  	/* Send NAK */
> -	l_info("Timeout %p %3.3x", sar, sar->app_idx);
> +	l_debug("Timeout %p %3.3x", sar, sar->app_idx);
>  	send_net_ack(net, sar, sar->flags);
>  
>  	sar->seg_timeout = l_timeout_create(SEG_TO, inseg_to, net, NULL);
> @@ -1647,7 +1643,6 @@ static void inmsg_to(struct l_timeout *msg_timeout, void *user_data)
>  
>  	sar->msg_timeout = NULL;
>  
> -	/* print_packet("Incoming SAR Timeout", sar->buf, sar->len); */
>  	mesh_sar_free(sar);
>  }
>  
> @@ -1668,7 +1663,6 @@ static void outmsg_to(struct l_timeout *msg_timeout, void *user_data)
>  				sar->buf, sar->len - 4,
>  				sar->user_data);
>  
> -	/* print_packet("Outgoing SAR Timeout", sar->buf, sar->len); */
>  	mesh_sar_free(sar);
>  }
>  
> @@ -1698,13 +1692,13 @@ static void ack_received(struct mesh_net *net, bool timeout,
>  	uint32_t ack_copy = ack_flag;
>  	uint16_t i;
>  
> -	l_info("ACK Rxed (%x) (to:%d): %8.8x", seq0, timeout, ack_flag);
> +	l_debug("ACK Rxed (%x) (to:%d): %8.8x", seq0, timeout, ack_flag);
>  
>  	outgoing = l_queue_find(net->sar_out, match_sar_seq0,
>  							L_UINT_TO_PTR(seq0));
>  
>  	if (!outgoing) {
> -		l_info("Not Found: %4.4x", seq0);
> +		l_debug("Not Found: %4.4x", seq0);
>  		return;
>  	}
>  
> @@ -1743,7 +1737,7 @@ static void ack_received(struct mesh_net *net, bool timeout,
>  
>  		ack_copy |= seg_flag;
>  
> -		l_info("Resend Seg %d net:%p dst:%x app_idx:%3.3x",
> +		l_debug("Resend Seg %d net:%p dst:%x app_idx:%3.3x",
>  				i, net, outgoing->remote, outgoing->app_idx);
>  
>  		send_seg(net, outgoing, i);
> @@ -1918,12 +1912,12 @@ static void friend_seg_rxed(struct mesh_net *net,
>  	if (segN == segO)
>  		frnd_msg->last_len = size;
>  
> -	l_info("RXed Seg %d, Flags %8.8x (cnt: %d)",
> +	l_debug("RXed Seg %d, Flags %8.8x (cnt: %d)",
>  						segO, frnd_msg->flags, cnt);
>  
>  	/* In reality, if one of these is true, then *both* must be true */
>  	if ((cnt == segN) || (frnd_msg->flags == expected)) {
> -		l_info("Full ACK");
> +		l_debug("Full ACK");
>  		send_frnd_ack(net, dst, src, hdr, frnd_msg->flags);
>  
>  		if (frnd_msg->ttl > 1) {
> @@ -1943,7 +1937,7 @@ static void friend_seg_rxed(struct mesh_net *net,
>  
>  	/* Always ACK if this is the largest outstanding segment */
>  	if ((largest & frnd_msg->flags) == largest) {
> -		l_info("Partial ACK");
> +		l_debug("Partial ACK");
>  		send_frnd_ack(net, dst, src, hdr, frnd_msg->flags);
>  	}
>  
> @@ -1997,7 +1991,7 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
>  	expected = 0xffffffff >> (31 - segN);
>  
>  	if (sar_in) {
> -		l_info("RXed (old: %04x %06x size:%d) %d of %d",
> +		l_debug("RXed (old: %04x %06x size:%d) %d of %d",
>  					seqZero, seq, size, segO, segN);
>  		/* Sanity Check--> certain things must match */
>  		if (SEG_MAX(true, sar_in->len) != segN ||
> @@ -2012,7 +2006,7 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
>  	} else {
>  		uint16_t len = MAX_SEG_TO_LEN(segN);
>  
> -		l_info("RXed (new: %04x %06x size: %d len: %d) %d of %d",
> +		l_debug("RXed (new: %04x %06x size: %d len: %d) %d of %d",
>  				seqZero, seq, size, len, segO, segN);
>  		l_debug("Queue Size: %d", l_queue_length(net->sar_in));
>  		sar_in = mesh_sar_new(len);
> @@ -2031,7 +2025,6 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
>  		l_debug("First Seg %4.4x", sar_in->flags);
>  		l_queue_push_head(net->sar_in, sar_in);
>  	}
> -	/* print_packet("Seg", data, size); */
>  
>  	seg_off = segO * MAX_SEG_LEN;
>  	memcpy(sar_in->buf + seg_off, data, size);
> @@ -2044,8 +2037,6 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
>  	sar_in->flags |= this_seg_flag;
>  	sar_in->ttl = ttl;
>  
> -	l_debug("Have Frags %4.4x", sar_in->flags);
> -
>  	/* Msg length only definitive on last segment */
>  	if (segO == segN)
>  		sar_in->len = segN * MAX_SEG_LEN + size;
> @@ -2166,7 +2157,7 @@ static bool ctl_received(struct mesh_net *net, uint16_t key_id,
>  				l_queue_find(net->friends,
>  					match_by_friend,
>  					L_UINT_TO_PTR(l_get_be16(pkt))));
> -		l_info("Remaining Friends: %d", l_queue_length(net->friends));
> +		l_debug("Remaining Friends: %d", l_queue_length(net->friends));
>  		break;
>  
>  	case NET_OP_PROXY_SUB_ADD:
> @@ -2212,7 +2203,7 @@ static bool ctl_received(struct mesh_net *net, uint16_t key_id,
>  			if (net->heartbeat.sub_max_hops < hops)
>  				net->heartbeat.sub_max_hops = hops;
>  
> -			l_info("HB: cnt:%4.4x min:%2.2x max:%2.2x",
> +			l_debug("HB: cnt:%4.4x min:%2.2x max:%2.2x",
>  					net->heartbeat.sub_count,
>  					net->heartbeat.sub_min_hops,
>  					net->heartbeat.sub_max_hops);
> @@ -2381,8 +2372,6 @@ static enum _relay_advice packet_received(void *user_data,
>  	if (is_us(net, net_src, true))
>  		return RELAY_NONE;
>  
> -	l_debug("check %08x", cache_cookie);
> -
>  	/* As a Relay, suppress repeats of last N packets that pass through */
>  	/* The "cache_cookie" should be unique part of App message */
>  	if (msg_in_cache(net, net_src, net_seq, cache_cookie))
> @@ -2394,7 +2383,7 @@ static enum _relay_advice packet_received(void *user_data,
>  	if (is_us(net, net_dst, false) ||
>  			(net_ctl && net_opcode == NET_OP_HEARTBEAT)) {
>  
> -		l_info("RX: App 0x%04x -> 0x%04x : TTL 0x%02x : SEQ 0x%06x",
> +		l_debug("RX: App 0x%04x -> 0x%04x : TTL 0x%02x : SEQ 0x%06x",
>  					net_src, net_dst, net_ttl, net_seq);
>  
>  		if (net_ctl) {
> @@ -2404,7 +2393,6 @@ static enum _relay_advice packet_received(void *user_data,
>  				if (net_dst & 0x8000)
>  					return RELAY_NONE;
>  
> -				/* print_packet("Got ACK", msg, app_msg_len); */
>  				/* Pedantic check for correct size */
>  				if (app_msg_len != 7)
>  					return RELAY_NONE;
> @@ -2576,7 +2564,7 @@ static void iv_upd_to(struct l_timeout *upd_timeout, void *user_data)
>  	case IV_UPD_UPDATING:
>  		if (l_queue_length(net->sar_out) ||
>  					l_queue_length(net->sar_queue)) {
> -			l_info("don't leave IV Update until sar_out empty");
> +			l_debug("don't leave IV Update until sar_out empty");
>  			l_timeout_modify(net->iv_update_timeout, 10);
>  			break;
>  		}
> @@ -2626,7 +2614,7 @@ static int key_refresh_phase_two(struct mesh_net *net, uint16_t idx)
>  	if (!subnet || !subnet->net_key_upd)
>  		return MESH_STATUS_INVALID_NETKEY;
>  
> -	l_info("Key refresh procedure phase 2: start using new net TX keys");
> +	l_debug("Key refresh procedure phase 2: start using new net TX keys");
>  	subnet->key_refresh = 1;
>  	subnet->net_key_tx = subnet->net_key_upd;
>  	/* TODO: Provisioner may need to stay in phase three until
> @@ -2659,7 +2647,7 @@ static int key_refresh_finish(struct mesh_net *net, uint16_t idx)
>  	if (subnet->kr_phase == KEY_REFRESH_PHASE_NONE)
>  		return MESH_STATUS_SUCCESS;
>  
> -	l_info("Key refresh phase 3: use new keys only, discard old ones");
> +	l_debug("Key refresh phase 3: use new keys only, discard old ones");
>  
>  	/* Switch to using new keys, discard old ones */
>  	net_key_unref(subnet->net_key_cur);
> @@ -2715,12 +2703,12 @@ static void update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index,
>  			 * Starting permissive state will allow us maximum
>  			 * (96 hours) to resync
>  			 */
> -			l_info("iv_upd_state = IV_UPD_UPDATING");
> +			l_debug("iv_upd_state = IV_UPD_UPDATING");
>  			net->iv_upd_state = IV_UPD_UPDATING;
>  			net->iv_update_timeout = l_timeout_create(
>  				IV_IDX_UPD_MIN, iv_upd_to, net, NULL);
>  		} else {
> -			l_info("iv_upd_state = IV_UPD_NORMAL");
> +			l_debug("iv_upd_state = IV_UPD_NORMAL");
>  			net->iv_upd_state = IV_UPD_NORMAL;
>  		}
>  	} else if (ivu) {
> @@ -2736,7 +2724,7 @@ static void update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index,
>  			return;
>  
>  		if (!net->iv_update) {
> -			l_info("iv_upd_state = IV_UPD_UPDATING");
> +			l_debug("iv_upd_state = IV_UPD_UPDATING");
>  			net->iv_upd_state = IV_UPD_UPDATING;
>  			net->iv_update_timeout = l_timeout_create(
>  					IV_IDX_UPD_MIN, iv_upd_to, net, NULL);
> @@ -2937,7 +2925,6 @@ bool mesh_net_attach(struct mesh_net *net, struct mesh_io *io)
>  		if (!fast_cache)
>  			fast_cache = l_queue_new();
>  
> -		l_info("Register io cb");
>  		mesh_io_register_recv_cb(io, snb, sizeof(snb),
>  							beacon_recv, NULL);
>  		mesh_io_register_recv_cb(io, pkt, sizeof(pkt),
> @@ -2981,7 +2968,7 @@ bool mesh_net_iv_index_update(struct mesh_net *net)
>  	if (net->iv_upd_state != IV_UPD_NORMAL)
>  		return false;
>  
> -	l_info("iv_upd_state = IV_UPD_UPDATING");
> +	l_debug("iv_upd_state = IV_UPD_UPDATING");
>  	mesh_net_flush_msg_queues(net);
>  	if (!mesh_config_write_iv_index(node_config_get(net->node),
>  						net->iv_index + 1, true))
> @@ -3082,23 +3069,18 @@ static bool send_seg(struct mesh_net *net, struct mesh_sar *msg, uint8_t segO)
>  		mesh_net_iv_index_update(net);
>  
>  	l_debug("segN %d segment %d seg_off %d", segN, segO, seg_off);
> -	/* print_packet("Sending", msg->buf + seg_off, seg_len); */
> -	{
> -		/* TODO: Are we RXing on an LPN's behalf? Then set RLY bit */
> -
> -		if (!mesh_crypto_packet_build(false, msg->ttl,
> -					seq_num,
> -					msg->src, msg->remote,
> -					0,
> -					msg->segmented, msg->key_aid,
> -					msg->szmic, false, msg->seqZero,
> -					segO, segN,
> +
> +	/* TODO: Are we RXing on an LPN's behalf? Then set RLY bit */
> +	if (!mesh_crypto_packet_build(false, msg->ttl, seq_num, msg->src,
> +					msg->remote, 0, msg->segmented,
> +					msg->key_aid, msg->szmic, false,
> +					msg->seqZero, segO, segN,
>  					msg->buf + seg_off, seg_len,
>  					packet + 1, &packet_len)) {
> -			l_error("Failed to build packet");
> -			return false;
> -		}
> +		l_error("Failed to build packet");
> +		return false;
>  	}
> +
>  	print_packet("Clr-Net Tx", packet + 1, packet_len);
>  
>  	subnet = l_queue_find(net->subnets, match_key_index,
> @@ -3112,20 +3094,7 @@ static bool send_seg(struct mesh_net *net, struct mesh_sar *msg, uint8_t segO)
>  		return false;
>  	}
>  
> -	/* print_packet("Step 4", packet + 1, packet_len); */
> -
> -	{
> -		char *str;
> -
> -		send_msg_pkt(net, packet, packet_len + 1);
> -
> -		str = l_util_hexstring(packet + 1, packet_len);
> -		l_info("TX: Network %04x -> %04x : %s (%u) : TTL %d : SEQ %06x",
> -				msg->src, msg->remote, str,
> -				packet_len, msg->ttl,
> -				msg->frnd ? msg->seqAuth + segO : seq_num);
> -		l_free(str);
> -	}
> +	send_msg_pkt(net, packet, packet_len + 1);
>  
>  	msg->last_seg = segO;
>  
> @@ -3140,7 +3109,6 @@ void mesh_net_send_seg(struct mesh_net *net, uint32_t net_key_id,
>  				uint32_t hdr,
>  				const void *seg, uint16_t seg_len)
>  {
> -	char *str;
>  	uint8_t packet[30];
>  	uint8_t packet_len;
>  	bool segmented = !!((hdr >> SEG_HDR_SHIFT) & true);
> @@ -3174,14 +3142,12 @@ void mesh_net_send_seg(struct mesh_net *net, uint32_t net_key_id,
>  		return;
>  	}
>  
> -	/* print_packet("Step 4", packet + 1, packet_len); */
> -
>  	send_msg_pkt(net, packet, packet_len + 1);
>  
> -	str = l_util_hexstring(packet + 1, packet_len);
> -	l_info("TX: Friend Seg-%d %04x -> %04x : %s (%u) : TTL %d : SEQ %06x",
> -			segO, src, dst, str, packet_len, ttl, seq);
> -	l_free(str);
> +	l_debug("TX: Friend Seg-%d %04x -> %04x : len %u) : TTL %d : SEQ %06x",
> +					segO, src, dst, packet_len, ttl, seq);
> +
> +	print_packet("TX: Friend", packet + 1, packet_len);
>  }
>  
>  bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
> @@ -3222,7 +3188,8 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
>  				szmic, seq & SEQ_ZERO_MASK,
>  				msg, msg_len);
>  
> -	/* If addressed to a unicast address and successfully enqueued,
> +	/*
> +	 * If addressed to a unicast address and successfully enqueued,
>  	 * or delivered to one of our Unicast addresses we are done
>  	 */
>  	if ((result && IS_UNICAST(dst)) || src == dst ||
> @@ -3243,6 +3210,7 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
>  	payload->iv_index = mesh_net_get_iv_index(net);
>  	payload->seqAuth = seq;
>  	payload->segmented = segmented;
> +
>  	if (segmented) {
>  		payload->flags = 0xffffffff >> (31 - seg_max);
>  		payload->seqZero = seq & SEQ_ZERO_MASK;
> @@ -3256,13 +3224,14 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
>  			/* Delay sending Outbound SAR unless prior
>  			 * SAR to same DST has completed */
>  
> -			l_info("OB-Queued SeqZero: %4.4x", payload->seqZero);
> +			l_debug("OB-Queued SeqZero: %4.4x", payload->seqZero);
>  			l_queue_push_tail(net->sar_queue, payload);
>  			return true;
>  		}
>  	}
>  
>  	result = true;
> +
>  	if (!IS_UNICAST(dst) && segmented) {
>  		int i;
>  
> @@ -3303,7 +3272,6 @@ void mesh_net_ack_send(struct mesh_net *net, uint32_t key_id,
>  	uint8_t data[7];
>  	uint8_t pkt_len;
>  	uint8_t pkt[30];
> -	char *str;
>  
>  	hdr = NET_OP_SEG_ACKNOWLEDGE << OPCODE_HDR_SHIFT;
>  	hdr |= rly << RELAY_HDR_SHIFT;
> @@ -3334,14 +3302,11 @@ void mesh_net_ack_send(struct mesh_net *net, uint32_t key_id,
>  		return;
>  	}
>  
> -	/* print_packet("Step 4", pkt, pkt_len); */
>  	send_msg_pkt(net, pkt, pkt_len + 1);
>  
> -	str = l_util_hexstring(pkt + 1, pkt_len);
> -	l_info("TX: Friend ACK %04x -> %04x : %s (%u) : TTL %d : SEQ %06x",
> -			src, dst, str, pkt_len,
> -			ttl, seq);
> -	l_free(str);
> +	l_debug("TX: Friend ACK %04x -> %04x : len %u : TTL %d : SEQ %06x",
> +					src, dst, pkt_len, ttl, seq);
> +	print_packet("TX: Friend ACK", pkt + 1, pkt_len);
>  }
>  
>  void mesh_net_transport_send(struct mesh_net *net, uint32_t key_id,
> @@ -3419,26 +3384,13 @@ void mesh_net_transport_send(struct mesh_net *net, uint32_t key_id,
>  				pkt + 1, &pkt_len))
>  		return;
>  
> -	/* print_packet("Step 2", pkt + 1, pkt_len); */
> -
>  	if (!net_key_encrypt(key_id, iv_index, pkt + 1, pkt_len)) {
>  		l_error("Failed to encode packet");
>  		return;
>  	}
>  
> -	/* print_packet("Step 4", pkt + 1, pkt_len); */
> -
> -	if (dst != 0) {
> -		char *str;
> -
> +	if (dst != 0)
>  		send_msg_pkt(net, pkt, pkt_len + 1);
> -
> -		str = l_util_hexstring(pkt + 1, pkt_len);
> -		l_info("TX: Network %04x -> %04x : %s (%u) : TTL %d : SEQ %06x",
> -				src, dst, str, pkt_len,
> -				ttl, use_seq);
> -		l_free(str);
> -	}
>  }
>  
>  uint8_t mesh_net_key_refresh_phase_set(struct mesh_net *net, uint16_t idx,
> @@ -3524,7 +3476,7 @@ int mesh_net_update_key(struct mesh_net *net, uint16_t idx,
>  
>  	if (subnet->net_key_upd) {
>  		net_key_unref(subnet->net_key_upd);
> -		l_info("Warning: overwriting new keys");
> +		l_debug("Warning: overwriting new keys");
>  	}
>  
>  	/* Preserve starting data */
> @@ -3539,7 +3491,7 @@ int mesh_net_update_key(struct mesh_net *net, uint16_t idx,
>  	l_queue_foreach(net->friends, frnd_kr_phase1,
>  					L_UINT_TO_PTR(subnet->net_key_upd));
>  
> -	l_info("key refresh phase 1: Key ID %d", subnet->net_key_upd);
> +	l_debug("key refresh phase 1: Key ID %d", subnet->net_key_upd);
>  
>  	if (!mesh_config_net_key_update(node_config_get(net->node), idx, value))
>  		return MESH_STATUS_STORAGE_FAIL;
> @@ -3812,9 +3764,6 @@ bool net_msg_check_replay_cache(struct mesh_net *net, uint16_t src,
>  		rpl_get_list(net->node, net->replay_cache);
>  	}
>  
> -	l_debug("Test Replay src: %4.4x seq: %6.6x iv: %8.8x",
> -						src, seq, iv_index);
> -
>  	rpe = l_queue_find(net->replay_cache, match_replay_cache,
>  						L_UINT_TO_PTR(src));
>  
> @@ -3854,7 +3803,6 @@ void net_msg_add_replay_cache(struct mesh_net *net, uint16_t src, uint32_t seq,
>  						L_UINT_TO_PTR(src));
>  
>  	if (!rpe) {
> -		l_debug("New Entry for %4.4x", src);
>  		rpe = l_new(struct mesh_rpl, 1);
>  		rpe->src = src;
>  	}
> diff --git a/mesh/pb-adv.c b/mesh/pb-adv.c
> index c1316ed1b..ae5b81391 100644
> --- a/mesh/pb-adv.c
> +++ b/mesh/pb-adv.c
> @@ -157,8 +157,6 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
>  		init_size = size;
>  	}
>  
> -	/* print_packet("FULL-TX", data, size); */
> -
>  	l_debug("Sending %u fragments for %u octets", max_seg + 1, size);
>  
>  	buf[6] = max_seg << 2;
> @@ -168,7 +166,6 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
>  
>  	l_debug("max_seg: %2.2x", max_seg);
>  	l_debug("size: %2.2x, CRC: %2.2x", size, buf[9]);
> -	/* print_packet("PB-TX", buf + 1, init_size + 9); */
>  
>  	pb_adv_send(session, MESH_IO_TX_COUNT_UNLIMITED, 200,
>  							buf, init_size + 10);
> @@ -186,8 +183,6 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
>  		buf[6] = (i << 2) | 0x02;
>  		memcpy(buf + 7, data + consumed, seg_size);
>  
> -		/* print_packet("PB-TX", buf + 1, seg_size + 6); */
> -
>  		pb_adv_send(session, MESH_IO_TX_COUNT_UNLIMITED, 200,
>  							buf, seg_size + 7);
>  
> @@ -225,7 +220,7 @@ static void tx_timeout(struct l_timeout *timeout, void *user_data)
>  
>  	mesh_send_cancel(filter, sizeof(filter));
>  
> -	l_info("TX timeout");
> +	l_debug("TX timeout");
>  	cb = session->close_cb;
>  	user_data = session->user_data;
>  	cb(user_data, 1);
> diff --git a/mesh/prov-initiator.c b/mesh/prov-initiator.c
> index 4ef31e95d..4de4df62d 100644
> --- a/mesh/prov-initiator.c
> +++ b/mesh/prov-initiator.c
> @@ -770,7 +770,7 @@ static void int_prov_rx(void *user_data, const uint8_t *data, uint16_t len)
>  		break;
>  
>  	case PROV_COMPLETE: /* Complete */
> -		l_info("Provisioning Complete");
> +		l_debug("Provisioning Complete");
>  		prov->state = INT_PROV_IDLE;
>  		int_prov_close(prov, PROV_ERR_SUCCESS);
>  		break;

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

end of thread, other threads:[~2020-05-29 17:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29  6:37 [PATCH BlueZ 0/5] Mesh clean up Inga Stotland
2020-05-29  6:37 ` [PATCH BlueZ 1/5] mesh: Make helper packet print depends on debug setting Inga Stotland
2020-05-29  6:37 ` [PATCH BlueZ 2/5] mesh: Debug output clean up Inga Stotland
2020-05-29 17:22   ` Gix, Brian
2020-05-29  6:37 ` [PATCH BlueZ 3/5] mesh: Remove debug-only related callback for packet send Inga Stotland
2020-05-29  6:37 ` [PATCH BlueZ 4/5] mesh: Clean up style in net.c Inga Stotland
2020-05-29  7:08   ` [BlueZ,4/5] " bluez.test.bot
2020-05-29  6:37 ` [PATCH BlueZ 5/5] mesh: Remove unused functions from net.c Inga Stotland

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