Lines Matching +full:data +full:- +full:role
7 * SPDX-License-Identifier: Apache-2.0
38 #define PDU_SAR(data) (data[0] >> 6) argument
61 struct bt_mesh_proxy_role *role; in proxy_sar_timeout() local
66 role = CONTAINER_OF(dwork, struct bt_mesh_proxy_role, sar_timer); in proxy_sar_timeout()
68 while (!k_fifo_is_empty(&role->pending)) { in proxy_sar_timeout()
69 struct bt_mesh_adv *adv = k_fifo_get(&role->pending, K_NO_WAIT); in proxy_sar_timeout()
76 if (role->conn) { in proxy_sar_timeout()
77 bt_conn_disconnect(role->conn, in proxy_sar_timeout()
85 const uint8_t *data = buf; in bt_mesh_proxy_msg_recv() local
86 struct bt_mesh_proxy_role *role = &roles[bt_conn_index(conn)]; in bt_mesh_proxy_msg_recv() local
88 if (net_buf_simple_tailroom(&role->buf) < len - 1) { in bt_mesh_proxy_msg_recv()
89 LOG_WRN("Proxy role buffer overflow"); in bt_mesh_proxy_msg_recv()
90 return -EINVAL; in bt_mesh_proxy_msg_recv()
93 switch (PDU_SAR(data)) { in bt_mesh_proxy_msg_recv()
95 if (role->buf.len) { in bt_mesh_proxy_msg_recv()
97 return -EINVAL; in bt_mesh_proxy_msg_recv()
100 role->msg_type = PDU_TYPE(data); in bt_mesh_proxy_msg_recv()
101 net_buf_simple_add_mem(&role->buf, data + 1, len - 1); in bt_mesh_proxy_msg_recv()
102 role->cb.recv(role); in bt_mesh_proxy_msg_recv()
103 net_buf_simple_reset(&role->buf); in bt_mesh_proxy_msg_recv()
107 if (role->buf.len) { in bt_mesh_proxy_msg_recv()
109 return -EINVAL; in bt_mesh_proxy_msg_recv()
112 k_work_reschedule(&role->sar_timer, PROXY_SAR_TIMEOUT); in bt_mesh_proxy_msg_recv()
113 role->msg_type = PDU_TYPE(data); in bt_mesh_proxy_msg_recv()
114 net_buf_simple_add_mem(&role->buf, data + 1, len - 1); in bt_mesh_proxy_msg_recv()
118 if (!role->buf.len) { in bt_mesh_proxy_msg_recv()
119 LOG_WRN("Continuation with no prior data"); in bt_mesh_proxy_msg_recv()
120 return -EINVAL; in bt_mesh_proxy_msg_recv()
123 if (role->msg_type != PDU_TYPE(data)) { in bt_mesh_proxy_msg_recv()
125 return -EINVAL; in bt_mesh_proxy_msg_recv()
128 k_work_reschedule(&role->sar_timer, PROXY_SAR_TIMEOUT); in bt_mesh_proxy_msg_recv()
129 net_buf_simple_add_mem(&role->buf, data + 1, len - 1); in bt_mesh_proxy_msg_recv()
133 if (!role->buf.len) { in bt_mesh_proxy_msg_recv()
134 LOG_WRN("Last SAR PDU with no prior data"); in bt_mesh_proxy_msg_recv()
135 return -EINVAL; in bt_mesh_proxy_msg_recv()
138 if (role->msg_type != PDU_TYPE(data)) { in bt_mesh_proxy_msg_recv()
140 return -EINVAL; in bt_mesh_proxy_msg_recv()
146 (void)k_work_cancel_delayable(&role->sar_timer); in bt_mesh_proxy_msg_recv()
147 net_buf_simple_add_mem(&role->buf, data + 1, len - 1); in bt_mesh_proxy_msg_recv()
148 role->cb.recv(role); in bt_mesh_proxy_msg_recv()
149 net_buf_simple_reset(&role->buf); in bt_mesh_proxy_msg_recv()
162 struct bt_mesh_proxy_role *role = &roles[bt_conn_index(conn)]; in bt_mesh_proxy_msg_send() local
164 LOG_DBG("conn %p type 0x%02x len %u: %s", (void *)conn, type, msg->len, in bt_mesh_proxy_msg_send()
165 bt_hex(msg->data, msg->len)); in bt_mesh_proxy_msg_send()
167 /* ATT_MTU - OpCode (1 byte) - Handle (2 bytes) */ in bt_mesh_proxy_msg_send()
168 mtu = bt_gatt_get_mtu(conn) - 3; in bt_mesh_proxy_msg_send()
169 if (mtu > msg->len) { in bt_mesh_proxy_msg_send()
171 return role->cb.send(conn, msg->data, msg->len, end, user_data); in bt_mesh_proxy_msg_send()
175 err = role->cb.send(conn, msg->data, mtu, NULL, NULL); in bt_mesh_proxy_msg_send()
182 while (msg->len) { in bt_mesh_proxy_msg_send()
183 if (msg->len + 1 <= mtu) { in bt_mesh_proxy_msg_send()
185 err = role->cb.send(conn, msg->data, msg->len, end, user_data); in bt_mesh_proxy_msg_send()
194 err = role->cb.send(conn, msg->data, mtu, NULL, NULL); in bt_mesh_proxy_msg_send()
222 net_buf_simple_add_mem(&msg, adv->b.data, adv->b.len); in proxy_relay_send()
227 bt_mesh_adv_send_start(0, err, &adv->ctx); in proxy_relay_send()
232 * not be called, so we need to clear the user data (net_buf, in proxy_relay_send()
233 * which is just opaque data to segment_and send) reference given in proxy_relay_send()
244 struct bt_mesh_proxy_role *role = &roles[bt_conn_index(conn)]; in bt_mesh_proxy_relay_send() local
246 k_fifo_put(&role->pending, bt_mesh_adv_ref(adv)); in bt_mesh_proxy_relay_send()
248 bt_mesh_wq_submit(&role->work); in bt_mesh_proxy_relay_send()
255 struct bt_mesh_proxy_role *role = CONTAINER_OF(work, struct bt_mesh_proxy_role, work); in proxy_msg_send_pending() local
258 if (!role->conn) { in proxy_msg_send_pending()
262 adv = k_fifo_get(&role->pending, K_NO_WAIT); in proxy_msg_send_pending()
267 (void)proxy_relay_send(role->conn, adv); in proxy_msg_send_pending()
270 if (!k_fifo_is_empty(&role->pending)) { in proxy_msg_send_pending()
271 bt_mesh_wq_submit(&role->work); in proxy_msg_send_pending()
275 static void proxy_msg_init(struct bt_mesh_proxy_role *role) in proxy_msg_init() argument
280 if (role->buf.__buf) { in proxy_msg_init()
281 net_buf_simple_reset(&role->buf); in proxy_msg_init()
285 net_buf_simple_init_with_data(&role->buf, in proxy_msg_init()
286 &bufs[bt_conn_index(role->conn) * in proxy_msg_init()
290 net_buf_simple_reset(&role->buf); in proxy_msg_init()
292 k_fifo_init(&role->pending); in proxy_msg_init()
293 k_work_init(&role->work, proxy_msg_send_pending); in proxy_msg_init()
295 k_work_init_delayable(&role->sar_timer, proxy_sar_timeout); in proxy_msg_init()
302 struct bt_mesh_proxy_role *role; in bt_mesh_proxy_role_setup() local
306 role = &roles[bt_conn_index(conn)]; in bt_mesh_proxy_role_setup()
308 role->conn = bt_conn_ref(conn); in bt_mesh_proxy_role_setup()
309 proxy_msg_init(role); in bt_mesh_proxy_role_setup()
311 role->cb.recv = recv; in bt_mesh_proxy_role_setup()
312 role->cb.send = send; in bt_mesh_proxy_role_setup()
314 return role; in bt_mesh_proxy_role_setup()
317 void bt_mesh_proxy_role_cleanup(struct bt_mesh_proxy_role *role) in bt_mesh_proxy_role_cleanup() argument
322 (void)k_work_cancel_delayable(&role->sar_timer); in bt_mesh_proxy_role_cleanup()
323 bt_conn_unref(role->conn); in bt_mesh_proxy_role_cleanup()
324 role->conn = NULL; in bt_mesh_proxy_role_cleanup()
326 conn_count--; in bt_mesh_proxy_role_cleanup()