mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-15 21:50:03 +00:00
mesh/friend.c - Fixes Friend Add Another Update
According MESH/NODE/FRND/FN/BV-20-C should add another Friend Update. This is port of Zephyr patch: commit 355bdf5cd95d9f8bf11fc0f00fb1bcb151ff5cab
This commit is contained in:
committed by
Michał Narajowski
parent
9eb75fb762
commit
d665f41935
@@ -191,6 +191,8 @@ void bt_mesh_friend_clear_net_idx(u16_t net_idx)
|
||||
}
|
||||
}
|
||||
|
||||
static void enqueue_update(struct bt_mesh_friend *frnd, u8_t md);
|
||||
|
||||
void bt_mesh_friend_sec_update(u16_t net_idx)
|
||||
{
|
||||
int i;
|
||||
@@ -205,7 +207,7 @@ void bt_mesh_friend_sec_update(u16_t net_idx)
|
||||
}
|
||||
|
||||
if (net_idx == BT_MESH_KEY_ANY || frnd->net_idx == net_idx) {
|
||||
frnd->sec_update = 1;
|
||||
enqueue_update(frnd, 0x00);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,7 +678,6 @@ static void enqueue_update(struct bt_mesh_friend *frnd, u8_t md)
|
||||
return;
|
||||
}
|
||||
|
||||
frnd->sec_update = 0;
|
||||
enqueue_buf(frnd, buf);
|
||||
}
|
||||
|
||||
@@ -1088,10 +1089,6 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
|
||||
BT_DBG("type %u", type);
|
||||
|
||||
if (type == BT_MESH_FRIEND_PDU_SINGLE) {
|
||||
if (frnd->sec_update) {
|
||||
enqueue_update(frnd, 1);
|
||||
}
|
||||
|
||||
enqueue_buf(frnd, buf);
|
||||
return;
|
||||
}
|
||||
@@ -1108,10 +1105,6 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
|
||||
net_buf_slist_put(&seg->queue, buf);
|
||||
|
||||
if (type == BT_MESH_FRIEND_PDU_COMPLETE) {
|
||||
if (frnd->sec_update) {
|
||||
enqueue_update(frnd, 1);
|
||||
}
|
||||
|
||||
net_buf_slist_merge_slist(&frnd->queue, &seg->queue);
|
||||
|
||||
frnd->queue_size += seg->seg_count;
|
||||
@@ -1159,6 +1152,38 @@ static void buf_send_end(int err, void *user_data)
|
||||
}
|
||||
}
|
||||
|
||||
static void update_overwrite(struct os_mbuf *buf, u8_t md)
|
||||
{
|
||||
struct net_buf_simple_state state;
|
||||
struct bt_mesh_ctl_friend_update *upd;
|
||||
|
||||
if (buf->om_len != 16) {
|
||||
return;
|
||||
}
|
||||
|
||||
net_buf_simple_save(buf, &state);
|
||||
|
||||
net_buf_skip(buf, 1); /* skip IVI, NID */
|
||||
|
||||
if (!(net_buf_pull_u8(buf) >> 7)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
net_buf_skip(buf, 7); /* skip seqnum src dec*/
|
||||
|
||||
if (TRANS_CTL_OP((u8_t *) net_buf_pull_mem(buf, 1))
|
||||
!= TRANS_CTL_OP_FRIEND_UPDATE) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
upd = net_buf_pull_mem(buf, sizeof(*upd));
|
||||
BT_DBG("Update Previous Friend Update MD 0x%02x -> 0x%02x", upd->md, md);
|
||||
upd->md = md;
|
||||
|
||||
end:
|
||||
net_buf_simple_restore(buf, &state);
|
||||
}
|
||||
|
||||
static void friend_timeout(struct ble_npl_event *work)
|
||||
{
|
||||
struct bt_mesh_friend *frnd = ble_npl_event_get_arg(work);
|
||||
@@ -1167,6 +1192,8 @@ static void friend_timeout(struct ble_npl_event *work)
|
||||
.end = buf_send_end,
|
||||
};
|
||||
|
||||
u8_t md;
|
||||
|
||||
__ASSERT_NO_MSG(frnd->pending_buf == 0);
|
||||
|
||||
BT_DBG("lpn 0x%04x send_last %u last %p", frnd->lpn,
|
||||
@@ -1192,6 +1219,10 @@ static void friend_timeout(struct ble_npl_event *work)
|
||||
return;
|
||||
}
|
||||
|
||||
md = (u8_t)(net_buf_slist_peek_head(&frnd->queue) != NULL);
|
||||
|
||||
update_overwrite(frnd->last, md);
|
||||
|
||||
if (encrypt_friend_pdu(frnd, frnd->last, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,6 @@ struct bt_mesh_friend {
|
||||
u8_t fsn:1,
|
||||
send_last:1,
|
||||
pending_req:1,
|
||||
sec_update:1,
|
||||
pending_buf:1,
|
||||
valid:1,
|
||||
established:1;
|
||||
|
||||
Reference in New Issue
Block a user