mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 04:04:31 +02: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:
@@ -168,6 +168,19 @@ static inline void net_buf_simple_reset(struct net_buf_simple *buf)
|
|||||||
buf->data = buf->__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
|
* @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;
|
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)
|
void *net_buf_simple_add(struct net_buf_simple *buf, size_t len)
|
||||||
{
|
{
|
||||||
u8_t *tail = net_buf_simple_tail(buf);
|
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,
|
struct net_buf *buf,
|
||||||
const struct unseg_app_sdu_meta *meta)
|
const struct unseg_app_sdu_meta *meta)
|
||||||
{
|
{
|
||||||
struct net_buf_simple sdu = {
|
struct net_buf_simple sdu;
|
||||||
.len = buf->len - 14,
|
|
||||||
.data = &buf->data[10],
|
net_buf_simple_clone(&buf->b, &sdu);
|
||||||
.__buf = &buf->data[10],
|
net_buf_simple_pull(&sdu, 10);
|
||||||
.size = buf->len - 10,
|
sdu.len -= 4;
|
||||||
};
|
|
||||||
|
|
||||||
return bt_mesh_app_decrypt(meta->key, meta->is_dev_key, 0, &sdu, &sdu,
|
return bt_mesh_app_decrypt(meta->key, meta->is_dev_key, 0, &sdu, &sdu,
|
||||||
meta->ad, meta->net.ctx.addr,
|
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,
|
struct net_buf *buf,
|
||||||
const struct unseg_app_sdu_meta *meta)
|
const struct unseg_app_sdu_meta *meta)
|
||||||
{
|
{
|
||||||
struct net_buf_simple sdu = {
|
struct net_buf_simple sdu;
|
||||||
.len = buf->len - 14,
|
|
||||||
.data = &buf->data[10],
|
net_buf_simple_clone(&buf->b, &sdu);
|
||||||
.__buf = &buf->data[10],
|
net_buf_simple_pull(&sdu, 10);
|
||||||
.size = buf->len - 10,
|
sdu.len -= 4;
|
||||||
};
|
|
||||||
|
|
||||||
return bt_mesh_app_encrypt(meta->key, meta->is_dev_key, 0, &sdu,
|
return bt_mesh_app_encrypt(meta->key, meta->is_dev_key, 0, &sdu,
|
||||||
meta->ad, meta->net.ctx.addr,
|
meta->ad, meta->net.ctx.addr,
|
||||||
|
Reference in New Issue
Block a user