Skip to content

Commit bc1d658

Browse files
LingaoMcfriedt
authored andcommitted
Bluetooth: Mesh: Move proxy complete message to seperate role
Move proxy complete message to seperate role. Signed-off-by: Lingao Meng <[email protected]>
1 parent d831d8a commit bc1d658

File tree

4 files changed

+83
-76
lines changed

4 files changed

+83
-76
lines changed

subsys/bluetooth/mesh/pb_gatt_srv.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,34 @@
3434

3535
static bool prov_fast_adv;
3636

37+
static void proxy_complete_pdu(struct bt_mesh_proxy_role *role);
3738
static int gatt_send(struct bt_conn *conn,
3839
const void *data, uint16_t len,
3940
bt_gatt_complete_func_t end, void *user_data);
4041

4142
static struct bt_mesh_proxy_role cli = {
42-
.cb.send = gatt_send,
43+
.cb = {
44+
.send = gatt_send,
45+
.recv = proxy_complete_pdu,
46+
},
4347
};
4448

4549
static bool service_registered;
4650

51+
static void proxy_complete_pdu(struct bt_mesh_proxy_role *role)
52+
{
53+
switch (role->msg_type) {
54+
case BT_MESH_PROXY_PROV:
55+
BT_DBG("Mesh Provisioning PDU");
56+
bt_mesh_pb_gatt_recv(role->conn, &role->buf);
57+
break;
58+
59+
default:
60+
BT_WARN("Unhandled Message Type 0x%02x", role->msg_type);
61+
break;
62+
}
63+
}
64+
4765
static ssize_t gatt_recv(struct bt_conn *conn,
4866
const struct bt_gatt_attr *attr, const void *buf,
4967
uint16_t len, uint16_t offset, uint8_t flags)

subsys/bluetooth/mesh/proxy_msg.c

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -73,73 +73,6 @@ static void proxy_sar_timeout(struct k_work *work)
7373
}
7474
}
7575

76-
#if defined(CONFIG_BT_MESH_PROXY)
77-
static void proxy_cfg(struct bt_mesh_proxy_role *role)
78-
{
79-
NET_BUF_SIMPLE_DEFINE(buf, BT_MESH_NET_MAX_PDU_LEN);
80-
struct bt_mesh_net_rx rx;
81-
int err;
82-
83-
err = bt_mesh_net_decode(&role->buf, BT_MESH_NET_IF_PROXY_CFG,
84-
&rx, &buf);
85-
if (err) {
86-
BT_ERR("Failed to decode Proxy Configuration (err %d)", err);
87-
return;
88-
}
89-
90-
rx.local_match = 1U;
91-
92-
if (bt_mesh_rpl_check(&rx, NULL)) {
93-
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
94-
rx.ctx.addr, rx.ctx.recv_dst, rx.seq);
95-
return;
96-
}
97-
98-
/* Remove network headers */
99-
net_buf_simple_pull(&buf, BT_MESH_NET_HDR_LEN);
100-
101-
BT_DBG("%u bytes: %s", buf.len, bt_hex(buf.data, buf.len));
102-
103-
if (buf.len < 1) {
104-
BT_WARN("Too short proxy configuration PDU");
105-
return;
106-
}
107-
108-
role->cb.recv(role->conn, &rx, &buf);
109-
}
110-
#endif
111-
112-
static void proxy_complete_pdu(struct bt_mesh_proxy_role *role)
113-
{
114-
switch (role->msg_type) {
115-
#if defined(CONFIG_BT_MESH_PROXY)
116-
case BT_MESH_PROXY_NET_PDU:
117-
BT_DBG("Mesh Network PDU");
118-
bt_mesh_net_recv(&role->buf, 0, BT_MESH_NET_IF_PROXY);
119-
break;
120-
case BT_MESH_PROXY_BEACON:
121-
BT_DBG("Mesh Beacon PDU");
122-
bt_mesh_beacon_recv(&role->buf);
123-
break;
124-
case BT_MESH_PROXY_CONFIG:
125-
BT_DBG("Mesh Configuration PDU");
126-
proxy_cfg(role);
127-
break;
128-
#endif
129-
#if defined(CONFIG_BT_MESH_PB_GATT)
130-
case BT_MESH_PROXY_PROV:
131-
BT_DBG("Mesh Provisioning PDU");
132-
bt_mesh_pb_gatt_recv(role->conn, &role->buf);
133-
break;
134-
#endif
135-
default:
136-
BT_WARN("Unhandled Message Type 0x%02x", role->msg_type);
137-
break;
138-
}
139-
140-
net_buf_simple_reset(&role->buf);
141-
}
142-
14376
ssize_t bt_mesh_proxy_msg_recv(struct bt_mesh_proxy_role *role,
14477
const void *buf, uint16_t len)
14578
{
@@ -154,7 +87,8 @@ ssize_t bt_mesh_proxy_msg_recv(struct bt_mesh_proxy_role *role,
15487

15588
role->msg_type = PDU_TYPE(data);
15689
net_buf_simple_add_mem(&role->buf, data + 1, len - 1);
157-
proxy_complete_pdu(role);
90+
role->cb.recv(role);
91+
net_buf_simple_reset(&role->buf);
15892
break;
15993

16094
case SAR_FIRST:
@@ -199,7 +133,8 @@ ssize_t bt_mesh_proxy_msg_recv(struct bt_mesh_proxy_role *role,
199133
*/
200134
(void)k_work_cancel_delayable(&role->sar_timer);
201135
net_buf_simple_add_mem(&role->buf, data + 1, len - 1);
202-
proxy_complete_pdu(role);
136+
role->cb.recv(role);
137+
net_buf_simple_reset(&role->buf);
203138
break;
204139
}
205140

subsys/bluetooth/mesh/proxy_msg.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626
#define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6)))
2727

28+
struct bt_mesh_proxy_role;
29+
2830
typedef int (*proxy_send_cb_t)(struct bt_conn *conn,
2931
const void *data, uint16_t len,
3032
bt_gatt_complete_func_t end, void *user_data);
3133

32-
typedef void (*proxy_recv_cb_t)(struct bt_conn *conn,
33-
struct bt_mesh_net_rx *rx,
34-
struct net_buf_simple *buf);
34+
typedef void (*proxy_recv_cb_t)(struct bt_mesh_proxy_role *role);
3535

3636
struct bt_mesh_proxy_role {
3737
struct bt_conn *conn;

subsys/bluetooth/mesh/proxy_srv.c

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
#include "proxy_msg.h"
3333

3434
static void proxy_send_beacons(struct k_work *work);
35-
static void proxy_filter_recv(struct bt_conn *conn,
36-
struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
35+
static void proxy_complete_pdu(struct bt_mesh_proxy_role *role);
3736
static int proxy_send(struct bt_conn *conn,
3837
const void *data, uint16_t len,
3938
bt_gatt_complete_func_t end, void *user_data);
@@ -53,7 +52,7 @@ static struct bt_mesh_proxy_client {
5352
.send_beacons = Z_WORK_INITIALIZER(proxy_send_beacons),
5453
.cli.cb = {
5554
.send = proxy_send,
56-
.recv = proxy_filter_recv,
55+
.recv = proxy_complete_pdu,
5756
},
5857
},
5958
};
@@ -263,6 +262,61 @@ static void proxy_filter_recv(struct bt_conn *conn,
263262
}
264263
}
265264

265+
static void proxy_cfg(struct bt_mesh_proxy_role *role)
266+
{
267+
NET_BUF_SIMPLE_DEFINE(buf, BT_MESH_NET_MAX_PDU_LEN);
268+
struct bt_mesh_net_rx rx;
269+
int err;
270+
271+
err = bt_mesh_net_decode(&role->buf, BT_MESH_NET_IF_PROXY_CFG,
272+
&rx, &buf);
273+
if (err) {
274+
BT_ERR("Failed to decode Proxy Configuration (err %d)", err);
275+
return;
276+
}
277+
278+
rx.local_match = 1U;
279+
280+
if (bt_mesh_rpl_check(&rx, NULL)) {
281+
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
282+
rx.ctx.addr, rx.ctx.recv_dst, rx.seq);
283+
return;
284+
}
285+
286+
/* Remove network headers */
287+
net_buf_simple_pull(&buf, BT_MESH_NET_HDR_LEN);
288+
289+
BT_DBG("%u bytes: %s", buf.len, bt_hex(buf.data, buf.len));
290+
291+
if (buf.len < 1) {
292+
BT_WARN("Too short proxy configuration PDU");
293+
return;
294+
}
295+
296+
proxy_filter_recv(role->conn, &rx, &buf);
297+
}
298+
299+
static void proxy_complete_pdu(struct bt_mesh_proxy_role *role)
300+
{
301+
switch (role->msg_type) {
302+
case BT_MESH_PROXY_NET_PDU:
303+
BT_DBG("Mesh Network PDU");
304+
bt_mesh_net_recv(&role->buf, 0, BT_MESH_NET_IF_PROXY);
305+
break;
306+
case BT_MESH_PROXY_BEACON:
307+
BT_DBG("Mesh Beacon PDU");
308+
bt_mesh_beacon_recv(&role->buf);
309+
break;
310+
case BT_MESH_PROXY_CONFIG:
311+
BT_DBG("Mesh Configuration PDU");
312+
proxy_cfg(role);
313+
break;
314+
default:
315+
BT_WARN("Unhandled Message Type 0x%02x", role->msg_type);
316+
break;
317+
}
318+
}
319+
266320
static int beacon_send(struct bt_mesh_proxy_client *client,
267321
struct bt_mesh_subnet *sub)
268322
{

0 commit comments

Comments
 (0)