Bluetooth: Mesh: Keep received buffer intact until transport layer
The lower transport layer is responsible e.g. for the Friend Queue, so we need to have the buffer in its original parsing state there. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
fafff0fa78
commit
799ee46b5c
4 changed files with 23 additions and 23 deletions
|
@ -49,6 +49,10 @@
|
|||
#define NID(pdu) ((pdu)[0] & 0x7f)
|
||||
#define CTL(pdu) ((pdu)[1] >> 7)
|
||||
#define TTL(pdu) ((pdu)[1] & 0x7f)
|
||||
#define SEQ(pdu) (((u32_t)(pdu)[2] << 16) | \
|
||||
((u32_t)(pdu)[3] << 8) | (u32_t)(pdu)[4]);
|
||||
#define SRC(pdu) (sys_get_be16(&(pdu)[5]))
|
||||
#define DST(pdu) (sys_get_be16(&(pdu)[7]))
|
||||
|
||||
/* Determine how many friendship credentials we need */
|
||||
#if defined(CONFIG_BT_MESH_FRIEND)
|
||||
|
@ -136,13 +140,6 @@ static bool msg_cache_match(struct bt_mesh_net_rx *rx,
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline u32_t net_seq(struct net_buf_simple *buf)
|
||||
{
|
||||
return ((net_buf_simple_pull_u8(buf) << 16) & 0xff0000) |
|
||||
((net_buf_simple_pull_u8(buf) << 8) & 0xff00) |
|
||||
net_buf_simple_pull_u8(buf);
|
||||
}
|
||||
|
||||
struct bt_mesh_subnet *bt_mesh_subnet_get(u16_t net_idx)
|
||||
{
|
||||
int i;
|
||||
|
@ -931,7 +928,7 @@ static int net_decrypt(struct bt_mesh_subnet *sub, u8_t idx, const u8_t *data,
|
|||
return -EALREADY;
|
||||
}
|
||||
|
||||
rx->ctx.addr = sys_get_be16(&buf->data[5]);
|
||||
rx->ctx.addr = SRC(buf->data);
|
||||
if (!BT_MESH_ADDR_IS_UNICAST(rx->ctx.addr)) {
|
||||
BT_WARN("Ignoring non-unicast src addr 0x%04x", rx->ctx.addr);
|
||||
return -EINVAL;
|
||||
|
@ -1092,8 +1089,7 @@ done:
|
|||
}
|
||||
|
||||
int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
|
||||
struct bt_mesh_net_rx *rx, struct net_buf_simple *buf,
|
||||
struct net_buf_simple_state *state)
|
||||
struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||
{
|
||||
if (data->len < 18) {
|
||||
BT_WARN("Dropping too short mesh packet (len %u)", data->len);
|
||||
|
@ -1117,11 +1113,6 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
|
|||
/* Initialize AppIdx to a sane value */
|
||||
rx->ctx.app_idx = BT_MESH_KEY_UNUSED;
|
||||
|
||||
/* Save parsing state so the buffer can later be relayed */
|
||||
if (state) {
|
||||
net_buf_simple_save(buf, state);
|
||||
}
|
||||
|
||||
rx->ctx.recv_ttl = TTL(buf->data);
|
||||
|
||||
/* Default to responding with TTL 0 for non-routed messages */
|
||||
|
@ -1132,10 +1123,8 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
|
|||
}
|
||||
|
||||
rx->ctl = CTL(buf->data);
|
||||
net_buf_simple_pull(buf, 2); /* SRC, already parsed by net_decrypt() */
|
||||
rx->seq = net_seq(buf);
|
||||
net_buf_simple_pull(buf, 2);
|
||||
rx->dst = net_buf_simple_pull_be16(buf);
|
||||
rx->seq = SEQ(buf->data);
|
||||
rx->dst = DST(buf->data);
|
||||
|
||||
BT_DBG("Decryption successful. Payload len %u", buf->len);
|
||||
|
||||
|
@ -1175,7 +1164,7 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
|
|||
return;
|
||||
}
|
||||
|
||||
if (bt_mesh_net_decode(data, net_if, &rx, buf, &state)) {
|
||||
if (bt_mesh_net_decode(data, net_if, &rx, buf)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1184,6 +1173,9 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
|
|||
bt_mesh_proxy_addr_add(data, rx.ctx.addr);
|
||||
}
|
||||
|
||||
/* Save parsing state so the buffer can later be relayed */
|
||||
net_buf_simple_save(buf, &state);
|
||||
|
||||
if (bt_mesh_fixed_group_match(rx.dst) || bt_mesh_elem_find(rx.dst)) {
|
||||
bt_mesh_trans_recv(buf, &rx);
|
||||
|
||||
|
|
|
@ -223,6 +223,8 @@ extern struct bt_mesh_net bt_mesh;
|
|||
#define BT_MESH_NET_IVI_TX (bt_mesh.iv_index - bt_mesh.iv_update)
|
||||
#define BT_MESH_NET_IVI_RX(rx) (bt_mesh.iv_index - (rx)->old_iv)
|
||||
|
||||
#define BT_MESH_NET_HDR_LEN 9
|
||||
|
||||
int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys,
|
||||
const u8_t key[16]);
|
||||
|
||||
|
@ -268,8 +270,7 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
|
|||
bool new_key, bool friend_cred, bt_mesh_adv_func_t cb);
|
||||
|
||||
int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
|
||||
struct bt_mesh_net_rx *rx, struct net_buf_simple *buf,
|
||||
struct net_buf_simple_state *state);
|
||||
struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
|
||||
enum bt_mesh_net_if net_if);
|
||||
|
|
|
@ -239,12 +239,15 @@ static void proxy_cfg(struct bt_mesh_proxy_client *client)
|
|||
int err;
|
||||
|
||||
err = bt_mesh_net_decode(&client->buf, BT_MESH_NET_IF_PROXY_CFG,
|
||||
&rx, buf, NULL);
|
||||
&rx, buf);
|
||||
if (err) {
|
||||
BT_ERR("Failed to decode Proxy Configuration (err %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Remove network headers */
|
||||
net_buf_simple_pull(buf, BT_MESH_NET_HDR_LEN);
|
||||
|
||||
BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
|
||||
if (buf->len < 1) {
|
||||
|
|
|
@ -1075,6 +1075,10 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx)
|
|||
|
||||
BT_DBG("src 0x%04x dst 0x%04x seq 0x%08x", rx->ctx.addr, rx->dst,
|
||||
rx->seq);
|
||||
|
||||
/* Remove network headers */
|
||||
net_buf_simple_pull(buf, BT_MESH_NET_HDR_LEN);
|
||||
|
||||
BT_DBG("Payload %s", bt_hex(buf->data, buf->len));
|
||||
|
||||
/* If LPN mode is enabled messages are only accepted when we've
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue