Skip to content

Commit 198c6c7

Browse files
committed
Bluetooth: Mesh: Move command buffer to proxy_msg.c
Move command buffer alloc to proxy_msg.c. Signed-off-by: Lingao Meng <[email protected]>
1 parent 6aba8bd commit 198c6c7

File tree

5 files changed

+39
-36
lines changed

5 files changed

+39
-36
lines changed

subsys/bluetooth/mesh/main.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,6 @@ int bt_mesh_init(const struct bt_mesh_prov *prov,
306306
return err;
307307
}
308308

309-
if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) {
310-
bt_mesh_proxy_init();
311-
}
312-
313309
if (IS_ENABLED(CONFIG_BT_MESH_PROV)) {
314310
err = bt_mesh_prov_init(prov);
315311
if (err) {

subsys/bluetooth/mesh/pb_gatt_srv.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,14 @@
3232
#include "proxy_msg.h"
3333
#include "pb_gatt_srv.h"
3434

35-
#define CLIENT_BUF_SIZE 66
36-
3735
static bool prov_fast_adv;
3836

3937
static int gatt_send(struct bt_conn *conn,
4038
const void *data, uint16_t len,
4139
bt_gatt_complete_func_t end, void *user_data);
4240

43-
static uint8_t __noinit client_buf_data[CLIENT_BUF_SIZE];
4441
static struct bt_mesh_proxy_role cli = {
4542
.cb.send = gatt_send,
46-
.buf = {
47-
.__buf = client_buf_data,
48-
.data = client_buf_data,
49-
.size = CLIENT_BUF_SIZE,
50-
.len = CLIENT_BUF_SIZE,
51-
},
5243
};
5344

5445
static bool service_registered;
@@ -91,7 +82,7 @@ static void gatt_connected(struct bt_conn *conn, uint8_t err)
9182

9283
BT_DBG("conn %p err 0x%02x", (void *)conn, err);
9384

94-
net_buf_simple_reset(&cli.buf);
85+
bt_mesh_proxy_msg_init(&cli);
9586
}
9687

9788
static void gatt_disconnected(struct bt_conn *conn, uint8_t reason)

subsys/bluetooth/mesh/proxy.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,3 @@ void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub);
4747

4848
bool bt_mesh_proxy_relay(struct net_buf *buf, uint16_t dst);
4949
void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, uint16_t addr);
50-
51-
int bt_mesh_proxy_init(void);

subsys/bluetooth/mesh/proxy_msg.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@
4848

4949
#define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6)))
5050

51+
#define PB_GATT_BUF_LEN_MAX 66
52+
#define PROXY_BUF_LEN_MAX 30
53+
54+
#if defined(CONFIG_BT_MESH_PB_GATT)
55+
#define PROXY_MSG_FIRST_BUF_LEN PB_GATT_BUF_LEN_MAX
56+
#else
57+
#define PROXY_MSG_FIRST_BUF_LEN PROXY_BUF_LEN_MAX
58+
#endif
59+
60+
static uint8_t __noinit bufs[PROXY_MSG_FIRST_BUF_LEN +
61+
((CONFIG_BT_MAX_CONN - 1) * PROXY_BUF_LEN_MAX)];
62+
5163
static void proxy_sar_timeout(struct k_work *work)
5264
{
5365
struct bt_mesh_proxy_role *role;
@@ -245,5 +257,29 @@ int bt_mesh_proxy_msg_send(struct bt_mesh_proxy_role *role, uint8_t type,
245257

246258
void bt_mesh_proxy_msg_init(struct bt_mesh_proxy_role *role)
247259
{
260+
uint8_t i, len;
261+
uint8_t *buf;
262+
263+
/* Check if buf has been allocated, in this way, we no longer need
264+
* to repeat the operation.
265+
*/
266+
if (role->buf.__buf) {
267+
net_buf_simple_reset(&role->buf);
268+
return;
269+
}
270+
271+
i = bt_conn_index(role->conn);
272+
if (!i) {
273+
len = PROXY_MSG_FIRST_BUF_LEN;
274+
buf = bufs;
275+
} else {
276+
len = PROXY_BUF_LEN_MAX;
277+
buf = &bufs[PROXY_MSG_FIRST_BUF_LEN + (PROXY_BUF_LEN_MAX * (i - 1))];
278+
}
279+
280+
net_buf_simple_init_with_data(&role->buf, buf, len);
281+
282+
net_buf_simple_reset(&role->buf);
283+
248284
k_work_init_delayable(&role->sar_timer, proxy_sar_timeout);
249285
}

subsys/bluetooth/mesh/proxy_srv.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ static struct bt_mesh_proxy_client {
5858
},
5959
};
6060

61-
static uint8_t __noinit client_buf_data[CLIENT_BUF_SIZE * CONFIG_BT_MAX_CONN];
62-
6361
static bool service_registered;
6462
static int conn_count;
6563

@@ -824,7 +822,8 @@ static void gatt_connected(struct bt_conn *conn, uint8_t err)
824822
client->cli.conn = bt_conn_ref(conn);
825823
client->filter_type = NONE;
826824
(void)memset(client->filter, 0, sizeof(client->filter));
827-
net_buf_simple_reset(&client->cli.buf);
825+
826+
bt_mesh_proxy_msg_init(&client->cli);
828827
}
829828

830829
static void gatt_disconnected(struct bt_conn *conn, uint8_t reason)
@@ -893,20 +892,3 @@ BT_CONN_CB_DEFINE(conn_callbacks_1) = {
893892
.connected = gatt_connected,
894893
.disconnected = gatt_disconnected,
895894
};
896-
897-
int bt_mesh_proxy_init(void)
898-
{
899-
int i;
900-
901-
/* Initialize the client receive buffers */
902-
for (i = 0; i < ARRAY_SIZE(clients); i++) {
903-
struct bt_mesh_proxy_client *client = &clients[i];
904-
905-
net_buf_simple_init_with_data(&client->cli.buf,
906-
client_buf_data + (i * CLIENT_BUF_SIZE), CLIENT_BUF_SIZE);
907-
908-
bt_mesh_proxy_msg_init(&client->cli);
909-
}
910-
911-
return 0;
912-
}

0 commit comments

Comments
 (0)