You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by na...@apache.org on 2021/05/27 08:19:38 UTC

[mynewt-nimble] branch master updated (aeb1adb -> a4d3fb4)

This is an automated email from the ASF dual-hosted git repository.

naraj pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git.


    from aeb1adb  bttester: handle special PSMs in l2cap
     new 77a1779  mesh: Fix typo when deleting app key in CDB
     new 8becf2a  mesh: Fix heartbeat subscription tests
     new 15d9fd6  mesh: Add net transmit status rx in config client
     new 299b2eb  mesh: Check response address in Configuration Client
     new 68c409a  mesh: Verify network buffer max len
     new 8256009  mesh: Initialize msg_ctx when re-encrypting friend msg
     new 8255bee  mesh: Update seqnum when re-encrypting for friend
     new ab0f5d8  mesh: Reduce proxy rx buffer to an exact fit
     new 9f396bc  mesh: Fix provisioner provisioning
     new 83cf6da  mesh: Add CDB handle key refresh phase
     new c5f9d9a  mesh: Get rid of magic number in cmd_get_comp
     new fa8ca30  mesh: Check subnet existence in heartbeat_send
     new 5e24948  mesh: Check model publish pointer before dereferencing
     new 26666ce  mesh: Resolve dead code in store_seg
     new b2f8d90  mesh: Explicitly ignore gatt_service_register return code
     new 5f60008  mesh: Remove unsigned typing to returns in heartbeat
     new 1198bb8  mesh: Resolve keys before logging subnet
     new 1696d0f  mesh: Make internal virtual addr pointers const
     new 6253904  mesh: Fix restoring fast period divisor from settings
     new 16efc16  mesh: Send Link Close message when closing link
     new 01879ef  bttester: Set Company ID to Intel Corp.
     new bc1fe4e  mesh: Set BT_MESH_ADV_USER_DATA_SIZE to size of 4 byte pointer
     new 7a5f6ec  mesh: Fix condition is net_tx_cred_get
     new fa8d955  mesh: Delete duplication in config
     new 195313a  mesh: Fix incorrect pointer type in cdb.c
     new 0fba723  bttester: Add lpn_cb
     new 8fe3735  mesh: Sync lpn.c with Zephyr
     new 56838dd  mesh: Set BLE_MESH_LPN_SUB_ALL_NODES_ADDR to off by default
     new a62a2e3  mesh: Fix typos in flags/frags
     new 5ea192a  bttester: Allow for more retransmit attempts in mesh
     new a4d3fb4  mesh: Fix macro in net.c

The 31 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 apps/bttester/src/bttester.h            |  21 ++++++
 apps/bttester/src/mesh.c                |  39 ++++++++++-
 apps/bttester/syscfg.yml                |   5 +-
 nimble/host/mesh/include/mesh/cdb.h     |   1 -
 nimble/host/mesh/include/mesh/cfg.h     |   6 ++
 nimble/host/mesh/include/mesh/cfg_cli.h |   3 +-
 nimble/host/mesh/include/mesh/mesh.h    |   1 +
 nimble/host/mesh/src/access.c           |  13 ++--
 nimble/host/mesh/src/adv.h              |   5 +-
 nimble/host/mesh/src/cdb.c              |   4 +-
 nimble/host/mesh/src/cfg_cli.c          | 111 ++++++++++++++++++++------------
 nimble/host/mesh/src/cfg_srv.c          |  10 ++-
 nimble/host/mesh/src/friend.c           |  17 ++++-
 nimble/host/mesh/src/heartbeat.c        |  13 +++-
 nimble/host/mesh/src/heartbeat.h        |   1 +
 nimble/host/mesh/src/lpn.c              |  76 ++++++++++------------
 nimble/host/mesh/src/mesh.c             |   2 +-
 nimble/host/mesh/src/net.c              |  17 ++---
 nimble/host/mesh/src/net.h              |  13 ++++
 nimble/host/mesh/src/pb_adv.c           |   3 +-
 nimble/host/mesh/src/pb_gatt.c          |   2 +-
 nimble/host/mesh/src/prov.c             |   4 +-
 nimble/host/mesh/src/provisioner.c      |  20 +++---
 nimble/host/mesh/src/proxy.c            |   4 +-
 nimble/host/mesh/src/settings.c         |   7 +-
 nimble/host/mesh/src/shell.c            |  12 ++--
 nimble/host/mesh/src/testing.c          |   4 --
 nimble/host/mesh/src/transport.c        |  12 ++--
 nimble/host/mesh/src/transport.h        |   4 +-
 nimble/host/mesh/syscfg.yml             |  12 +---
 30 files changed, 280 insertions(+), 162 deletions(-)

[mynewt-nimble] 28/31: mesh: Set BLE_MESH_LPN_SUB_ALL_NODES_ADDR to off by default

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 56838dd93564a9b03b137ad6d3f1651ad029bccc
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Wed May 5 14:20:16 2021 +0200

    mesh: Set BLE_MESH_LPN_SUB_ALL_NODES_ADDR to off by default
---
 nimble/host/mesh/syscfg.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/syscfg.yml b/nimble/host/mesh/syscfg.yml
index ada5b64..d110a38 100644
--- a/nimble/host/mesh/syscfg.yml
+++ b/nimble/host/mesh/syscfg.yml
@@ -453,7 +453,7 @@ syscfg.defs:
         description: >
             Automatically subscribe all nodes address when friendship
             established.
-        value: 1
+        value: 0
 
     BLE_MESH_FRIEND:
         description: >

[mynewt-nimble] 25/31: mesh: Fix incorrect pointer type in cdb.c

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 195313a8d9082f2a34a09002cc823005a9d0a9fc
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Fri Apr 30 13:24:36 2021 +0200

    mesh: Fix incorrect pointer type in cdb.c
---
 nimble/host/mesh/src/provisioner.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/provisioner.c b/nimble/host/mesh/src/provisioner.c
index 265dbf2..c51a769 100644
--- a/nimble/host/mesh/src/provisioner.c
+++ b/nimble/host/mesh/src/provisioner.c
@@ -503,7 +503,7 @@ static void send_prov_data(void)
 #endif
 	bt_mesh_prov_buf_init(pdu, PROV_DATA);
 #if MYNEWT_VAL(BLE_MESH_CDB)
-	net_buf_simple_add_mem(&pdu, sub->keys[SUBNET_KEY_TX_IDX(sub)].net_key, 16);
+	net_buf_simple_add_mem(pdu, sub->keys[SUBNET_KEY_TX_IDX(sub)].net_key, 16);
 	net_buf_simple_add_be16(pdu, prov_device.node->net_idx);
 	net_buf_simple_add_u8(pdu, bt_mesh_cdb_subnet_flags(sub));
 	net_buf_simple_add_be32(pdu, bt_mesh_cdb.iv_index);

[mynewt-nimble] 17/31: mesh: Resolve keys before logging subnet

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 1198bb8fb02c190418157a9d1f316f62565f6d7c
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 14:23:46 2021 +0200

    mesh: Resolve keys before logging subnet
    
    Moves the debug log printing the transport packet metadata to after the
    keys are resolved, so that the subnet pointer is valid.
    
    this is port of 9b4266b5914da021ba40372eeb390bd1d3d9df7f
---
 nimble/host/mesh/src/transport.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/nimble/host/mesh/src/transport.c b/nimble/host/mesh/src/transport.c
index f3a7c2d..9e70434 100644
--- a/nimble/host/mesh/src/transport.c
+++ b/nimble/host/mesh/src/transport.c
@@ -642,15 +642,15 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct os_mbuf *msg,
 		return -EINVAL;
 	}
 
-	BT_DBG("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx->sub->net_idx,
-	       tx->ctx->app_idx, tx->ctx->addr);
-	BT_DBG("len %u: %s", msg->om_len, bt_hex(msg->om_data, msg->om_len));
-
 	err = bt_mesh_keys_resolve(tx->ctx, &tx->sub, &key, &aid);
 	if (err) {
 		return err;
 	}
 
+	BT_DBG("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx->sub->net_idx,
+	       tx->ctx->app_idx, tx->ctx->addr);
+	BT_DBG("len %u: %s", msg->om_len, bt_hex(msg->om_data, msg->om_len));
+
 	tx->xmit = bt_mesh_net_transmit_get();
 	tx->aid = aid;
 

[mynewt-nimble] 29/31: mesh: Fix typos in flags/frags

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit a62a2e37cc8f05c69da825a790d8b3680667d8cb
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Thu May 6 13:46:05 2021 +0200

    mesh: Fix typos in flags/frags
---
 nimble/host/mesh/src/adv.h    | 3 +++
 nimble/host/mesh/src/friend.c | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/adv.h b/nimble/host/mesh/src/adv.h
