Merge branch 'bugfix/friend_and_lpn_issues' into 'master'

ble_mesh: stack: Fix friend and lpn issues

See merge request espressif/esp-idf!19378
This commit is contained in:
Island 2022-08-09 14:39:58 +08:00
commit ee10f25b89
4 changed files with 25 additions and 15 deletions

View File

@ -64,6 +64,7 @@ enum {
};
static void (*friend_cb)(bool establish, uint16_t lpn_addr, uint8_t reason);
static void enqueue_update(struct bt_mesh_friend *frnd, uint8_t md);
static bool friend_init = false;
@ -233,7 +234,23 @@ void bt_mesh_friend_sec_update(uint16_t net_idx)
}
if (net_idx == BLE_MESH_KEY_ANY || frnd->net_idx == net_idx) {
frnd->sec_update = 1U;
/* For case MESH/NODE/FRND/FN/BV-20-C.
* A situation is:
* The friend node may receive more than one different secure updates
* consecutively. And using the previous approach will cause only the
* latest Friend Update message been enqueued.
* So we update the implementation here to enqueue the Friend Update
* message immediately once a different secure beacon is received.
*
* A disadvantage of the change is:
* A friend node may receive different secure beacons. Then the
* beacon_cache mechanism will not work. This will cause the friend
* message queue been full of these secure beacons. So before enqueuing
* the secure updates, we should check if the currently received one
* is already exists in the message queue. Or enhance the beacon cache
* filtering mechanism.
*/
enqueue_update(frnd, 1);
}
}
}
@ -699,7 +716,6 @@ static void enqueue_update(struct bt_mesh_friend *frnd, uint8_t md)
return;
}
frnd->sec_update = 0U;
enqueue_buf(frnd, buf);
}
@ -1116,10 +1132,6 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
BT_DBG("type %u", type);
if (type == BLE_MESH_FRIEND_PDU_SINGLE) {
if (frnd->sec_update) {
enqueue_update(frnd, 1);
}
enqueue_buf(frnd, buf);
return;
}
@ -1136,10 +1148,6 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
net_buf_slist_put(&seg->queue, buf);
if (type == BLE_MESH_FRIEND_PDU_COMPLETE) {
if (frnd->sec_update) {
enqueue_update(frnd, 1);
}
sys_slist_merge_slist(&frnd->queue, &seg->queue);
frnd->queue_size += seg->seg_count;

View File

@ -20,7 +20,7 @@ extern "C" {
#define BLE_MESH_KEY_ANY 0xffff
#define BLE_MESH_ADDR_IS_UNICAST(addr) ((addr) && (addr) < 0x8000)
#define BLE_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) <= 0xff00)
#define BLE_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) < 0xff00)
#define BLE_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000)
#define BLE_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb)

View File

@ -1188,7 +1188,8 @@ static bool relay_to_adv(enum bt_mesh_net_if net_if)
case BLE_MESH_NET_IF_LOCAL:
return true;
case BLE_MESH_NET_IF_ADV:
return (bt_mesh_relay_get() == BLE_MESH_RELAY_ENABLED);
return ((bt_mesh_relay_get() == BLE_MESH_RELAY_ENABLED) ||
(bt_mesh_friend_get() == BLE_MESH_FRIEND_ENABLED));
case BLE_MESH_NET_IF_PROXY:
return (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED);
default:
@ -1221,7 +1222,8 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
if (rx->net_if == BLE_MESH_NET_IF_ADV &&
bt_mesh_relay_get() != BLE_MESH_RELAY_ENABLED &&
bt_mesh_gatt_proxy_get() != BLE_MESH_GATT_PROXY_ENABLED) {
bt_mesh_gatt_proxy_get() != BLE_MESH_GATT_PROXY_ENABLED &&
bt_mesh_friend_get() != BLE_MESH_FRIEND_ENABLED) {
return;
}
@ -1378,8 +1380,9 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
return -EBADMSG;
}
/* For case MESH/NODE/RLY/BV-01-C, even the DST is RFU, it needs to be forwarded. */
if (BLE_MESH_ADDR_IS_RFU(rx->ctx.recv_dst)) {
BT_ERR("Destination address is RFU; dropping packet");
BT_ERR("Destination address is RFU; dropping packet 0x%02x", rx->ctx.recv_dst);
return -EBADMSG;
}

View File

@ -95,7 +95,6 @@ struct bt_mesh_friend {
uint8_t fsn:1,
send_last:1,
pending_req:1,
sec_update:1,
pending_buf:1,
valid:1,
established:1;