Bluetooth: Mesh: Cfg: Implement Low Power Node PollTimeout Get fully
Now that Friend support is complete we can create a full implementation of the LPN PollTimeout Get message. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
6abfab08d4
commit
95d34e0583
3 changed files with 35 additions and 12 deletions
|
@ -2503,7 +2503,9 @@ static void lpn_timeout_get(struct bt_mesh_model *model,
|
|||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 5 + 4);
|
||||
struct bt_mesh_friend *frnd;
|
||||
u16_t lpn_addr;
|
||||
s32_t timeout;
|
||||
|
||||
lpn_addr = net_buf_simple_pull_le16(buf);
|
||||
|
||||
|
@ -2517,7 +2519,24 @@ static void lpn_timeout_get(struct bt_mesh_model *model,
|
|||
|
||||
bt_mesh_model_msg_init(msg, OP_LPN_TIMEOUT_STATUS);
|
||||
net_buf_simple_add_le16(msg, lpn_addr);
|
||||
memset(net_buf_simple_add(msg, 3), 0, 3);
|
||||
|
||||
if (!IS_ENABLED(CONFIG_BLUETOOTH_MESH_FRIEND)) {
|
||||
timeout = 0;
|
||||
goto send_rsp;
|
||||
}
|
||||
|
||||
frnd = bt_mesh_friend_find(BT_MESH_KEY_ANY, lpn_addr, true);
|
||||
if (!frnd) {
|
||||
timeout = 0;
|
||||
goto send_rsp;
|
||||
}
|
||||
|
||||
timeout = k_delayed_work_remaining_get(&frnd->timer) / 100;
|
||||
|
||||
send_rsp:
|
||||
net_buf_simple_add_u8(msg, timeout);
|
||||
net_buf_simple_add_u8(msg, timeout >> 8);
|
||||
net_buf_simple_add_u8(msg, timeout >> 16);
|
||||
|
||||
if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
|
||||
BT_ERR("Unable to send LPN PollTimeout Status");
|
||||
|
|
|
@ -94,12 +94,12 @@ static struct net_buf *friend_buf_alloc(u16_t src)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static struct bt_mesh_friend *friend_lpn_find(u16_t net_idx, u16_t addr,
|
||||
bool established)
|
||||
struct bt_mesh_friend *bt_mesh_friend_find(u16_t net_idx, u16_t lpn_addr,
|
||||
bool established)
|
||||
{
|
||||
int i;
|
||||
|
||||
BT_DBG("net_idx 0x%04x addr 0x%04x", net_idx, addr);
|
||||
BT_DBG("net_idx 0x%04x lpn_addr 0x%04x", net_idx, lpn_addr);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
|
||||
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
|
||||
|
@ -108,11 +108,11 @@ static struct bt_mesh_friend *friend_lpn_find(u16_t net_idx, u16_t addr,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (frnd->net_idx != net_idx) {
|
||||
if (net_idx != BT_MESH_KEY_ANY && frnd->net_idx != net_idx) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (frnd->lpn == addr) {
|
||||
if (frnd->lpn == lpn_addr) {
|
||||
return frnd;
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
|||
|
||||
BT_DBG("LPN addr 0x%04x counter 0x%04x", lpn_addr, lpn_counter);
|
||||
|
||||
frnd = friend_lpn_find(rx->sub->net_idx, lpn_addr, true);
|
||||
frnd = bt_mesh_friend_find(rx->sub->net_idx, lpn_addr, true);
|
||||
if (!frnd) {
|
||||
BT_WARN("No matching LPN addr 0x%04x", lpn_addr);
|
||||
return 0;
|
||||
|
@ -415,7 +415,7 @@ int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
frnd = friend_lpn_find(rx->sub->net_idx, rx->ctx.addr, true);
|
||||
frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true);
|
||||
if (!frnd) {
|
||||
BT_WARN("No matching LPN addr 0x%04x", rx->ctx.addr);
|
||||
return 0;
|
||||
|
@ -452,7 +452,7 @@ int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
frnd = friend_lpn_find(rx->sub->net_idx, rx->ctx.addr, true);
|
||||
frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true);
|
||||
if (!frnd) {
|
||||
BT_WARN("No matching LPN addr 0x%04x", rx->ctx.addr);
|
||||
return 0;
|
||||
|
@ -508,7 +508,7 @@ int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
frnd = friend_lpn_find(rx->sub->net_idx, rx->ctx.addr, false);
|
||||
frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, false);
|
||||
if (!frnd) {
|
||||
BT_WARN("No matching LPN addr 0x%04x", rx->ctx.addr);
|
||||
return 0;
|
||||
|
@ -664,9 +664,10 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
|||
|
||||
old_friend = sys_be16_to_cpu(msg->prev_addr);
|
||||
if (BT_MESH_ADDR_IS_UNICAST(old_friend)) {
|
||||
frnd = friend_lpn_find(rx->sub->net_idx, old_friend, true);
|
||||
frnd = bt_mesh_friend_find(rx->sub->net_idx, old_friend, true);
|
||||
} else {
|
||||
frnd = friend_lpn_find(rx->sub->net_idx, rx->ctx.addr, true);
|
||||
frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr,
|
||||
true);
|
||||
}
|
||||
|
||||
if (frnd) {
|
||||
|
|
|
@ -14,6 +14,9 @@ enum bt_mesh_friend_pdu_type {
|
|||
|
||||
bool bt_mesh_friend_match(u16_t net_idx, u16_t addr);
|
||||
|
||||
struct bt_mesh_friend *bt_mesh_friend_find(u16_t net_idx, u16_t addr,
|
||||
bool established);
|
||||
|
||||
void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx,
|
||||
enum bt_mesh_friend_pdu_type type,
|
||||
u64_t *seq_auth, struct net_buf_simple *sbuf);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue