|
48 | 48 |
|
49 | 49 | #define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6))) |
50 | 50 |
|
| 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 | + |
51 | 63 | static void proxy_sar_timeout(struct k_work *work) |
52 | 64 | { |
53 | 65 | 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, |
245 | 257 |
|
246 | 258 | void bt_mesh_proxy_msg_init(struct bt_mesh_proxy_role *role) |
247 | 259 | { |
| 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 | + |
248 | 284 | k_work_init_delayable(&role->sar_timer, proxy_sar_timeout); |
249 | 285 | } |
0 commit comments