Skip to content

Commit 6e260af

Browse files
LingaoMjhedberg
authored andcommitted
Bluetooth: Mesh: Fixes Friend Add Another Update
Fixes: #20746 According MESH/NODE/FRND/FN/BV-20-C should add another Friend Update. Signed-off-by: Lingao Meng <[email protected]>
1 parent 6ade720 commit 6e260af

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

subsys/bluetooth/mesh/friend.c

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ void bt_mesh_friend_clear_net_idx(u16_t net_idx)
190190
}
191191
}
192192

193+
static void enqueue_update(struct bt_mesh_friend *frnd, u8_t md);
194+
193195
void bt_mesh_friend_sec_update(u16_t net_idx)
194196
{
195197
int i;
@@ -204,7 +206,7 @@ void bt_mesh_friend_sec_update(u16_t net_idx)
204206
}
205207

206208
if (net_idx == BT_MESH_KEY_ANY || frnd->net_idx == net_idx) {
207-
frnd->sec_update = 1U;
209+
enqueue_update(frnd, 0x00);
208210
}
209211
}
210212
}
@@ -653,7 +655,6 @@ static void enqueue_update(struct bt_mesh_friend *frnd, u8_t md)
653655
return;
654656
}
655657

656-
frnd->sec_update = 0U;
657658
enqueue_buf(frnd, buf);
658659
}
659660

@@ -1057,10 +1058,6 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
10571058
BT_DBG("type %u", type);
10581059

10591060
if (type == BT_MESH_FRIEND_PDU_SINGLE) {
1060-
if (frnd->sec_update) {
1061-
enqueue_update(frnd, 1);
1062-
}
1063-
10641061
enqueue_buf(frnd, buf);
10651062
return;
10661063
}
@@ -1077,10 +1074,6 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
10771074
net_buf_slist_put(&seg->queue, buf);
10781075

10791076
if (type == BT_MESH_FRIEND_PDU_COMPLETE) {
1080-
if (frnd->sec_update) {
1081-
enqueue_update(frnd, 1);
1082-
}
1083-
10841077
sys_slist_merge_slist(&frnd->queue, &seg->queue);
10851078

10861079
frnd->queue_size += seg->seg_count;
@@ -1127,6 +1120,38 @@ static void buf_send_end(int err, void *user_data)
11271120
}
11281121
}
11291122

1123+
static void update_overwrite(struct net_buf *buf, u8_t md)
1124+
{
1125+
struct net_buf_simple_state state;
1126+
struct bt_mesh_ctl_friend_update *upd;
1127+
1128+
if (buf->len != 16) {
1129+
return;
1130+
}
1131+
1132+
net_buf_simple_save(&buf->b, &state);
1133+
1134+
net_buf_skip(buf, 1); /* skip IVI, NID */
1135+
1136+
if (!(net_buf_pull_u8(buf) >> 7)) {
1137+
goto end;
1138+
}
1139+
1140+
net_buf_skip(buf, 7); /* skip seqnum src dec*/
1141+
1142+
if (TRANS_CTL_OP((u8_t *) net_buf_pull_mem(buf, 1))
1143+
!= TRANS_CTL_OP_FRIEND_UPDATE) {
1144+
goto end;
1145+
}
1146+
1147+
upd = net_buf_pull_mem(buf, sizeof(*upd));
1148+
BT_DBG("Update Previous Friend Update MD 0x%02x -> 0x%02x", upd->md, md);
1149+
upd->md = md;
1150+
1151+
end:
1152+
net_buf_simple_restore(&buf->b, &state);
1153+
}
1154+
11301155
static void friend_timeout(struct k_work *work)
11311156
{
11321157
struct bt_mesh_friend *frnd = CONTAINER_OF(work, struct bt_mesh_friend,
@@ -1136,6 +1161,8 @@ static void friend_timeout(struct k_work *work)
11361161
.end = buf_send_end,
11371162
};
11381163

1164+
u8_t md;
1165+
11391166
__ASSERT_NO_MSG(frnd->pending_buf == 0U);
11401167

11411168
BT_DBG("lpn 0x%04x send_last %u last %p", frnd->lpn,
@@ -1161,6 +1188,10 @@ static void friend_timeout(struct k_work *work)
11611188
return;
11621189
}
11631190

1191+
md = (u8_t)(sys_slist_peek_head(&frnd->queue) != NULL);
1192+
1193+
update_overwrite(frnd->last, md);
1194+
11641195
if (encrypt_friend_pdu(frnd, frnd->last, false)) {
11651196
return;
11661197
}

subsys/bluetooth/mesh/net.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ struct bt_mesh_friend {
9797
u8_t fsn:1,
9898
send_last:1,
9999
pending_req:1,
100-
sec_update:1,
101100
pending_buf:1,
102101
valid:1,
103102
established:1;

0 commit comments

Comments
 (0)