ble_mesh: Use net_buf_simple_clone

Uses net_buf_simple_clone to access the sdu of an unsegmented app packet
for re-encryption.
pull/4625/head
lly 2019-10-24 16:17:22 +08:00
rodzic aec696a3a4
commit f3b9b099cd
3 zmienionych plików z 29 dodań i 12 usunięć

Wyświetl plik

@ -168,6 +168,19 @@ static inline void net_buf_simple_reset(struct net_buf_simple *buf)
buf->data = buf->__buf;
}
/**
* Clone buffer state, using the same data buffer.
*
* Initializes a buffer to point to the same data as an existing buffer.
* Allows operations on the same data without altering the length and
* offset of the original.
*
* @param original Buffer to clone.
* @param clone The new clone.
*/
void net_buf_simple_clone(const struct net_buf_simple *original,
struct net_buf_simple *clone);
/**
* @brief Prepare data to be added at the end of the buffer
*

Wyświetl plik

@ -31,6 +31,12 @@ static inline struct net_buf *pool_get_uninit(struct net_buf_pool *pool,
return buf;
}
void net_buf_simple_clone(const struct net_buf_simple *original,
struct net_buf_simple *clone)
{
memcpy(clone, original, sizeof(struct net_buf_simple));
}
void *net_buf_simple_add(struct net_buf_simple *buf, size_t len)
{
u8_t *tail = net_buf_simple_tail(buf);

Wyświetl plik

@ -384,12 +384,11 @@ static int unseg_app_sdu_decrypt(struct bt_mesh_friend *frnd,
struct net_buf *buf,
const struct unseg_app_sdu_meta *meta)
{
struct net_buf_simple sdu = {
.len = buf->len - 14,
.data = &buf->data[10],
.__buf = &buf->data[10],
.size = buf->len - 10,
};
struct net_buf_simple sdu;
net_buf_simple_clone(&buf->b, &sdu);
net_buf_simple_pull(&sdu, 10);
sdu.len -= 4;
return bt_mesh_app_decrypt(meta->key, meta->is_dev_key, 0, &sdu, &sdu,
meta->ad, meta->net.ctx.addr,
@ -401,12 +400,11 @@ static int unseg_app_sdu_encrypt(struct bt_mesh_friend *frnd,
struct net_buf *buf,
const struct unseg_app_sdu_meta *meta)
{
struct net_buf_simple sdu = {
.len = buf->len - 14,
.data = &buf->data[10],
.__buf = &buf->data[10],
.size = buf->len - 10,
};
struct net_buf_simple sdu;
net_buf_simple_clone(&buf->b, &sdu);
net_buf_simple_pull(&sdu, 10);
sdu.len -= 4;
return bt_mesh_app_encrypt(meta->key, meta->is_dev_key, 0, &sdu,
meta->ad, meta->net.ctx.addr,