mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ble_mesh: Use net_buf_simple_clone
Uses net_buf_simple_clone to access the sdu of an unsegmented app packet for re-encryption.
This commit is contained in:
parent
4bf2ceee4e
commit
318f83e33a
@ -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
|
||||
*
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user