index 6566df9..38db786 100644
--- a/nimble/host/mesh/src/adv.h
+++ b/nimble/host/mesh/src/adv.h
@@ -35,6 +35,9 @@ typedef void (*bt_mesh_adv_func_t)(struct os_mbuf *buf, uint16_t duration,
 				   int err, void *user_data);
 
 struct bt_mesh_adv {
+
+	struct net_buf *frags;
+
 	const struct bt_mesh_send_cb *cb;
 	void *cb_data;
 
diff --git a/nimble/host/mesh/src/friend.c b/nimble/host/mesh/src/friend.c
index 5918ecf..354d31a 100644
--- a/nimble/host/mesh/src/friend.c
+++ b/nimble/host/mesh/src/friend.c
@@ -125,6 +125,7 @@ static void purge_buffers(struct net_buf_slist_t *list)
 	while (!net_buf_slist_is_empty(list)) {
 		struct os_mbuf *buf;
 		buf = (void *)net_buf_slist_get(list);
+		BT_MESH_ADV(buf)->frags = NULL;
 		BT_MESH_ADV(buf)->flags &= ~NET_BUF_FRAGS;
 		net_buf_unref(buf);
 	}
@@ -1235,7 +1236,7 @@ static void friend_timeout(struct ble_npl_event *work)
 
 	/* Clear the flag we use for segment tracking */
 	BT_MESH_ADV(frnd->last)->flags &= ~NET_BUF_FRAGS;
-	BT_MESH_ADV(frnd->last)->flags = 0;
+	BT_MESH_ADV(frnd->last)->frags = 0;
 
 	BT_DBG("Sending buf %p from Friend Queue of LPN 0x%04x",
 	       frnd->last, frnd->lpn);
@@ -1381,6 +1382,7 @@ static void friend_purge_old_ack(struct bt_mesh_friend *frnd, uint64_t *seq_auth
 
 			net_buf_slist_remove(&frnd->queue, prev, cur);
 			frnd->queue_size--;
+			BT_MESH_ADV(buf)->frags = 0;
 
 			net_buf_unref(buf);
 			break;
@@ -1622,6 +1624,7 @@ static bool friend_queue_prepare_space(struct bt_mesh_friend *frnd, uint16_t add
 		BT_DBG("PENDING SEGMENTS %d", pending_segments);
 
 		/* Make sure old slist entry state doesn't remain */
+		BT_MESH_ADV(buf)->frags = NULL;
 		BT_MESH_ADV(buf)->flags &= ~NET_BUF_FRAGS;
 
 		net_buf_unref(buf);

[mynewt-nimble] 19/31: mesh: Fix restoring fast period divisor from settings

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 6253904845b4ab8afdc41eec21ff96211bed5106
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 14:27:03 2021 +0200

    mesh: Fix restoring fast period divisor from settings
    
    The Health Fast Period Divisor is stored within
    the model publish parameters on the access layer.
    The opposite part for divisor restoring has been missed.
    
    this is port of 73e1c6a77d71f8b51746946f78f0b3525101e1c0
---
 nimble/host/mesh/src/settings.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/nimble/host/mesh/src/settings.c b/nimble/host/mesh/src/settings.c
index cb583eb..903230d 100644
--- a/nimble/host/mesh/src/settings.c
+++ b/nimble/host/mesh/src/settings.c
@@ -552,6 +552,7 @@ static int mod_set_pub(struct bt_mesh_model *mod, char *val)
 		mod->pub->ttl = 0;
 		mod->pub->period = 0;
 		mod->pub->retransmit = 0;
+		mod->pub->period_div = pub.period_div;
 		mod->pub->count = 0;
 
 		BT_DBG("Cleared publication for model");

[mynewt-nimble] 08/31: mesh: Reduce proxy rx buffer to an exact fit

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit ab0f5d833b22c4aee089e750563175744d0d59d8
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:48:24 2021 +0200

    mesh: Reduce proxy rx buffer to an exact fit
    
    Removes the 3 byte padding at the end of each proxy connection's rx
    buffer.
    
    this is port of 135af766664f1fd1d9eacd2ffc78aa6d240663db
---
 nimble/host/mesh/src/proxy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/proxy.c b/nimble/host/mesh/src/proxy.c
index 9ed983d..d013c79 100644
--- a/nimble/host/mesh/src/proxy.c
+++ b/nimble/host/mesh/src/proxy.c
@@ -86,7 +86,7 @@ ble_uuid16_t BT_UUID_MESH_PROXY_DATA_OUT       = BLE_UUID16_INIT(0x2ade);
 
 #define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6)))
 
-#define CLIENT_BUF_SIZE 68
+#define CLIENT_BUF_SIZE 65
 
 static const struct ble_gap_adv_params slow_adv_param = {
 	.conn_mode = (BLE_GAP_CONN_MODE_UND),

[mynewt-nimble] 20/31: mesh: Send Link Close message when closing link

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 16efc1651aac7f82714c89d6338407cb67383aed
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 14:34:15 2021 +0200

    mesh: Send Link Close message when closing link
    
    Instead of silently closing the link we should send a Link Close message
    three times before resetting provisioning state.
    
    From Mesh Profile Specification v1.0.1.:
    ```
    5.3.1.4.3 Link Close message
    
    The Link Close message is used to close a link.
    ```
    
    ```
    5.3.2 Link Establishment procedure
    
    The device shall start the link timer, set to 60 seconds, when the link
    is open. When the link timer expires, then the device shall close the
    link.
    ```
    
    ```
    5.3.3 Generic Provisioning behavior
    
    If the sender does not receive a Transaction Acknowledgment message
    within 30 seconds after sending the first message in a transaction,
    the sender shall cancel the transaction, cancel the provisioning
    process and close the link.
    ```
    
    From Mesh Profile Test Specification p6:
    ```
    MESH/PVNR/PBADV/BV-01-C
    
    Test Procedure:
    [...]
    6. The IUT is induced to send a Link Close message with the Reason field
    set to 0x02 to terminate the link. The message is sent at least three
    times to ensure the message is received by the Lower Tester.
    ```
    
    this is port of 497d9df96acde1d28f7cd83c786e496e8ea0db67
---
 nimble/host/mesh/src/pb_adv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/pb_adv.c b/nimble/host/mesh/src/pb_adv.c
index 28391b1..653ec03 100644
--- a/nimble/host/mesh/src/pb_adv.c
+++ b/nimble/host/mesh/src/pb_adv.c
@@ -125,6 +125,7 @@ static void gen_prov_ack_send(uint8_t xact_id);
 static void link_open(struct prov_rx *rx, struct os_mbuf *buf);
 static void link_ack(struct prov_rx *rx, struct os_mbuf *buf);
 static void link_close(struct prov_rx *rx, struct os_mbuf *buf);
+static void prov_link_close(enum prov_bearer_link_status status);
 
 static void buf_sent(int err, void *user_data)
 {
@@ -281,7 +282,7 @@ static void protocol_timeout(struct ble_npl_event *work)
 	BT_DBG("");
 
 	link.rx.seg = 0U;
-	close_link(PROV_BEARER_LINK_STATUS_TIMEOUT);
+	prov_link_close(PROV_BEARER_LINK_STATUS_TIMEOUT);
 }
 /*******************************************************************************
  * Generic provisioning

[mynewt-nimble] 13/31: mesh: Check model publish pointer before dereferencing

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 5e24948f0f409826cedcf8a6a1c0189024ce85cd
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 13:10:27 2021 +0200

    mesh: Check model publish pointer before dereferencing
    
    Moves the if !(pub) check to happen before it gets used in the
    initialization of the message context in bt_mesh_model_publish.
    
    this is port of bba2d7b84b82ac7322898776b46727580bc39ae0
---
 nimble/host/mesh/src/access.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/nimble/host/mesh/src/access.c b/nimble/host/mesh/src/access.c
index da07718..d23a656 100644
--- a/nimble/host/mesh/src/access.c
+++ b/nimble/host/mesh/src/access.c
@@ -682,8 +682,15 @@ int bt_mesh_model_send(struct bt_mesh_model *model,
 
 int bt_mesh_model_publish(struct bt_mesh_model *model)
 {
+	int err;
 	struct os_mbuf *sdu = NET_BUF_SIMPLE(BT_MESH_TX_SDU_MAX);
 	struct bt_mesh_model_pub *pub = model->pub;
+
+	if (!pub) {
+		err = -ENOTSUP;
+		goto done;
+	}
+
 	struct bt_mesh_msg_ctx ctx = {
 		.addr = pub->addr,
 		.send_ttl = pub->ttl,
@@ -694,15 +701,9 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
 		.ctx = &ctx,
 		.src = bt_mesh_model_elem(model)->addr,
 	};
-	int err;
 
 	BT_DBG("");
 
-	if (!pub) {
-		err = -ENOTSUP;
-		goto done;
-	}
-
 	if (pub->addr == BT_MESH_ADDR_UNASSIGNED) {
 		err = -EADDRNOTAVAIL;
 		goto done;

[mynewt-nimble] 03/31: mesh: Add net transmit status rx in config client

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 15d9fd610b046f9c72e6766326d9536cdc3d155c
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:04:32 2021 +0200

    mesh: Add net transmit status rx in config client
    
    Adds an opcode handler for the network transmit status opcode.
    
    this is port of 66699b81708a257f41a3a4572cd67b904b511d01
---
 nimble/host/mesh/src/cfg_cli.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/nimble/host/mesh/src/cfg_cli.c b/nimble/host/mesh/src/cfg_cli.c
index a87cd7b..104d4e6 100644
--- a/nimble/host/mesh/src/cfg_cli.c
+++ b/nimble/host/mesh/src/cfg_cli.c
@@ -136,6 +136,27 @@ static void relay_status(struct bt_mesh_model *model,
 	k_sem_give(&cli->op_sync);
 }
 
+static void net_transmit_status(struct bt_mesh_model *model,
+				struct bt_mesh_msg_ctx *ctx,
+				struct os_mbuf *buf)
+{
+	uint8_t *status;
+
+	BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
+	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
+	       bt_hex(buf->om_data, buf->om_len));
+
+	if (cli->op_pending != OP_NET_TRANSMIT_STATUS) {
+		BT_WARN("Unexpected Net Transmit Status message");
+		return;
+	}
+
+	status = cli->op_param;
+	*status = net_buf_simple_pull_u8(buf);
+
+	k_sem_give(&cli->op_sync);
+}
+
 struct net_key_param {
 	uint8_t *status;
 	uint16_t net_idx;
@@ -693,6 +714,7 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
 	{ OP_FRIEND_STATUS,          1,   friend_status },
 	{ OP_GATT_PROXY_STATUS,      1,   gatt_proxy_status },
 	{ OP_RELAY_STATUS,           2,   relay_status },
+	{ OP_NET_TRANSMIT_STATUS,    1,   net_transmit_status },
 	{ OP_NET_KEY_STATUS,         3,   net_key_status },
 	{ OP_NET_KEY_LIST,           0,   net_key_list },
 	{ OP_APP_KEY_STATUS,         4,   app_key_status },

[mynewt-nimble] 10/31: mesh: Add CDB handle key refresh phase

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 83cf6da68cb8c49371875cc113d176f9cfe74f89
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:58:17 2021 +0200

    mesh: Add CDB handle key refresh phase
    
    Fixed some undesired or incorrect macros, which
    can cause build error.
    
    this is port of 71fd8e1d0141096238aadb9ce20a14781cf50b7c
---
 nimble/host/mesh/include/mesh/cdb.h |  1 -
 nimble/host/mesh/include/mesh/cfg.h |  6 ++++++
 nimble/host/mesh/src/cdb.c          |  2 +-
 nimble/host/mesh/src/provisioner.c  |  2 +-
 nimble/host/mesh/src/settings.c     |  4 +---
 nimble/host/mesh/src/shell.c        | 10 +++++-----
 nimble/host/mesh/src/testing.c      |  4 ----
 7 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/nimble/host/mesh/include/mesh/cdb.h b/nimble/host/mesh/include/mesh/cdb.h
index 8f9a6bc..440390c 100644
--- a/nimble/host/mesh/include/mesh/cdb.h
+++ b/nimble/host/mesh/include/mesh/cdb.h
@@ -40,7 +40,6 @@ struct bt_mesh_cdb_node {
 struct bt_mesh_cdb_subnet {
 	uint16_t net_idx;
 
-	bool kr_flag;
 	uint8_t kr_phase;
 
 	struct {
diff --git a/nimble/host/mesh/include/mesh/cfg.h b/nimble/host/mesh/include/mesh/cfg.h
index 378f0a0..6fd6926 100644
--- a/nimble/host/mesh/include/mesh/cfg.h
+++ b/nimble/host/mesh/include/mesh/cfg.h
@@ -35,6 +35,12 @@ enum bt_mesh_feat_state {
 	BT_MESH_FEATURE_NOT_SUPPORTED,
 };
 
+/* Key Refresh Phase */
+#define BT_MESH_KR_NORMAL                   0x00
+#define BT_MESH_KR_PHASE_1                  0x01
+#define BT_MESH_KR_PHASE_2                  0x02
+#define BT_MESH_KR_PHASE_3                  0x03
+
 /* Legacy feature defines */
 #define BT_MESH_RELAY_DISABLED              BT_MESH_FEATURE_DISABLED
 #define BT_MESH_RELAY_ENABLED               BT_MESH_FEATURE_ENABLED
diff --git a/nimble/host/mesh/src/cdb.c b/nimble/host/mesh/src/cdb.c
index f0c2e5f..60d47de 100644
--- a/nimble/host/mesh/src/cdb.c
+++ b/nimble/host/mesh/src/cdb.c
@@ -235,7 +235,7 @@ uint8_t bt_mesh_cdb_subnet_flags(const struct bt_mesh_cdb_subnet *sub)
 {
 	uint8_t flags = 0x00;
 
-	if (sub && sub->kr_flag) {
+	if (sub && SUBNET_KEY_TX_IDX(sub)) {
 		flags |= BT_MESH_NET_FLAG_KR;
 	}
 
diff --git a/nimble/host/mesh/src/provisioner.c b/nimble/host/mesh/src/provisioner.c
index e26efe7..265dbf2 100644
--- a/nimble/host/mesh/src/provisioner.c
+++ b/nimble/host/mesh/src/provisioner.c
@@ -503,7 +503,7 @@ static void send_prov_data(void)
 #endif
 	bt_mesh_prov_buf_init(pdu, PROV_DATA);
 #if MYNEWT_VAL(BLE_MESH_CDB)
-	net_buf_simple_add_mem(pdu, sub->keys[sub->kr_flag].net_key, 16);
+	net_buf_simple_add_mem(&pdu, sub->keys[SUBNET_KEY_TX_IDX(sub)].net_key, 16);
 	net_buf_simple_add_be16(pdu, prov_device.node->net_idx);
 	net_buf_simple_add_u8(pdu, bt_mesh_cdb_subnet_flags(sub));
 	net_buf_simple_add_be32(pdu, bt_mesh_cdb.iv_index);
diff --git a/nimble/host/mesh/src/settings.c b/nimble/host/mesh/src/settings.c
index 193cc0b..1fb2b08 100644
--- a/nimble/host/mesh/src/settings.c
+++ b/nimble/host/mesh/src/settings.c
@@ -829,7 +829,6 @@ static int cdb_subnet_set(int argc, char *name)
 	if (sub) {
 		BT_DBG("Updating existing NetKeyIndex 0x%03x", net_idx);
 
-		sub->kr_flag = key.kr_flag;
 		sub->kr_phase = key.kr_phase;
 		memcpy(sub->keys[0].net_key, &key.val[0], 16);
 		memcpy(sub->keys[1].net_key, &key.val[1], 16);
@@ -843,7 +842,6 @@ static int cdb_subnet_set(int argc, char *name)
 		return -ENOMEM;
 	}
 
-	sub->kr_flag = key.kr_flag;
 	sub->kr_phase = key.kr_phase;
 	memcpy(sub->keys[0].net_key, &key.val[0], 16);
 	memcpy(sub->keys[1].net_key, &key.val[1], 16);
@@ -1608,7 +1606,7 @@ static void store_cdb_subnet(const struct bt_mesh_cdb_subnet *sub)
 
 	memcpy(&key.val[0], sub->keys[0].net_key, 16);
 	memcpy(&key.val[1], sub->keys[1].net_key, 16);
-	key.kr_flag = sub->kr_flag;
+	key.kr_flag = 0U; /* Deprecated */
 	key.kr_phase = sub->kr_phase;
 
 	snprintk(path, sizeof(path), "bt/mesh/cdb/Subnet/%x", sub->net_idx);
diff --git a/nimble/host/mesh/src/shell.c b/nimble/host/mesh/src/shell.c
index 1ac4caf..ade9cd6 100644
--- a/nimble/host/mesh/src/shell.c
+++ b/nimble/host/mesh/src/shell.c
@@ -738,7 +738,7 @@ int cmd_mesh_init(int argc, char *argv[])
 
 	printk("Mesh initialized\n");
 
-	if (IS_ENABLED(CONFIG_SETTINGS)) {
+	if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
 		settings_load();
 	}
 
@@ -2345,7 +2345,7 @@ static int cmd_provision(int argc, char *argv[])
 			return 0;
 		}
 
-		net_key = sub->keys[sub->kr_flag].net_key;
+		net_key = sub->keys[SUBNET_KEY_TX_IDX(sub)].net_key;
 	}
 
 	err = bt_mesh_provision(net_key, net_idx, 0, iv_index, addr,
@@ -2905,7 +2905,7 @@ static int cmd_cdb_node_add(int argc, char *argv[])
 
 	memcpy(node->dev_key, dev_key, 16);
 
-	if (IS_ENABLED(CONFIG_SETTINGS)) {
+	if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
 		bt_mesh_store_cdb_node(node);
 	}
 
@@ -2959,7 +2959,7 @@ static int cmd_cdb_subnet_add(int argc,
 
 	memcpy(sub->keys[0].net_key, net_key, 16);
 
-	if (IS_ENABLED(CONFIG_SETTINGS)) {
+	if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
 		bt_mesh_store_cdb_subnet(sub);
 	}
 
@@ -3015,7 +3015,7 @@ static int cmd_cdb_app_key_add(int argc,
 
 	memcpy(key->keys[0].app_key, app_key, 16);
 
-	if (IS_ENABLED(CONFIG_SETTINGS)) {
+	if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
 		bt_mesh_store_cdb_app_key(key);
 	}
 
diff --git a/nimble/host/mesh/src/testing.c b/nimble/host/mesh/src/testing.c
index dfe8d18..7ee11a1 100644
--- a/nimble/host/mesh/src/testing.c
+++ b/nimble/host/mesh/src/testing.c
@@ -135,8 +135,6 @@ void bt_test_print_credentials(void)
 		console_printf("Subnet: %d\n", i);
 		console_printf("\tNetKeyIdx: %04x\n",
 			       sub->net_idx);
-		console_printf("\tNetKey: %s\n",
-			       bt_hex(sub->keys[sub->kr_flag].net_key, 16));
 	}
 
 	for (i = 0; i < ARRAY_SIZE(bt_mesh_cdb.app_keys); ++i)
@@ -154,8 +152,6 @@ void bt_test_print_credentials(void)
 			       app_key->net_idx);
 		console_printf("\tAppKeyIdx: %04x\n",
 			       app_key->app_idx);
-		console_printf("\tAppKey: %s\n",
-			       bt_hex(app_key->keys[sub->kr_flag].app_key, 16));
 	}
 
 	for (i = 0; i < ARRAY_SIZE(bt_mesh_cdb.subnets); ++i)

[mynewt-nimble] 06/31: mesh: Initialize msg_ctx when re-encrypting friend msg

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 8256009f6d90e6b81b9839e7ec32de87b34df87b
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:46:00 2021 +0200

    mesh: Initialize msg_ctx when re-encrypting friend msg
    
    Set app_idx and net_idx in the msg_ctx before calling
    bt_mesh_keys_resolve when re-encrypting friend messages, as they'll be
    referenced inside the function.
    
    this is port of 48526b6925a11bb979b657912dda012303e9050e
---
 nimble/host/mesh/src/friend.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/friend.c b/nimble/host/mesh/src/friend.c
index 9a83c87..8dc55c1 100644
--- a/nimble/host/mesh/src/friend.c
+++ b/nimble/host/mesh/src/friend.c
@@ -345,7 +345,12 @@ static int unseg_app_sdu_unpack(struct bt_mesh_friend *frnd,
 				struct unseg_app_sdu_meta *meta)
 {
 	uint16_t app_idx = FRIEND_ADV(buf)->app_idx;
-	struct bt_mesh_net_rx net;
+	struct bt_mesh_net_rx net = {
+		.ctx = {
+			.app_idx = app_idx,
+			.net_idx = frnd->subnet->net_idx,
+		},
+	};
 	int err;
 
 	meta->subnet = frnd->subnet;
@@ -437,6 +442,8 @@ static int unseg_app_sdu_prepare(struct bt_mesh_friend *frnd,
 		return 0;
 	}
 
+	BT_DBG("Re-encrypting friend pdu");
+
 	err = unseg_app_sdu_decrypt(frnd, buf, &meta);
 	if (err) {
 		BT_WARN("Decryption failed! %d", err);

[mynewt-nimble] 02/31: mesh: Fix heartbeat subscription tests

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 8becf2a64f0659d431685e5f39f8fbfa2aa2404b
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 10:44:43 2021 +0200

    mesh: Fix heartbeat subscription tests
    
    MESH/NODE/CFG/HBS/BV-01-C expects the MinHops to be 0x7f after
    disabling subscription, but 0x00 for subsequent Get requests.
    
    MESH/NODE/CFG/HBS/BV-02-C expects us to return previous
    count value and then reset it to 0.
    
    this is port of 419d2aa85b3e2656ac8bdd99875313e9f4b4720c
---
 nimble/host/mesh/src/cfg_srv.c   | 10 +++++++++-
 nimble/host/mesh/src/heartbeat.c |  5 +++++
 nimble/host/mesh/src/heartbeat.h |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/cfg_srv.c b/nimble/host/mesh/src/cfg_srv.c
index 8a085bd..404f731 100644
--- a/nimble/host/mesh/src/cfg_srv.c
+++ b/nimble/host/mesh/src/cfg_srv.c
@@ -2387,11 +2387,19 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
 	/* MESH/NODE/CFG/HBS/BV-01-C expects the MinHops to be 0x7f after
 	 * disabling subscription, but 0x00 for subsequent Get requests.
 	 */
-	if (!period_log) {
+	if (sub.src == BT_MESH_ADDR_UNASSIGNED || !period_log) {
 		sub.min_hops = BT_MESH_TTL_MAX;
 	}
 
 	hb_sub_send_status(model, ctx, &sub);
+
+	/* MESH/NODE/CFG/HBS/BV-02-C expects us to return previous
+	 * count value and then reset it to 0.
+	 */
+	if (sub.src != BT_MESH_ADDR_UNASSIGNED &&
+	    sub.dst != BT_MESH_ADDR_UNASSIGNED && !period) {
+		bt_mesh_hb_sub_reset_count();
+	}
 }
 
 const struct bt_mesh_model_op bt_mesh_cfg_srv_op[] = {
diff --git a/nimble/host/mesh/src/heartbeat.c b/nimble/host/mesh/src/heartbeat.c
index 538a1cb..f990dc0 100644
--- a/nimble/host/mesh/src/heartbeat.c
+++ b/nimble/host/mesh/src/heartbeat.c
@@ -303,6 +303,11 @@ uint8_t bt_mesh_hb_sub_set(uint16_t src, uint16_t dst, uint32_t period)
 	return STATUS_SUCCESS;
 }
 
+void bt_mesh_hb_sub_reset_count(void)
+{
+	sub.count = 0;
+}
+
 void bt_mesh_hb_sub_get(struct bt_mesh_hb_sub *get)
 {
 	*get = sub;
diff --git a/nimble/host/mesh/src/heartbeat.h b/nimble/host/mesh/src/heartbeat.h
index c43683f..92b0cae 100644
--- a/nimble/host/mesh/src/heartbeat.h
+++ b/nimble/host/mesh/src/heartbeat.h
@@ -38,3 +38,4 @@ void bt_mesh_hb_feature_changed(uint16_t features);
 
 uint8_t bt_mesh_hb_pub_set(struct bt_mesh_hb_pub *hb_pub);
 uint8_t bt_mesh_hb_sub_set(uint16_t src, uint16_t dst, uint32_t period);
+void bt_mesh_hb_sub_reset_count(void);

[mynewt-nimble] 31/31: mesh: Fix macro in net.c

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit a4d3fb4368eb1952739121317f0aa64d54e1bcb4
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Fri May 7 14:06:21 2021 +0200

    mesh: Fix macro in net.c
---
 nimble/host/mesh/src/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/net.c b/nimble/host/mesh/src/net.c
index db97b95..bbe186e 100644
--- a/nimble/host/mesh/src/net.c
+++ b/nimble/host/mesh/src/net.c
@@ -344,7 +344,7 @@ static void bt_mesh_net_local(struct ble_npl_event *work)
 
 static const struct bt_mesh_net_cred *net_tx_cred_get(struct bt_mesh_net_tx *tx)
 {
-#if defined(CONFIG_BT_MESH_LOW_POWER)
+#if IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)
 	if (tx->friend_cred && bt_mesh_lpn_established()) {
 		return &bt_mesh.lpn.cred[SUBNET_KEY_TX_IDX(tx->sub)];
 	}

[mynewt-nimble] 22/31: mesh: Set BT_MESH_ADV_USER_DATA_SIZE to size of 4 byte pointer

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit bc1fe4e4320976d23d84db4c36f612741fb6245e
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Thu Apr 22 10:59:19 2021 +0200

    mesh: Set BT_MESH_ADV_USER_DATA_SIZE to size of 4 byte pointer
    
    this is affecting MESH/NODE/TNPT/BV-04-C
---
 nimble/host/mesh/src/adv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/adv.h b/nimble/host/mesh/src/adv.h
index 779ee58..6566df9 100644
--- a/nimble/host/mesh/src/adv.h
+++ b/nimble/host/mesh/src/adv.h
@@ -17,7 +17,7 @@
 #define BT_MESH_ADV_DATA_SIZE 31
 
 /* The user data is a pointer (4 bytes) to struct bt_mesh_adv */
-#define BT_MESH_ADV_USER_DATA_SIZE (sizeof(struct bt_mesh_adv *))
+#define BT_MESH_ADV_USER_DATA_SIZE 4
 
 #define BT_MESH_MBUF_HEADER_SIZE (sizeof(struct os_mbuf_pkthdr) + \
                                     BT_MESH_ADV_USER_DATA_SIZE +\

[mynewt-nimble] 18/31: mesh: Make internal virtual addr pointers const

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 1696d0fbeb66912e7eb456ce97c06f0e36a13b8f
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 14:26:11 2021 +0200

    mesh: Make internal virtual addr pointers const
    
    Adds the const qualifier to the internal api for adding and removing
    virtual addresses, to allow them to accept const hardcoded values in
    tests.
    
    this is port of 20ce680d790a4c0b8232f5aeadce864c1fc537af
---
 nimble/host/mesh/src/transport.c | 4 ++--
 nimble/host/mesh/src/transport.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/nimble/host/mesh/src/transport.c b/nimble/host/mesh/src/transport.c
index 9e70434..6391272 100644
--- a/nimble/host/mesh/src/transport.c
+++ b/nimble/host/mesh/src/transport.c
@@ -1650,7 +1650,7 @@ static inline void va_store(struct bt_mesh_va *store)
 	}
 }
 
-uint8_t bt_mesh_va_add(uint8_t uuid[16], uint16_t *addr)
+uint8_t bt_mesh_va_add(const uint8_t uuid[16], uint16_t *addr)
 {
 	struct bt_mesh_va *va = NULL;
 	int err;
@@ -1692,7 +1692,7 @@ uint8_t bt_mesh_va_add(uint8_t uuid[16], uint16_t *addr)
 	return STATUS_SUCCESS;
 }
 
-uint8_t bt_mesh_va_del(uint8_t uuid[16], uint16_t *addr)
+uint8_t bt_mesh_va_del(const uint8_t uuid[16], uint16_t *addr)
 {
 	struct bt_mesh_va *va = NULL;
 
diff --git a/nimble/host/mesh/src/transport.h b/nimble/host/mesh/src/transport.h
index 23be713..bf458e8 100644
--- a/nimble/host/mesh/src/transport.h
+++ b/nimble/host/mesh/src/transport.h
@@ -106,8 +106,8 @@ struct bt_mesh_va *bt_mesh_va_get(uint16_t index);
 
 struct bt_mesh_va *bt_mesh_va_find(uint8_t uuid[16]);
 
-uint8_t bt_mesh_va_add(uint8_t uuid[16], uint16_t *addr);
+uint8_t bt_mesh_va_add(const uint8_t uuid[16], uint16_t *addr);
 
-uint8_t bt_mesh_va_del(uint8_t uuid[16], uint16_t *addr);
+uint8_t bt_mesh_va_del(const uint8_t uuid[16], uint16_t *addr);
 
 uint8_t *bt_mesh_va_label_get(uint16_t addr);
\ No newline at end of file

[mynewt-nimble] 07/31: mesh: Update seqnum when re-encrypting for friend

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 8255bee130c3ab3e1852448f09634e60fd3ca9fc
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:47:24 2021 +0200

    mesh: Update seqnum when re-encrypting for friend
    
    Sets the sequence number when re-encrypting messages from the friend to
    the lpn.
    
    this is port of 512444d863f0e4de69ea600dda37b11f032e9707
---
 nimble/host/mesh/src/friend.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/friend.c b/nimble/host/mesh/src/friend.c
index 8dc55c1..5918ecf 100644
--- a/nimble/host/mesh/src/friend.c
+++ b/nimble/host/mesh/src/friend.c
@@ -442,7 +442,8 @@ static int unseg_app_sdu_prepare(struct bt_mesh_friend *frnd,
 		return 0;
 	}
 
-	BT_DBG("Re-encrypting friend pdu");
+	BT_DBG("Re-encrypting friend pdu (SeqNum %06x -> %06x)",
+	       meta.crypto.seq_num, bt_mesh.seq);
 
 	err = unseg_app_sdu_decrypt(frnd, buf, &meta);
 	if (err) {
@@ -450,6 +451,8 @@ static int unseg_app_sdu_prepare(struct bt_mesh_friend *frnd,
 		return err;
 	}
 
+	meta.crypto.seq_num = bt_mesh.seq;
+
 	err = unseg_app_sdu_encrypt(frnd, buf, &meta);
 	if (err) {
 		BT_WARN("Re-encryption failed! %d", err);

[mynewt-nimble] 05/31: mesh: Verify network buffer max len

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 68c409ab57b351e4161c33b2d2775a41f2289bb0
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:29:23 2021 +0200

    mesh: Verify network buffer max len
    
    As network_decode needs a target buffer for decoding, the max PDU length
    must be checked to prevent overflow on the target buffer. When receiving
    a proxy configuration message with excessive length, there's no previous
    check for this.
    
    Also pulls the NET PDU length defines out into net.h, so they can be
    used when defining the target buffers.
    
    this is port of 2bd5b63dfd1cba183f2c20af5ff497346827087f
---
 nimble/host/mesh/src/net.c   | 15 ++++++---------
 nimble/host/mesh/src/net.h   | 13 +++++++++++++
 nimble/host/mesh/src/proxy.c |  2 +-
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/nimble/host/mesh/src/net.c b/nimble/host/mesh/src/net.c
index 8b86935..2e1d6dc 100644
--- a/nimble/host/mesh/src/net.c
+++ b/nimble/host/mesh/src/net.c
@@ -34,14 +34,6 @@
 #include "mesh/glue.h"
 #include "mesh/slist.h"
 
-/* Minimum valid Mesh Network PDU length. The Network headers
- * themselves take up 9 bytes. After that there is a minumum of 1 byte
- * payload for both CTL=1 and CTL=0 PDUs (smallest OpCode is 1 byte). CTL=1
- * PDUs must use a 64-bit (8 byte) NetMIC, whereas CTL=0 PDUs have at least
- * a 32-bit (4 byte) NetMIC and AppMIC giving again a total of 8 bytes.
- */
-#define BT_MESH_NET_MIN_PDU_LEN (BT_MESH_NET_HDR_LEN + 1 + 8)
-
 #define LOOPBACK_MAX_PDU_LEN (BT_MESH_NET_HDR_LEN + 16)
 #define LOOPBACK_USER_DATA_SIZE sizeof(struct bt_mesh_subnet *)
 #define LOOPBACK_BUF_SUB(buf) (*(struct bt_mesh_subnet **)net_buf_user_data(buf))
@@ -702,6 +694,11 @@ int bt_mesh_net_decode(struct os_mbuf *in, enum bt_mesh_net_if net_if,
 		return -EINVAL;
 	}
 
+	if (in->om_len > BT_MESH_NET_MAX_PDU_LEN) {
+		BT_WARN("Dropping too long mesh packet (len %u)", in->om_len);
+		return -EINVAL;
+	}
+
 	if (net_if == BT_MESH_NET_IF_ADV && check_dup(in)) {
 		BT_DBG("duplicate packet; dropping %u bytes: %s", in->om_len,
 			   bt_hex(in->om_data, in->om_len));
@@ -754,7 +751,7 @@ int bt_mesh_net_decode(struct os_mbuf *in, enum bt_mesh_net_if net_if,
 void bt_mesh_net_recv(struct os_mbuf *data, int8_t rssi,
 		      enum bt_mesh_net_if net_if)
 {
-	struct os_mbuf *buf = NET_BUF_SIMPLE(29);
+	struct os_mbuf *buf = NET_BUF_SIMPLE(BT_MESH_NET_MAX_PDU_LEN);
 	struct bt_mesh_net_rx rx = { .ctx.recv_rssi = rssi };
 	struct net_buf_simple_state state;
 
diff --git a/nimble/host/mesh/src/net.h b/nimble/host/mesh/src/net.h
index f4b1192..8c50154 100644
--- a/nimble/host/mesh/src/net.h
+++ b/nimble/host/mesh/src/net.h
@@ -25,6 +25,19 @@
 				    CONFIG_BT_MESH_IVU_DIVIDER)
 #define BT_MESH_IVU_TIMEOUT        K_HOURS(BT_MESH_IVU_HOURS)
 
+/* Minimum valid Mesh Network PDU length. The Network headers
+ * themselves take up 9 bytes. After that there is a minimum of 1 byte
+ * payload for both CTL=1 and CTL=0 PDUs (smallest OpCode is 1 byte). CTL=1
+ * PDUs must use a 64-bit (8 byte) NetMIC, whereas CTL=0 PDUs have at least
+ * a 32-bit (4 byte) NetMIC and AppMIC giving again a total of 8 bytes.
+ */
+#define BT_MESH_NET_MIN_PDU_LEN (BT_MESH_NET_HDR_LEN + 1 + 8)
+/* Maximum valid Mesh Network PDU length. The longest packet can either be a
+ * transport control message (CTL=1) of 12 bytes + 8 bytes of NetMIC, or an
+ * access message (CTL=0) of 16 bytes + 4 bytes of NetMIC.
+ */
+#define BT_MESH_NET_MAX_PDU_LEN (BT_MESH_NET_HDR_LEN + 16 + 4)
+
 struct bt_mesh_net_cred;
 
 struct bt_mesh_node {
diff --git a/nimble/host/mesh/src/proxy.c b/nimble/host/mesh/src/proxy.c
index 6d631b7..9ed983d 100644
--- a/nimble/host/mesh/src/proxy.c
+++ b/nimble/host/mesh/src/proxy.c
@@ -328,7 +328,7 @@ static void send_filter_status(struct bt_mesh_proxy_client *client,
 
 static void proxy_cfg(struct bt_mesh_proxy_client *client)
 {
-	struct os_mbuf *buf = NET_BUF_SIMPLE(29);
+	struct os_mbuf *buf = NET_BUF_SIMPLE(BT_MESH_NET_MAX_PDU_LEN);
 	struct bt_mesh_net_rx rx;
 	uint8_t opcode;
 	int err;

[mynewt-nimble] 11/31: mesh: Get rid of magic number in cmd_get_comp

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit c5f9d9a3c49125759a25b54119d58d867c0fc62c
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 13:04:04 2021 +0200

    mesh: Get rid of magic number in cmd_get_comp
---
 nimble/host/mesh/src/shell.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/shell.c b/nimble/host/mesh/src/shell.c
index ade9cd6..0a27e27 100644
--- a/nimble/host/mesh/src/shell.c
+++ b/nimble/host/mesh/src/shell.c
@@ -997,7 +997,7 @@ struct shell_cmd_help cmd_timeout_help = {
 
 static int cmd_get_comp(int argc, char *argv[])
 {
-	struct os_mbuf *comp = NET_BUF_SIMPLE(32);
+	struct os_mbuf *comp = NET_BUF_SIMPLE(BT_MESH_RX_SDU_MAX);
 	uint8_t status, page = 0x00;
 	int err = 0;
 

[mynewt-nimble] 26/31: bttester: Add lpn_cb

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 0fba723f06ab652a35f6bc02dd21d9a85e119e72
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Fri Apr 30 13:25:45 2021 +0200

    bttester: Add lpn_cb
    
    Add support of lpn_cb (established and terminated). It's required for
    MESH/NODE/HBP-BV-05-C
    
    Allow to acces bt_mesh by apllications (required to fill btp response
    with valid data)
---
 apps/bttester/src/bttester.h         | 21 ++++++++++++++++++++
 apps/bttester/src/mesh.c             | 37 ++++++++++++++++++++++++++++++++++++
 nimble/host/mesh/include/mesh/mesh.h |  1 +
 3 files changed, 59 insertions(+)

diff --git a/apps/bttester/src/bttester.h b/apps/bttester/src/bttester.h
index 6761681..4a8fc47 100644
--- a/apps/bttester/src/bttester.h
+++ b/apps/bttester/src/bttester.h
@@ -997,6 +997,27 @@ struct mesh_invalid_bearer_ev {
 
 #define MESH_EV_INCOMP_TIMER_EXP	0x88
 
+#define MESH_EV_LPN_ESTABLISHED		0x8b
+struct mesh_lpn_established_ev {
+    uint16_t net_idx;
+    uint16_t friend_addr;
+    uint8_t queue_size;
+    uint8_t recv_win;
+} __packed;
+
+#define MESH_EV_LPN_TERMINATED		0x8c
+struct mesh_lpn_terminated_ev {
+    uint16_t net_idx;
+    uint16_t friend_addr;
+} __packed;
+
+#define MESH_EV_LPN_POLLED			0x8d
+struct mesh_lpn_polled_ev {
+    uint16_t net_idx;
+    uint16_t friend_addr;
+    uint8_t retry;
+} __packed;
+
 void tester_init(void);
 void tester_rsp(uint8_t service, uint8_t opcode, uint8_t index, uint8_t status);
 void tester_send(uint8_t service, uint8_t opcode, uint8_t index, uint8_t *data,
diff --git a/apps/bttester/src/mesh.c b/apps/bttester/src/mesh.c
index 1ad322f..87bdbea 100644
--- a/apps/bttester/src/mesh.c
+++ b/apps/bttester/src/mesh.c
@@ -937,11 +937,48 @@ static struct bt_test_cb bt_test_cb = {
 	.mesh_trans_incomp_timer_exp = incomp_timer_exp_cb,
 };
 
+static void lpn_established(uint16_t friend_addr)
+{
+
+	struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
+	struct mesh_lpn_established_ev ev = { lpn->sub->net_idx, friend_addr, lpn->queue_size,
+					      lpn->recv_win };
+
+	SYS_LOG_DBG("Friendship (as LPN) established with "
+		"Friend 0x%04x Queue Size %d Receive Window %d",
+		friend_addr, lpn->queue_size, lpn->recv_win);
+
+	tester_send(BTP_SERVICE_ID_MESH, MESH_EV_LPN_ESTABLISHED,
+		    CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
+}
+
+static void lpn_terminated(uint16_t friend_addr)
+{
+	struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
+	struct mesh_lpn_terminated_ev ev = { lpn->sub->net_idx, friend_addr };
+
+	SYS_LOG_DBG("Friendship (as LPN) lost with Friend "
+		"0x%04x", friend_addr);
+
+	tester_send(BTP_SERVICE_ID_MESH, MESH_EV_LPN_TERMINATED,
+		    CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
+}
+
+void lpn_cb(uint16_t friend_addr, bool established)
+{
+	if (established) {
+		lpn_established(friend_addr);
+	} else {
+		lpn_terminated(friend_addr);
+	}
+}
+
 uint8_t tester_init_mesh(void)
 {
 	health_pub_init();
 
 	if (IS_ENABLED(CONFIG_BT_TESTING)) {
+		bt_mesh_lpn_set_cb(lpn_cb);
 		bt_test_cb_register(&bt_test_cb);
 	}
 
diff --git a/nimble/host/mesh/include/mesh/mesh.h b/nimble/host/mesh/include/mesh/mesh.h
index b9bc24f..83390ec 100644
--- a/nimble/host/mesh/include/mesh/mesh.h
+++ b/nimble/host/mesh/include/mesh/mesh.h
@@ -27,5 +27,6 @@
 #include "cfg.h"
 #include "heartbeat.h"
 #include "../src/app_keys.h"
+#include "../src/net.h"
 
 #endif /* __BT_MESH_H */

[mynewt-nimble] 01/31: mesh: Fix typo when deleting app key in CDB

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 77a1779a53a4c18d18804900988ffac437800d11
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 10:39:57 2021 +0200

    mesh: Fix typo when deleting app key in CDB
    
    This commit sets `net_idx` to `BT_MESH_KEY_UNUSED` when deleting app key in
    cdb.
    
    this is port of d593af30db1c9164db35ccc28862b06718440cad
---
 nimble/host/mesh/src/cdb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/cdb.c b/nimble/host/mesh/src/cdb.c
index 459730e..f0c2e5f 100644
--- a/nimble/host/mesh/src/cdb.c
+++ b/nimble/host/mesh/src/cdb.c
@@ -359,7 +359,7 @@ void bt_mesh_cdb_app_key_del(struct bt_mesh_cdb_app_key *key, bool store)
 		bt_mesh_clear_cdb_app_key(key);
 	}
 
-	key->net_idx = BT_MESH_ADDR_UNASSIGNED;
+	key->net_idx = BT_MESH_KEY_UNUSED;
 	memset(key->keys, 0, sizeof(key->keys));
 }
 

[mynewt-nimble] 09/31: mesh: Fix provisioner provisioning

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 9f396bca302c892a43f79c01b96fdaa1cc417040
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:51:57 2021 +0200

    mesh: Fix provisioner provisioning
    
    Correct format errors, such as oob action 2-octers
    should use 0x%04x, and action in prov capalilities pdu
    big-ending. When every call `bt_mesh_auth_method_set<*>`
    should also clear auth value, otherwise will case confirm
    failed.
    
    Provisioner role expect peer public key should be sent
    immediately, instead of requiring ACK. After all, ACK may
    be lost, and the other device’s public key will be sent
    over, and provisioning procedure will be failed..
    
    this is port of 0841ee69f2376f40befa938caacf97172be6fecd
---
 nimble/host/mesh/src/prov.c        |  4 ++--
 nimble/host/mesh/src/provisioner.c | 18 ++++++++++--------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/nimble/host/mesh/src/prov.c b/nimble/host/mesh/src/prov.c
index ba514dd..170fc1d 100644
--- a/nimble/host/mesh/src/prov.c
+++ b/nimble/host/mesh/src/prov.c
@@ -40,7 +40,7 @@ int bt_mesh_prov_reset_state(void (*func)(const uint8_t key[64]))
 
 	int err;
 	static struct bt_pub_key_cb pub_key_cb;
-	const size_t offset = offsetof(struct bt_mesh_prov_link, dhkey);
+	const size_t offset = offsetof(struct bt_mesh_prov_link, auth);
 
 	pub_key_cb.func = func ? func : pub_key_ready;
 
@@ -257,7 +257,7 @@ static void prov_recv(const struct prov_bearer *bearer, void *cb_data,
 
 	if (type >= ARRAY_SIZE(bt_mesh_prov_link.role->op)) {
 		BT_ERR("Unknown provisioning PDU type 0x%02x", type);
-		bt_mesh_prov_link.role->error(PROV_ERR_NVAL_FMT);
+		bt_mesh_prov_link.role->error(PROV_ERR_NVAL_PDU);
 		return;
 	}
 
diff --git a/nimble/host/mesh/src/provisioner.c b/nimble/host/mesh/src/provisioner.c
index d69aa66..e26efe7 100644
--- a/nimble/host/mesh/src/provisioner.c
+++ b/nimble/host/mesh/src/provisioner.c
@@ -168,9 +168,9 @@ static bool prov_check_method(struct bt_mesh_dev_capabilities *caps)
 		}
 
 		if (!(BIT(bt_mesh_prov_link.oob_action) & caps->input_actions)) {
-			BT_WARN("The required input action (0x%02x) "
+			BT_WARN("The required input action (0x%04x) "
 				"not supported by the device (0x%02x)",
-				bt_mesh_prov_link.oob_action, caps->input_actions);
+				(uint16_t)BIT(bt_mesh_prov_link.oob_action), caps->input_actions);
 			return false;
 		}
 
@@ -194,9 +194,9 @@ static bool prov_check_method(struct bt_mesh_dev_capabilities *caps)
 		}
 
 		if (!(BIT(bt_mesh_prov_link.oob_action) & caps->output_actions)) {
-			BT_WARN("The required output action (0x%02x) "
+			BT_WARN("The required output action (0x%04x) "
 				"not supported by the device (0x%02x)",
-				bt_mesh_prov_link.oob_action, caps->output_actions);
+				(uint16_t)BIT(bt_mesh_prov_link.oob_action), caps->output_actions);
 			return false;
 		}
 
@@ -226,9 +226,11 @@ static void prov_capabilities(const uint8_t *data)
 	BT_DBG("Static OOB Type:   0x%02x", caps.static_oob);
 	BT_DBG("Output OOB Size:   %u", caps.output_size);
 
-	caps.output_actions = (bt_mesh_output_action_t)data[6];
+	caps.output_actions = (bt_mesh_output_action_t)
+		(sys_get_be16(&data[6]));
 	caps.input_size = data[8];
-	caps.input_actions = (bt_mesh_input_action_t)data[9];
+	caps.input_actions = (bt_mesh_input_action_t)
+		(sys_get_be16(&data[9]));
 	BT_DBG("Output OOB Action: 0x%04x", caps.output_actions);
 	BT_DBG("Input OOB Size:    %u", caps.input_size);
 	BT_DBG("Input OOB Action:  0x%04x", caps.input_actions);
@@ -324,8 +326,6 @@ static void public_key_sent(int err, void *cb_data)
 		prov_dh_key_gen();
 		return;
 	}
-
-	bt_mesh_prov_link.expect = PROV_PUB_KEY;
 }
 
 static void send_pub_key(void)
@@ -355,6 +355,8 @@ static void send_pub_key(void)
 		BT_ERR("Failed to send Public Key");
 		return;
 	}
+
+	bt_mesh_prov_link.expect = PROV_PUB_KEY;
 }
 
 static void prov_dh_key_cb(const uint8_t dhkey[32])

[mynewt-nimble] 14/31: mesh: Resolve dead code in store_seg

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 26666ceebd64ed797011ca13546fbca5aad78f64
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 13:11:45 2021 +0200

    mesh: Resolve dead code in store_seg
    
    If CONFIG_BT_MESH_SEQ_STORE_RATE is 1, the check in store_seq can be
    reduced to a simple if (false), and the modulo code does not need to be
    included in the build.
    
    this is port of aef354c6bc3264de9f2a38b8c56ff5253b35912a
---
 nimble/host/mesh/src/settings.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/settings.c b/nimble/host/mesh/src/settings.c
index 1fb2b08..cb583eb 100644
--- a/nimble/host/mesh/src/settings.c
+++ b/nimble/host/mesh/src/settings.c
@@ -1189,7 +1189,7 @@ static void store_pending_seq(void)
 
 void bt_mesh_store_seq(void)
 {
-	if (CONFIG_BT_MESH_SEQ_STORE_RATE &&
+	if (CONFIG_BT_MESH_SEQ_STORE_RATE > 1 &&
 	    (bt_mesh.seq % CONFIG_BT_MESH_SEQ_STORE_RATE)) {
 		return;
 	}

[mynewt-nimble] 15/31: mesh: Explicitly ignore gatt_service_register return code

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit b2f8d90f638f095af1cd3ae5ae98a92d40263ce5
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 14:00:26 2021 +0200

    mesh: Explicitly ignore gatt_service_register return code
    
    The error code from gatt_service_register is being ignored to ensure
    that repeated actions still complete. Do this explicitly by adding
    (void) casts, resolving coverity warnings on accidental error code
    ignores.
    
    this is port of f9d41595a3a168d982e95c1f46ef9fb8b989c55b
---
 nimble/host/mesh/src/mesh.c    | 2 +-
 nimble/host/mesh/src/pb_gatt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/nimble/host/mesh/src/mesh.c b/nimble/host/mesh/src/mesh.c
index bbb4ee3..10c6fff 100644
--- a/nimble/host/mesh/src/mesh.c
+++ b/nimble/host/mesh/src/mesh.c
@@ -117,7 +117,7 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx,
 		atomic_clear_bit(bt_mesh.flags, BT_MESH_VALID);
 
 		if (MYNEWT_VAL(BLE_MESH_PB_GATT)  && pb_gatt_enabled) {
-			bt_mesh_proxy_prov_enable();
+			(void)bt_mesh_proxy_prov_enable();
 		}
 
 		return err;
diff --git a/nimble/host/mesh/src/pb_gatt.c b/nimble/host/mesh/src/pb_gatt.c
index a8f7378..bce7cf6 100644
--- a/nimble/host/mesh/src/pb_gatt.c
+++ b/nimble/host/mesh/src/pb_gatt.c
@@ -115,7 +115,7 @@ int bt_mesh_pb_gatt_close(uint16_t conn_handle)
 
 static int link_accept(const struct prov_bearer_cb *cb, void *cb_data)
 {
-	bt_mesh_proxy_prov_enable();
+	(void)bt_mesh_proxy_prov_enable();
 	bt_mesh_adv_update();
 
 	link.cb = cb;

[mynewt-nimble] 24/31: mesh: Delete duplication in config

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit fa8d955c93c4a8a14cb9ea029fa8e15ab3a0ac89
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Apr 26 09:19:40 2021 +0200

    mesh: Delete duplication in config
---
 nimble/host/mesh/syscfg.yml | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/nimble/host/mesh/syscfg.yml b/nimble/host/mesh/syscfg.yml
index 9683df4..ada5b64 100644
--- a/nimble/host/mesh/syscfg.yml
+++ b/nimble/host/mesh/syscfg.yml
@@ -428,16 +428,6 @@ syscfg.defs:
             a value of 300 means 30 seconds.
         value: 300
 
-    BLE_MESH_LPN_POLL_TIMEOUT:
-        description: >
-            PollTimeout timer is used to measure time between two
-            consecutive requests sent by the Low Power node. If no
-            requests are received by the Friend node before the
-            PollTimeout timer expires, then the friendship is considered
-            terminated. The value is in units of 100 milliseconds, so e.g.
-            a value of 300 means 30 seconds.
-        value: 300
-
     BLE_MESH_LPN_INIT_POLL_TIMEOUT:
         description: >
             The initial value of the PollTimeout timer when Friendship

[mynewt-nimble] 04/31: mesh: Check response address in Configuration Client

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 299b2ebe9ab2ac6c9cb85cffb0f10e18428212e1
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:15:23 2021 +0200

    mesh: Check response address in Configuration Client
    
    The Configuration Client doesn't check the address in a received
    response. This means that a response from any device will be accepted.
    
    This change ensures that the correct response will be accepted.
    
    this is port of 8bcc85b38cccf1f36e769e907f43137f68305aa7
---
 nimble/host/mesh/include/mesh/cfg_cli.h |  3 +-
 nimble/host/mesh/src/cfg_cli.c          | 91 ++++++++++++++++++---------------
 2 files changed, 51 insertions(+), 43 deletions(-)

diff --git a/nimble/host/mesh/include/mesh/cfg_cli.h b/nimble/host/mesh/include/mesh/cfg_cli.h
index bd2f9fe..368bdfc 100644
--- a/nimble/host/mesh/include/mesh/cfg_cli.h
+++ b/nimble/host/mesh/include/mesh/cfg_cli.h
@@ -26,8 +26,9 @@ struct bt_mesh_cfg_cli {
 	struct bt_mesh_model *model;
 
 	struct k_sem          op_sync;
-	uint32_t                 op_pending;
+	uint32_t              op_pending;
 	void                 *op_param;
+    	uint16_t              op_addr;
 };
 
 extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];
diff --git a/nimble/host/mesh/src/cfg_cli.c b/nimble/host/mesh/src/cfg_cli.c
index 104d4e6..2df7d70 100644
--- a/nimble/host/mesh/src/cfg_cli.c
+++ b/nimble/host/mesh/src/cfg_cli.c
@@ -33,6 +33,11 @@ static int32_t msg_timeout = K_SECONDS(5);
 
 static struct bt_mesh_cfg_cli *cli;
 
+static inline bool cli_response_check(uint32_t resp_opcode, uint16_t resp_addr)
+{
+	return cli->op_pending == resp_opcode && cli->op_addr == resp_addr;
+}
+
 static void comp_data_status(struct bt_mesh_model *model,
 			     struct bt_mesh_msg_ctx *ctx,
 			     struct os_mbuf *buf)
@@ -44,7 +49,7 @@ static void comp_data_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_DEV_COMP_DATA_STATUS) {
+	if (!cli_response_check(OP_DEV_COMP_DATA_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Composition Data Status");
 		return;
 	}
@@ -69,7 +74,7 @@ static void state_status_u8(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != expect_status) {
+	if (!cli_response_check(expect_status, ctx->addr)) {
 		BT_WARN("Unexpected Status (0x%08x != 0x%08x)",
 			(unsigned) cli->op_pending, (unsigned) expect_status);
 		return;
@@ -124,7 +129,7 @@ static void relay_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_RELAY_STATUS) {
+	if (!cli_response_check(OP_RELAY_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Relay Status message");
 		return;
 	}
@@ -146,7 +151,7 @@ static void net_transmit_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_NET_TRANSMIT_STATUS) {
+	if (!cli_response_check(OP_NET_TRANSMIT_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Net Transmit Status message");
 		return;
 	}
@@ -174,7 +179,7 @@ static void net_key_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_NET_KEY_STATUS) {
+	if (!cli_response_check(OP_NET_KEY_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Net Key Status message");
 		return;
 	}
@@ -211,7 +216,7 @@ static void net_key_list(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_NET_KEY_LIST) {
+	if (!cli_response_check(OP_NET_KEY_LIST, ctx->addr)) {
 		BT_WARN("Unexpected Net Key List message");
 		return;
 	}
@@ -238,7 +243,7 @@ static void node_reset_status(struct bt_mesh_model *model,
 	BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x",
 		ctx->net_idx, ctx->app_idx, ctx->addr);
 
-	if (cli->op_pending != OP_NODE_RESET_STATUS) {
+	if (!cli_response_check(OP_NODE_RESET_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Node Reset Status message");
 		return;
 	}
@@ -269,7 +274,7 @@ static void app_key_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_APP_KEY_STATUS) {
+	if (!cli_response_check(OP_APP_KEY_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected App Key Status message");
 		return;
 	}
@@ -310,7 +315,7 @@ static void app_key_list(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_APP_KEY_LIST) {
+	if (!cli_response_check(OP_APP_KEY_LIST, ctx->addr)) {
 		BT_WARN("Unexpected App Key List message");
 		return;
 	}
@@ -360,7 +365,7 @@ static void mod_app_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_MOD_APP_STATUS) {
+	if (!cli_response_check(OP_MOD_APP_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Model App Status message");
 		return;
 	}
@@ -449,7 +454,7 @@ static void mod_app_list(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_SIG_MOD_APP_LIST) {
+	if (!cli_response_check(OP_SIG_MOD_APP_LIST, ctx->addr)) {
 		BT_WARN("Unexpected Model App List message");
 		return;
 	}
@@ -465,7 +470,7 @@ static void mod_app_list_vnd(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_VND_MOD_APP_LIST) {
+	if (!cli_response_check(OP_VND_MOD_APP_LIST, ctx->addr)) {
 		BT_WARN("Unexpected Model App List Vendor message");
 		return;
 	}
@@ -493,7 +498,7 @@ static void mod_pub_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_MOD_PUB_STATUS) {
+	if (!cli_response_check(OP_MOD_PUB_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Model Pub Status message");
 		return;
 	}
@@ -569,7 +574,7 @@ static void mod_sub_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_MOD_SUB_STATUS) {
+	if (!cli_response_check(OP_MOD_SUB_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Model Subscription Status message");
 		return;
 	}
@@ -613,7 +618,7 @@ static void mod_sub_list(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_MOD_SUB_LIST) {
+	if (!cli_response_check(OP_MOD_SUB_LIST, ctx->addr)) {
 		BT_WARN("Unexpected Model Subscription List message");
 		return;
 	}
@@ -629,7 +634,7 @@ static void mod_sub_list_vnd(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_MOD_SUB_LIST_VND) {
+	if (!cli_response_check(OP_MOD_SUB_LIST_VND, ctx->addr)) {
 		BT_WARN("Unexpected Model Subscription List Vendor message");
 		return;
 	}
@@ -652,7 +657,7 @@ static void hb_sub_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_HEARTBEAT_SUB_STATUS) {
+	if (!cli_response_check(OP_HEARTBEAT_SUB_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Heartbeat Subscription Status message");
 		return;
 	}
@@ -686,7 +691,7 @@ static void hb_pub_status(struct bt_mesh_model *model,
 	       ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
 	       bt_hex(buf->om_data, buf->om_len));
 
-	if (cli->op_pending != OP_HEARTBEAT_PUB_STATUS) {
+	if (!cli_response_check(OP_HEARTBEAT_PUB_STATUS, ctx->addr)) {
 		BT_WARN("Unexpected Heartbeat Publication Status message");
 		return;
 	}
@@ -764,7 +769,7 @@ const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb = {
 	.init = cfg_cli_init,
 };
 
-static int cli_prepare(void *param, uint32_t op)
+static int cli_prepare(void *param, uint32_t op, uint16_t addr)
 {
 	if (!cli) {
 		BT_ERR("No available Configuration Client context!");
@@ -778,6 +783,7 @@ static int cli_prepare(void *param, uint32_t op)
 
 	cli->op_param = param;
 	cli->op_pending = op;
+	cli->op_addr = addr;
 
 	return 0;
 }
@@ -786,6 +792,7 @@ static void cli_reset(void)
 {
 	cli->op_pending = 0;
 	cli->op_param = NULL;
+	cli->op_addr = BT_MESH_ADDR_UNASSIGNED;
 }
 
 static int cli_wait(void)
@@ -815,7 +822,7 @@ int bt_mesh_cfg_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_DEV_COMP_DATA_STATUS);
+	err = cli_prepare(&param, OP_DEV_COMP_DATA_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -848,7 +855,7 @@ static int get_state_u8(uint16_t net_idx, uint16_t addr, uint32_t op, uint32_t r
 	};
 	int err;
 
-	err = cli_prepare(val, rsp);
+	err = cli_prepare(val, rsp, addr);
 	if (err) {
 		goto done;
 	}
@@ -880,7 +887,7 @@ static int set_state_u8(uint16_t net_idx, uint16_t addr, uint32_t op, uint32_t r
 	};
 	int err;
 
-	err = cli_prepare(val, rsp);
+	err = cli_prepare(val, rsp, addr);
 	if (err) {
 		goto done;
 	}
@@ -980,7 +987,7 @@ int bt_mesh_cfg_relay_get(uint16_t net_idx, uint16_t addr, uint8_t *status,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_RELAY_STATUS);
+	err = cli_prepare(&param, OP_RELAY_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1016,7 +1023,7 @@ int bt_mesh_cfg_relay_set(uint16_t net_idx, uint16_t addr, uint8_t new_relay,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_RELAY_STATUS);
+	err = cli_prepare(&param, OP_RELAY_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1054,7 +1061,7 @@ int bt_mesh_cfg_net_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_id
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_NET_KEY_STATUS);
+	err = cli_prepare(&param, OP_NET_KEY_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1097,7 +1104,7 @@ int bt_mesh_cfg_net_key_get(uint16_t net_idx, uint16_t addr, uint16_t *keys,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_NET_KEY_LIST);
+	err = cli_prepare(&param, OP_NET_KEY_LIST, addr);
 	if (err) {
 		return err;
 	}
@@ -1131,7 +1138,7 @@ int bt_mesh_cfg_net_key_del(uint16_t net_idx, uint16_t addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_NET_KEY_STATUS);
+	err = cli_prepare(&param, OP_NET_KEY_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1175,7 +1182,7 @@ int bt_mesh_cfg_app_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_id
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_APP_KEY_STATUS);
+	err = cli_prepare(&param, OP_APP_KEY_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1218,7 +1225,7 @@ int bt_mesh_cfg_node_reset(uint16_t net_idx, uint16_t addr, bool *status)
 		*status = false;
 	}
 
-	err = cli_prepare(status, OP_NODE_RESET_STATUS);
+	err = cli_prepare(status, OP_NODE_RESET_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1265,7 +1272,7 @@ int bt_mesh_cfg_app_key_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_id
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_APP_KEY_LIST);
+	err = cli_prepare(&param, OP_APP_KEY_LIST, addr);
 	if (err) {
 		os_mbuf_free_chain(msg);
 		return err;
@@ -1303,7 +1310,7 @@ int bt_mesh_cfg_app_key_del(uint16_t net_idx, uint16_t addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_APP_KEY_STATUS);
+	err = cli_prepare(&param, OP_APP_KEY_STATUS, addr);
 	if (err) {
 		os_mbuf_free_chain(msg);
 		return err;
@@ -1350,7 +1357,7 @@ static int mod_app_bind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_MOD_APP_STATUS);
+	err = cli_prepare(&param, OP_MOD_APP_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1422,7 +1429,7 @@ static int mod_app_unbind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_MOD_APP_STATUS);
+	err = cli_prepare(&param, OP_MOD_APP_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1501,7 +1508,7 @@ static int mod_member_list_get(uint32_t op, uint32_t expect_op, uint16_t net_idx
 	};
 	int err;
 
-	err = cli_prepare(&param, expect_op);
+	err = cli_prepare(&param, expect_op, addr);
 	if (err) {
 		goto done;
 	}
@@ -1573,7 +1580,7 @@ static int mod_sub(uint32_t op, uint16_t net_idx, uint16_t addr, uint16_t elem_a
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_MOD_SUB_STATUS);
+	err = cli_prepare(&param, OP_MOD_SUB_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1684,7 +1691,7 @@ static int mod_sub_va(uint32_t op, uint16_t net_idx, uint16_t addr, uint16_t ele
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_MOD_SUB_STATUS);
+	err = cli_prepare(&param, OP_MOD_SUB_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1825,7 +1832,7 @@ static int mod_pub_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_MOD_PUB_STATUS);
+	err = cli_prepare(&param, OP_MOD_PUB_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1897,7 +1904,7 @@ static int mod_pub_set(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_MOD_PUB_STATUS);
+	err = cli_prepare(&param, OP_MOD_PUB_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -1970,7 +1977,7 @@ int bt_mesh_cfg_hb_sub_set(uint16_t net_idx, uint16_t addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_HEARTBEAT_SUB_STATUS);
+	err = cli_prepare(&param, OP_HEARTBEAT_SUB_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -2014,7 +2021,7 @@ int bt_mesh_cfg_hb_sub_get(uint16_t net_idx, uint16_t addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_HEARTBEAT_SUB_STATUS);
+	err = cli_prepare(&param, OP_HEARTBEAT_SUB_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -2054,7 +2061,7 @@ int bt_mesh_cfg_hb_pub_set(uint16_t net_idx, uint16_t addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_HEARTBEAT_PUB_STATUS);
+	err = cli_prepare(&param, OP_HEARTBEAT_PUB_STATUS, addr);
 	if (err) {
 		goto done;
 	}
@@ -2101,7 +2108,7 @@ int bt_mesh_cfg_hb_pub_get(uint16_t net_idx, uint16_t addr,
 	};
 	int err;
 
-	err = cli_prepare(&param, OP_HEARTBEAT_PUB_STATUS);
+	err = cli_prepare(&param, OP_HEARTBEAT_PUB_STATUS, addr);
 	if (err) {
 		goto done;
 	}

[mynewt-nimble] 27/31: mesh: Sync lpn.c with Zephyr

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 8fe37356da9ab934dcf55c7759cb26e595ffefe6
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Wed May 5 12:23:20 2021 +0200

    mesh: Sync lpn.c with Zephyr
---
 nimble/host/mesh/src/lpn.c | 76 +++++++++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 42 deletions(-)

diff --git a/nimble/host/mesh/src/lpn.c b/nimble/host/mesh/src/lpn.c
index bd48c08..45c9004 100644
--- a/nimble/host/mesh/src/lpn.c
+++ b/nimble/host/mesh/src/lpn.c
@@ -148,6 +148,24 @@ static inline void group_clear(atomic_t *target, atomic_t *source)
 
 static void clear_friendship(bool force, bool disable);
 
+static int32_t poll_timeout(struct bt_mesh_lpn *lpn)
+{
+	/* If we're waiting for segment acks keep polling at high freq */
+	if (bt_mesh_tx_in_progress()) {
+		return min(POLL_TIMEOUT_MAX(lpn), K_SECONDS(1));
+	}
+
+	if (lpn->poll_timeout < POLL_TIMEOUT_MAX(lpn)) {
+		lpn->poll_timeout *= 2;
+		lpn->poll_timeout = min(lpn->poll_timeout,
+					POLL_TIMEOUT_MAX(lpn));
+	}
+
+	BT_DBG("Poll Timeout is %ums", (unsigned) lpn->poll_timeout);
+
+	return lpn->poll_timeout;
+}
+
 static void friend_clear_sent(int err, void *user_data)
 {
 	struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
@@ -211,6 +229,7 @@ static void clear_friendship(bool force, bool disable)
 
 	bt_mesh_rx_reset();
 
+	lpn_set_state(BT_MESH_LPN_DISABLED);
 	k_delayed_work_cancel(&lpn->timer);
 
 	if (lpn->clear_success) {
@@ -229,7 +248,7 @@ static void clear_friendship(bool force, bool disable)
 	lpn->recv_win = 0;
 	lpn->queue_size = 0;
 	lpn->disable = 0;
-	lpn->sent_req = 0;
+	lpn->sent_req = 0U;
 	lpn->established = 0;
 	lpn->clear_success = 0;
 	lpn->sub = NULL;
@@ -246,13 +265,12 @@ static void clear_friendship(bool force, bool disable)
 
 	bt_mesh_hb_feature_changed(BT_MESH_FEAT_LOW_POWER);
 
-	if (disable) {
+	if (!disable) {
 		lpn_set_state(BT_MESH_LPN_DISABLED);
+		k_delayed_work_submit(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT);
 		return;
 	}
 
-	lpn_set_state(BT_MESH_LPN_ENABLED);
-	k_delayed_work_submit(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT);
 }
 
 static void friend_req_sent(uint16_t duration, int err, void *user_data)
@@ -331,7 +349,7 @@ static void req_sent(uint16_t duration, int err, void *user_data)
 
 	if (err) {
 		BT_ERR("Sending request failed (err %d)", err);
-		lpn->sent_req = 0;
+		lpn->sent_req = 0U;
 		group_zero(lpn->pending);
 		return;
 	}
@@ -459,11 +477,14 @@ static void friend_response_received(struct bt_mesh_lpn *lpn)
 		lpn->fsn++;
 	}
 
-	k_delayed_work_cancel(&lpn->timer);
 	bt_mesh_scan_disable();
 	lpn_set_state(BT_MESH_LPN_ESTABLISHED);
 	lpn->req_attempts = 0;
-	lpn->sent_req = 0;
+	lpn->sent_req = 0U;
+
+	int32_t timeout = poll_timeout(lpn);
+
+	k_delayed_work_submit(&lpn->timer, K_MSEC(timeout));
 }
 
 void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx)
@@ -476,6 +497,10 @@ void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx)
 		return;
 	}
 
+	if (lpn->state != BT_MESH_LPN_WAIT_UPDATE) {
+		return;
+	}
+
 	if (lpn->sent_req != TRANS_CTL_OP_FRIEND_POLL) {
 		BT_WARN("Unexpected message withouth a preceding Poll");
 		return;
@@ -545,7 +570,6 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx,
 		}
 	}
 	/* TODO: Add offer acceptance criteria check */
-	k_delayed_work_cancel(&lpn->timer);
 
 	lpn->recv_win = msg->recv_win;
 	lpn->queue_size = msg->queue_size;
@@ -738,7 +762,7 @@ static void update_timeout(struct bt_mesh_lpn *lpn)
 
 		if (lpn->req_attempts < REQ_ATTEMPTS(lpn)) {
 			BT_WARN("Retrying first Friend Poll");
-			lpn->sent_req = 0;
+			lpn->sent_req = 0U;
 			if (send_friend_poll() == 0) {
 				return;
 			}
@@ -793,7 +817,7 @@ static void lpn_timeout(struct ble_npl_event *work)
 		if (lpn->req_attempts < REQ_ATTEMPTS(lpn)) {
 			uint8_t req = lpn->sent_req;
 
-			lpn->sent_req = 0;
+			lpn->sent_req = 0U;
 
 			if (!req || req == TRANS_CTL_OP_FRIEND_POLL) {
 				send_friend_poll();
@@ -856,24 +880,6 @@ void bt_mesh_lpn_group_del(uint16_t *groups, size_t group_count)
 	sub_update(TRANS_CTL_OP_FRIEND_SUB_REM);
 }
 
-static int32_t poll_timeout(struct bt_mesh_lpn *lpn)
-{
-	/* If we're waiting for segment acks keep polling at high freq */
-	if (bt_mesh_tx_in_progress()) {
-		return min(POLL_TIMEOUT_MAX(lpn), K_SECONDS(1));
-	}
-
-	if (lpn->poll_timeout < POLL_TIMEOUT_MAX(lpn)) {
-		lpn->poll_timeout *= 2;
-		lpn->poll_timeout = min(lpn->poll_timeout,
-					POLL_TIMEOUT_MAX(lpn));
-	}
-
-	BT_DBG("Poll Timeout is %ums", (unsigned) lpn->poll_timeout);
-
-	return lpn->poll_timeout;
-}
-
 int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx,
 			       struct os_mbuf *buf)
 {
@@ -932,12 +938,6 @@ int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx,
 		send_friend_poll();
 	}
 
-	if (!lpn->sent_req) {
-		int32_t timeout = poll_timeout(lpn);
-
-		k_delayed_work_submit(&lpn->timer, K_MSEC(timeout));
-	}
-
 	return 0;
 }
 
@@ -1020,12 +1020,6 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
 		send_friend_poll();
 	}
 
-	if (!lpn->sent_req) {
-		int32_t timeout = poll_timeout(lpn);
-
-		k_delayed_work_submit(&lpn->timer, K_MSEC(timeout));
-	}
-
 	return 0;
 }
 
@@ -1073,8 +1067,6 @@ int bt_mesh_lpn_init(void)
 
 	BT_DBG("");
 
-	lpn->groups_changed = 0;
-
 	k_delayed_work_init(&lpn->timer, lpn_timeout);
 
 	if (lpn->state == BT_MESH_LPN_ENABLED) {

[mynewt-nimble] 21/31: bttester: Set Company ID to Intel Corp.

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 01879ef557be49f966a7ab7393169e0b5f841bb1
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Tue Apr 20 10:52:17 2021 +0200

    bttester: Set Company ID to Intel Corp.
    
    Tests require CID to have valid value, listed in BT SIG
    Assigned Numbers/Company Identifiers. Let's set it to
    Intel Corp. (0x0002)
    
    This affects MESH/NODE/CFG/CFGF/BV-01-C
---
 apps/bttester/src/mesh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/bttester/src/mesh.c b/apps/bttester/src/mesh.c
index 8226fe9..1ad322f 100644
--- a/apps/bttester/src/mesh.c
+++ b/apps/bttester/src/mesh.c
@@ -41,7 +41,7 @@
 extern uint8_t own_addr_type;
 
 #define CONTROLLER_INDEX 0
-#define CID_LOCAL 0xffff
+#define CID_LOCAL 0x0002
 
 /* Health server data */
 #define CUR_FAULTS_MAX 4

[mynewt-nimble] 30/31: bttester: Allow for more retransmit attempts in mesh

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 5ea192af0108f72ab7f5ef0223e12f17c83e6841
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Thu May 6 13:59:41 2021 +0200

    bttester: Allow for more retransmit attempts in mesh
    
    This improves stability of transport tests
---
 apps/bttester/syscfg.yml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/apps/bttester/syscfg.yml b/apps/bttester/syscfg.yml
index db869c3..7f99ded 100644
--- a/apps/bttester/syscfg.yml
+++ b/apps/bttester/syscfg.yml
@@ -80,7 +80,7 @@ syscfg.vals:
     SHELL_TASK: 0
     SHELL_NEWTMGR: 0
     LOG_LEVEL: 12
-    MSYS_1_BLOCK_COUNT: 80
+    MSYS_1_BLOCK_COUNT: 100
 
     BLE_MONITOR_RTT: 1
     CONSOLE_RTT: 0
@@ -127,7 +127,8 @@ syscfg.vals:
     BLE_MESH_CFG_CLI: 1
     BLE_MESH_RX_SDU_MAX: 110
     BLE_MESH_HEALTH_CLI: 1
-    BLE_MESH_FRIEND_QUEUE_SIZE: 32
+    BLE_MESH_FRIEND_QUEUE_SIZE: 16
+    BLE_MESH_SEG_RETRANSMIT_ATTEMPTS: 6
     BLE_MESH_RX_SEG_MAX: 13
     BLE_MESH_TX_SEG_MSG_COUNT: 2
     BLE_MAX_CONNECTIONS: 8

[mynewt-nimble] 16/31: mesh: Remove unsigned typing to returns in heartbeat

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 5f60008a2b6d631410062ee6f3d1aca12a742256
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 14:01:21 2021 +0200

    mesh: Remove unsigned typing to returns in heartbeat
    
    Removes U-suffix from signed return codes in heartbeat.c.
    
    this is port of dc6e880eab8526bd6ba9ab8bca3f6e2a299ff98e
---
 nimble/host/mesh/src/heartbeat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/heartbeat.c b/nimble/host/mesh/src/heartbeat.c
index 3ba7ae3..09d6459 100644
--- a/nimble/host/mesh/src/heartbeat.c
+++ b/nimble/host/mesh/src/heartbeat.c
@@ -91,7 +91,7 @@ static int heartbeat_send(const struct bt_mesh_send_cb *cb, void *cb_data)
 	 * removed.
 	 */
 	if (!tx.sub || pub.dst == BT_MESH_ADDR_UNASSIGNED) {
-		return 0U;
+		return 0;
 	}
 
 	hb.init_ttl = pub.ttl;

[mynewt-nimble] 23/31: mesh: Fix condition is net_tx_cred_get

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 7a5f6ec320eacc3b9bc35820bf88194243ea1078
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Apr 26 09:15:56 2021 +0200

    mesh: Fix condition is net_tx_cred_get
    
    Preprocessor directives using defined() in mesh should use
    identifiers defined in glue.h
---
 nimble/host/mesh/src/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nimble/host/mesh/src/net.c b/nimble/host/mesh/src/net.c
index 2e1d6dc..db97b95 100644
--- a/nimble/host/mesh/src/net.c
+++ b/nimble/host/mesh/src/net.c
@@ -344,7 +344,7 @@ static void bt_mesh_net_local(struct ble_npl_event *work)
 
 static const struct bt_mesh_net_cred *net_tx_cred_get(struct bt_mesh_net_tx *tx)
 {
-#if defined(BLE_MESH_LOW_POWER)
+#if defined(CONFIG_BT_MESH_LOW_POWER)
 	if (tx->friend_cred && bt_mesh_lpn_established()) {
 		return &bt_mesh.lpn.cred[SUBNET_KEY_TX_IDX(tx->sub)];
 	}

[mynewt-nimble] 12/31: mesh: Check subnet existence in heartbeat_send

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit fa8ca30b87fce7af909d464cef9b9b3383626ea2
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 13:04:55 2021 +0200

    mesh: Check subnet existence in heartbeat_send
    
    Check that the assigned subnet hasn't been removed in heartbeat_send to
    avoid potential NULL defererence in transport's ctl_send.
    
    this is port of 8309353b7f556d7457f75b2777a2561a31a85a78
---
 nimble/host/mesh/src/heartbeat.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/nimble/host/mesh/src/heartbeat.c b/nimble/host/mesh/src/heartbeat.c
index f990dc0..3ba7ae3 100644
--- a/nimble/host/mesh/src/heartbeat.c
+++ b/nimble/host/mesh/src/heartbeat.c
@@ -87,8 +87,10 @@ static int heartbeat_send(const struct bt_mesh_send_cb *cb, void *cb_data)
 		.xmit = bt_mesh_net_transmit_get(),
 	};
 
-	/* Do nothing if heartbeat publication is not enabled */
-	if (pub.dst == BT_MESH_ADDR_UNASSIGNED) {
+	/* Do nothing if heartbeat publication is not enabled or the subnet is
+	 * removed.
+	 */
+	if (!tx.sub || pub.dst == BT_MESH_ADDR_UNASSIGNED) {
 		return 0U;
 	}