Merge branch 'bugfix/ble_mesh_proxy_cfg_replay_v3.3' into 'release/v3.3'

Bugfix/ble mesh proxy cfg replay (v3.3)

See merge request espressif/esp-idf!10821
This commit is contained in:
Island 2020-10-13 17:24:11 +08:00
commit 7d8d841659
6 changed files with 49 additions and 6 deletions

View file

@ -2912,17 +2912,25 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
phase == BLE_MESH_KR_PHASE_2) {
sub->kr_phase = BLE_MESH_KR_PHASE_2;
sub->kr_flag = 1;
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
BT_DBG("Storing kr phase persistently");
bt_mesh_store_subnet(sub);
}
bt_mesh_net_beacon_update(sub);
} else if ((sub->kr_phase == BLE_MESH_KR_PHASE_1 ||
sub->kr_phase == BLE_MESH_KR_PHASE_2) &&
phase == BLE_MESH_KR_PHASE_3) {
sub->kr_phase = BLE_MESH_KR_NORMAL;
sub->kr_flag = 0;
bt_mesh_net_revoke_keys(sub);
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) ||
IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
friend_cred_refresh(ctx->net_idx);
}
sub->kr_phase = BLE_MESH_KR_NORMAL;
sub->kr_flag = 0;
bt_mesh_net_beacon_update(sub);
}

View file

@ -501,6 +501,7 @@ void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub)
BT_DBG("idx 0x%04x", sub->net_idx);
memcpy(&sub->keys[0], &sub->keys[1], sizeof(sub->keys[0]));
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
BT_DBG("Store updated NetKey persistently");
bt_mesh_store_subnet(sub);
@ -515,6 +516,7 @@ void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub)
memcpy(&key->keys[0], &key->keys[1], sizeof(key->keys[0]));
key->updated = false;
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
BT_DBG("Store updated AppKey persistently");
bt_mesh_store_app_key(key);
@ -535,6 +537,12 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key)
if (sub->kr_phase == BLE_MESH_KR_PHASE_1) {
BT_INFO("Phase 1 -> Phase 2");
sub->kr_phase = BLE_MESH_KR_PHASE_2;
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
BT_DBG("Storing kr phase persistently");
bt_mesh_store_subnet(sub);
}
return true;
}
} else {
@ -553,12 +561,15 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key)
*/
case BLE_MESH_KR_PHASE_2:
BT_INFO("KR Phase 0x%02x -> Normal", sub->kr_phase);
sub->kr_phase = BLE_MESH_KR_NORMAL;
bt_mesh_net_revoke_keys(sub);
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) ||
IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
friend_cred_refresh(sub->net_idx);
}
sub->kr_phase = BLE_MESH_KR_NORMAL;
return true;
}
}
@ -582,6 +593,10 @@ void bt_mesh_rpl_reset(void)
} else {
rpl->old_iv = true;
}
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_store_rpl(rpl);
}
}
}
}

View file

@ -18,6 +18,7 @@
#include "mesh.h"
#include "access.h"
#include "beacon.h"
#include "transport.h"
#include "mesh_common.h"
#include "foundation.h"
#include "proxy_client.h"
@ -171,6 +172,14 @@ static void proxy_cfg(struct bt_mesh_proxy_server *server)
return;
}
rx.local_match = 1U;
if (bt_mesh_rpl_check(&rx, NULL)) {
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
rx.ctx.addr, rx.ctx.recv_dst, rx.seq);
return;
}
/* Remove network headers */
net_buf_simple_pull(&buf, BLE_MESH_NET_HDR_LEN);

View file

@ -16,6 +16,7 @@
#include "prov.h"
#include "beacon.h"
#include "access.h"
#include "transport.h"
#include "foundation.h"
#include "proxy_server.h"
@ -308,6 +309,14 @@ static void proxy_cfg(struct bt_mesh_proxy_client *client)
return;
}
rx.local_match = 1U;
if (bt_mesh_rpl_check(&rx, NULL)) {
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
rx.ctx.addr, rx.ctx.recv_dst, rx.seq);
return;
}
/* Remove network headers */
net_buf_simple_pull(&buf, BLE_MESH_NET_HDR_LEN);

View file

@ -665,7 +665,7 @@ static void update_rpl(struct bt_mesh_rpl *rpl, struct bt_mesh_net_rx *rx)
* updated (needed for segmented messages), whereas if a NULL match is given
* the RPL is immediately updated (used for unsegmented messages).
*/
static bool is_replay(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match)
bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match)
{
int i;
@ -1058,7 +1058,7 @@ static int trans_unseg(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx,
return -EINVAL;
}
if (is_replay(rx, NULL)) {
if (bt_mesh_rpl_check(rx, NULL)) {
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
rx->ctx.addr, rx->ctx.recv_dst, rx->seq);
return -EINVAL;
@ -1486,7 +1486,7 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
return -EINVAL;
}
if (is_replay(net_rx, &rpl)) {
if (bt_mesh_rpl_check(net_rx, &rpl)) {
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
net_rx->ctx.addr, net_rx->ctx.recv_dst, net_rx->seq);
return -EINVAL;

View file

@ -114,6 +114,8 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx);
void bt_mesh_trans_init(void);
void bt_mesh_trans_deinit(bool erase);
bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match);
void bt_mesh_heartbeat_send(void);
int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx,