Lines Matching refs:chan
36 #define ATT_CHAN(_ch) CONTAINER_OF(_ch, struct bt_att_chan, chan.chan)
105 struct bt_l2cap_le_chan chan; member
113 static bool bt_att_is_enhanced(struct bt_att_chan *chan) in bt_att_is_enhanced() argument
120 return atomic_test_bit(chan->flags, ATT_ENHANCED); in bt_att_is_enhanced()
123 static uint16_t bt_att_mtu(struct bt_att_chan *chan) in bt_att_mtu() argument
130 return MIN(chan->chan.rx.mtu, chan->chan.tx.mtu); in bt_att_mtu()
289 static int bt_att_chan_send(struct bt_att_chan *chan, struct net_buf *buf);
292 static void bt_att_disconnected(struct bt_l2cap_chan *chan);
294 struct net_buf *bt_att_create_rsp_pdu(struct bt_att_chan *chan, uint8_t op);
303 struct bt_l2cap_chan *chan = &att_chan->chan.chan; in att_sent() local
307 LOG_DBG("conn %p chan %p", conn, chan); in att_sent()
315 bt_att_sent(chan); in att_sent()
325 static int chan_send(struct bt_att_chan *chan, struct net_buf *buf) in chan_send() argument
337 if (!atomic_test_bit(chan->flags, ATT_CONNECTED)) { in chan_send()
343 chan->chan.tx.cid != BT_L2CAP_CID_ATT) { in chan_send()
354 if (IS_ENABLED(CONFIG_BT_EATT) && bt_att_is_enhanced(chan)) { in chan_send()
358 if (atomic_test_bit(chan->flags, ATT_PENDING_SENT)) { in chan_send()
368 !atomic_test_bit(chan->chan.chan.status, in chan_send()
373 atomic_set_bit(chan->flags, ATT_PENDING_SENT); in chan_send()
374 data->att_chan = chan; in chan_send()
379 err = bt_l2cap_chan_send(&chan->chan.chan, buf); in chan_send()
382 atomic_clear_bit(chan->flags, ATT_PENDING_SENT); in chan_send()
399 err = bt_smp_sign(chan->att->conn, buf); in chan_send()
409 data->att_chan = chan; in chan_send()
411 err = bt_l2cap_send_pdu(&chan->chan, buf, NULL, NULL); in chan_send()
425 static bool att_chan_matches_chan_opt(struct bt_att_chan *chan, enum bt_att_chan_opt chan_opt) in att_chan_matches_chan_opt() argument
433 if (bt_att_is_enhanced(chan)) { in att_chan_matches_chan_opt()
440 static struct net_buf *get_first_buf_matching_chan(struct k_fifo *fifo, struct bt_att_chan *chan) in get_first_buf_matching_chan() argument
453 att_chan_matches_chan_opt(chan, meta->chan_opt)) { in get_first_buf_matching_chan()
474 static struct bt_att_req *get_first_req_matching_chan(sys_slist_t *reqs, struct bt_att_chan *chan) in get_first_req_matching_chan() argument
482 if (att_chan_matches_chan_opt(chan, meta->chan_opt)) { in get_first_req_matching_chan()
507 static int process_queue(struct bt_att_chan *chan, struct k_fifo *queue) in process_queue() argument
512 buf = get_first_buf_matching_chan(queue, chan); in process_queue()
514 err = bt_att_chan_send(chan, buf); in process_queue()
528 static int chan_req_send(struct bt_att_chan *chan, struct bt_att_req *req) in chan_req_send() argument
533 if (bt_att_mtu(chan) < net_buf_frags_len(req->buf)) { in chan_req_send()
537 LOG_DBG("chan %p req %p len %zu", chan, req, net_buf_frags_len(req->buf)); in chan_req_send()
539 chan->req = req; in chan_req_send()
549 err = bt_att_chan_send(chan, buf); in chan_req_send()
553 chan->req = NULL; in chan_req_send()
555 bt_gatt_req_set_mtu(req, bt_att_mtu(chan)); in chan_req_send()
564 struct bt_att_chan *chan = ATT_CHAN(ch); in bt_att_sent() local
565 struct bt_att *att = chan->att; in bt_att_sent()
568 LOG_DBG("chan %p", chan); in bt_att_sent()
570 atomic_clear_bit(chan->flags, ATT_PENDING_SENT); in bt_att_sent()
582 if (!chan->req && !sys_slist_is_empty(&att->reqs)) { in bt_att_sent()
585 if (chan_req_send(chan, ATT_REQ(node)) >= 0) { in bt_att_sent()
594 err = process_queue(chan, &chan->tx_queue); in bt_att_sent()
600 (void)process_queue(chan, &att->tx_queue); in bt_att_sent()
606 struct bt_att_chan *chan = data->att_chan; in chan_rebegin_att_timeout() local
608 LOG_DBG("chan %p chan->req %p", chan, chan->req); in chan_rebegin_att_timeout()
610 if (!atomic_test_bit(chan->flags, ATT_CONNECTED)) { in chan_rebegin_att_timeout()
618 if (chan->req) { in chan_rebegin_att_timeout()
619 k_work_reschedule(&chan->timeout_work, BT_ATT_TIMEOUT); in chan_rebegin_att_timeout()
626 struct bt_att_chan *chan = data->att_chan; in chan_req_notif_sent() local
627 struct bt_conn *conn = chan->att->conn; in chan_req_notif_sent()
632 LOG_DBG("chan %p CID 0x%04X", chan, chan->chan.tx.cid); in chan_req_notif_sent()
634 if (!atomic_test_bit(chan->flags, ATT_CONNECTED)) { in chan_req_notif_sent()
689 static struct net_buf *bt_att_chan_create_pdu(struct bt_att_chan *chan, uint8_t op, size_t len) in bt_att_chan_create_pdu() argument
696 if (len + sizeof(op) > bt_att_mtu(chan)) { in bt_att_chan_create_pdu()
697 LOG_WRN("ATT MTU exceeded, max %u, wanted %zu", bt_att_mtu(chan), in bt_att_chan_create_pdu()
728 data->att_chan = chan; in bt_att_chan_create_pdu()
736 static int bt_att_chan_send(struct bt_att_chan *chan, struct net_buf *buf) in bt_att_chan_send() argument
738 LOG_DBG("chan %p flags %lu code 0x%02x", chan, atomic_get(chan->flags), in bt_att_chan_send()
742 !att_chan_matches_chan_opt(chan, bt_att_get_tx_meta_data(buf)->chan_opt)) { in bt_att_chan_send()
746 return chan_send(chan, buf); in bt_att_chan_send()
751 struct bt_att_chan *chan, *tmp, *prev = NULL; in att_send_process() local
754 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&att->chans, chan, tmp, node) { in att_send_process()
756 (bt_att_is_enhanced(chan) == bt_att_is_enhanced(prev))) { in att_send_process()
764 err = process_queue(chan, &att->tx_queue); in att_send_process()
770 prev = chan; in att_send_process()
774 static void bt_att_chan_send_rsp(struct bt_att_chan *chan, struct net_buf *buf) in bt_att_chan_send_rsp() argument
778 err = chan_send(chan, buf); in bt_att_chan_send_rsp()
781 k_fifo_put(&chan->tx_queue, buf); in bt_att_chan_send_rsp()
785 static void send_err_rsp(struct bt_att_chan *chan, uint8_t req, uint16_t handle, in send_err_rsp() argument
796 buf = bt_att_chan_create_pdu(chan, BT_ATT_OP_ERROR_RSP, sizeof(*rsp)); in send_err_rsp()
806 bt_att_chan_send_rsp(chan, buf); in send_err_rsp()
809 static uint8_t att_mtu_req(struct bt_att_chan *chan, struct net_buf *buf) in att_mtu_req() argument
819 if (bt_att_is_enhanced(chan)) { in att_mtu_req()
834 pdu = bt_att_create_rsp_pdu(chan, BT_ATT_OP_MTU_RSP); in att_mtu_req()
846 bt_att_chan_send_rsp(chan, pdu); in att_mtu_req()
851 chan->chan.rx.mtu = mtu_server; in att_mtu_req()
852 chan->chan.tx.mtu = mtu_client; in att_mtu_req()
854 LOG_DBG("Negotiated MTU %u", bt_att_mtu(chan)); in att_mtu_req()
863 atomic_set_bit(chan->att->conn->flags, BT_CONN_ATT_MTU_EXCHANGED); in att_mtu_req()
866 att_chan_mtu_updated(chan); in att_mtu_req()
871 static int bt_att_chan_req_send(struct bt_att_chan *chan, in bt_att_chan_req_send() argument
874 __ASSERT_NO_MSG(chan); in bt_att_chan_req_send()
877 __ASSERT_NO_MSG(!chan->req); in bt_att_chan_req_send()
881 return chan_req_send(chan, req); in bt_att_chan_req_send()
887 struct bt_att_chan *chan, *tmp, *prev = NULL; in att_req_send_process() local
889 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&att->chans, chan, tmp, node) { in att_req_send_process()
891 if (chan->req) { in att_req_send_process()
895 if (!req && prev && (bt_att_is_enhanced(chan) == bt_att_is_enhanced(prev))) { in att_req_send_process()
903 prev = chan; in att_req_send_process()
906 req = get_first_req_matching_chan(&att->reqs, chan); in att_req_send_process()
911 if (bt_att_chan_req_send(chan, req) >= 0) { in att_req_send_process()
920 static uint8_t att_handle_rsp(struct bt_att_chan *chan, void *pdu, uint16_t len, in att_handle_rsp() argument
926 LOG_DBG("chan %p err %d len %u: %s", chan, err, len, bt_hex(pdu, len)); in att_handle_rsp()
929 k_work_cancel_delayable(&chan->timeout_work); in att_handle_rsp()
931 if (!chan->req) { in att_handle_rsp()
937 if (chan->req == &cancel) { in att_handle_rsp()
938 chan->req = NULL; in att_handle_rsp()
943 func = chan->req->func; in att_handle_rsp()
944 chan->req->func = NULL; in att_handle_rsp()
945 params = chan->req->user_data; in att_handle_rsp()
948 bt_att_req_free(chan->req); in att_handle_rsp()
949 chan->req = NULL; in att_handle_rsp()
953 att_req_send_process(chan->att); in att_handle_rsp()
955 func(chan->att->conn, err, pdu, len, params); in att_handle_rsp()
962 static uint8_t att_mtu_rsp(struct bt_att_chan *chan, struct net_buf *buf) in att_mtu_rsp() argument
975 return att_handle_rsp(chan, NULL, 0, BT_ATT_ERR_INVALID_PDU); in att_mtu_rsp()
981 chan->chan.rx.mtu = BT_LOCAL_ATT_MTU_UATT; in att_mtu_rsp()
986 chan->chan.tx.mtu = mtu; in att_mtu_rsp()
988 LOG_DBG("Negotiated MTU %u", bt_att_mtu(chan)); in att_mtu_rsp()
990 att_chan_mtu_updated(chan); in att_mtu_rsp()
992 return att_handle_rsp(chan, rsp, buf->len, 0); in att_mtu_rsp()
1018 struct bt_att_chan *chan; member
1031 struct bt_att_chan *chan = data->chan; in find_info_cb() local
1053 if (bt_att_mtu(chan) - data->buf->len > in find_info_cb()
1070 if (bt_att_mtu(chan) - data->buf->len > in find_info_cb()
1079 static uint8_t att_find_info_rsp(struct bt_att_chan *chan, uint16_t start_handle, in att_find_info_rsp() argument
1086 data.buf = bt_att_create_rsp_pdu(chan, BT_ATT_OP_FIND_INFO_RSP); in att_find_info_rsp()
1091 data.chan = chan; in att_find_info_rsp()
1097 send_err_rsp(chan, BT_ATT_OP_FIND_INFO_REQ, start_handle, in att_find_info_rsp()
1102 bt_att_chan_send_rsp(chan, data.buf); in att_find_info_rsp()
1107 static uint8_t att_find_info_req(struct bt_att_chan *chan, struct net_buf *buf) in att_find_info_req() argument
1120 send_err_rsp(chan, BT_ATT_OP_FIND_INFO_REQ, err_handle, in att_find_info_req()
1125 return att_find_info_rsp(chan, start_handle, end_handle); in att_find_info_req()
1129 struct bt_att_chan *chan; member
1141 struct bt_att_chan *chan = data->chan; in find_type_cb() local
1142 struct bt_conn *conn = chan->chan.chan.conn; in find_type_cb()
1165 if (bt_att_mtu(chan) - net_buf_frags_len(data->buf) < in find_type_cb()
1172 len = MIN(bt_att_mtu(chan) - net_buf_frags_len(data->buf), in find_type_cb()
1232 static uint8_t att_find_type_rsp(struct bt_att_chan *chan, uint16_t start_handle, in att_find_type_rsp() argument
1240 data.buf = bt_att_create_rsp_pdu(chan, BT_ATT_OP_FIND_TYPE_RSP); in att_find_type_rsp()
1245 data.chan = chan; in att_find_type_rsp()
1259 send_err_rsp(chan, BT_ATT_OP_FIND_TYPE_REQ, start_handle, in att_find_type_rsp()
1264 bt_att_chan_send_rsp(chan, data.buf); in att_find_type_rsp()
1269 static uint8_t att_find_type_req(struct bt_att_chan *chan, struct net_buf *buf) in att_find_type_req() argument
1285 send_err_rsp(chan, BT_ATT_OP_FIND_TYPE_REQ, err_handle, in att_find_type_req()
1296 send_err_rsp(chan, BT_ATT_OP_FIND_TYPE_REQ, start_handle, in att_find_type_req()
1301 return att_find_type_rsp(chan, start_handle, end_handle, value, in att_find_type_req()
1317 struct bt_att_chan *chan; member
1360 static ssize_t att_chan_read(struct bt_att_chan *chan, in att_chan_read() argument
1365 struct bt_conn *conn = chan->chan.chan.conn; in att_chan_read()
1370 if (bt_att_mtu(chan) <= net_buf_frags_len(buf)) { in att_chan_read()
1380 len = MIN(bt_att_mtu(chan) - net_buf_frags_len(buf), in att_chan_read()
1392 len = MIN(bt_att_mtu(chan) - net_buf_frags_len(buf), in att_chan_read()
1413 } while (bt_att_mtu(chan) > net_buf_frags_len(buf) && read == len); in att_chan_read()
1422 struct bt_att_chan *chan = data->chan; in read_type_cb() local
1423 struct bt_conn *conn = chan->chan.chan.conn; in read_type_cb()
1468 read = att_chan_read(chan, attr, data->buf, 0, attr_read_type_cb, data); in read_type_cb()
1479 return bt_att_mtu(chan) - net_buf_frags_len(data->buf) > in read_type_cb()
1483 static uint8_t att_read_type_rsp(struct bt_att_chan *chan, struct bt_uuid *uuid, in att_read_type_rsp() argument
1490 data.buf = bt_att_create_rsp_pdu(chan, BT_ATT_OP_READ_TYPE_RSP); in att_read_type_rsp()
1495 data.chan = chan; in att_read_type_rsp()
1508 send_err_rsp(chan, BT_ATT_OP_READ_TYPE_REQ, start_handle, in att_read_type_rsp()
1513 bt_att_chan_send_rsp(chan, data.buf); in att_read_type_rsp()
1518 static uint8_t att_read_type_req(struct bt_att_chan *chan, struct net_buf *buf) in att_read_type_req() argument
1546 send_err_rsp(chan, BT_ATT_OP_READ_TYPE_REQ, err_handle, in att_read_type_req()
1562 if (!bt_gatt_change_aware(chan->chan.chan.conn, true)) { in att_read_type_req()
1567 if (!atomic_test_and_set_bit(chan->flags, ATT_OUT_OF_SYNC_SENT)) { in att_read_type_req()
1575 return att_read_type_rsp(chan, &u.uuid, start_handle, end_handle); in att_read_type_req()
1579 struct bt_att_chan *chan; member
1589 struct bt_att_chan *chan = data->chan; in read_cb() local
1590 struct bt_conn *conn = chan->chan.chan.conn; in read_cb()
1614 ret = att_chan_read(chan, attr, data->buf, data->offset, NULL, NULL); in read_cb()
1623 static uint8_t att_read_rsp(struct bt_att_chan *chan, uint8_t op, uint8_t rsp, in att_read_rsp() argument
1628 if (!bt_gatt_change_aware(chan->att->conn, true)) { in att_read_rsp()
1629 if (!atomic_test_and_set_bit(chan->flags, ATT_OUT_OF_SYNC_SENT)) { in att_read_rsp()
1642 data.buf = bt_att_create_rsp_pdu(chan, rsp); in att_read_rsp()
1647 data.chan = chan; in att_read_rsp()
1659 send_err_rsp(chan, op, handle, data.err); in att_read_rsp()
1663 bt_att_chan_send_rsp(chan, data.buf); in att_read_rsp()
1668 static uint8_t att_read_req(struct bt_att_chan *chan, struct net_buf *buf) in att_read_req() argument
1679 return att_read_rsp(chan, BT_ATT_OP_READ_REQ, BT_ATT_OP_READ_RSP, in att_read_req()
1683 static uint8_t att_read_blob_req(struct bt_att_chan *chan, struct net_buf *buf) in att_read_blob_req() argument
1695 return att_read_rsp(chan, BT_ATT_OP_READ_BLOB_REQ, in att_read_blob_req()
1700 static uint8_t att_read_mult_req(struct bt_att_chan *chan, struct net_buf *buf) in att_read_mult_req() argument
1705 if (!bt_gatt_change_aware(chan->att->conn, true)) { in att_read_mult_req()
1706 if (!atomic_test_and_set_bit(chan->flags, ATT_OUT_OF_SYNC_SENT)) { in att_read_mult_req()
1715 data.buf = bt_att_create_rsp_pdu(chan, BT_ATT_OP_READ_MULT_RSP); in att_read_mult_req()
1720 data.chan = chan; in att_read_mult_req()
1742 send_err_rsp(chan, BT_ATT_OP_READ_MULT_REQ, handle, in att_read_mult_req()
1748 bt_att_chan_send_rsp(chan, data.buf); in att_read_mult_req()
1759 struct bt_att_chan *chan = data->chan; in read_vl_cb() local
1760 struct bt_conn *conn = chan->chan.chan.conn; in read_vl_cb()
1787 if (bt_att_mtu(chan) - data->buf->len < 2) { in read_vl_cb()
1793 read = att_chan_read(chan, attr, data->buf, data->offset, NULL, NULL); in read_vl_cb()
1804 static uint8_t att_read_mult_vl_req(struct bt_att_chan *chan, struct net_buf *buf) in att_read_mult_vl_req() argument
1809 if (!bt_gatt_change_aware(chan->att->conn, true)) { in att_read_mult_vl_req()
1810 if (!atomic_test_and_set_bit(chan->flags, ATT_OUT_OF_SYNC_SENT)) { in att_read_mult_vl_req()
1819 data.buf = bt_att_create_rsp_pdu(chan, BT_ATT_OP_READ_MULT_VL_RSP); in att_read_mult_vl_req()
1824 data.chan = chan; in att_read_mult_vl_req()
1842 send_err_rsp(chan, BT_ATT_OP_READ_MULT_VL_REQ, handle, in att_read_mult_vl_req()
1848 bt_att_chan_send_rsp(chan, data.buf); in att_read_mult_vl_req()
1855 struct bt_att_chan *chan; member
1884 struct bt_att_chan *chan = data->chan; in read_group_cb() local
1907 bt_att_mtu(chan) - data->buf->len < data->rsp->len) { in read_group_cb()
1919 read = att_chan_read(chan, attr, data->buf, 0, attr_read_group_cb, in read_group_cb()
1934 static uint8_t att_read_group_rsp(struct bt_att_chan *chan, struct bt_uuid *uuid, in att_read_group_rsp() argument
1941 data.buf = bt_att_create_rsp_pdu(chan, BT_ATT_OP_READ_GROUP_RSP); in att_read_group_rsp()
1946 data.chan = chan; in att_read_group_rsp()
1957 send_err_rsp(chan, BT_ATT_OP_READ_GROUP_REQ, start_handle, in att_read_group_rsp()
1962 bt_att_chan_send_rsp(chan, data.buf); in att_read_group_rsp()
1967 static uint8_t att_read_group_req(struct bt_att_chan *chan, struct net_buf *buf) in att_read_group_req() argument
1996 send_err_rsp(chan, BT_ATT_OP_READ_GROUP_REQ, err_handle, in att_read_group_req()
2010 send_err_rsp(chan, BT_ATT_OP_READ_GROUP_REQ, start_handle, in att_read_group_req()
2015 return att_read_group_rsp(chan, &u.uuid, start_handle, end_handle); in att_read_group_req()
2084 static uint8_t att_write_rsp(struct bt_att_chan *chan, uint8_t req, uint8_t rsp, in att_write_rsp() argument
2090 if (!bt_gatt_change_aware(chan->att->conn, req ? true : false)) { in att_write_rsp()
2091 if (!atomic_test_and_set_bit(chan->flags, ATT_OUT_OF_SYNC_SENT)) { in att_write_rsp()
2106 data.buf = bt_att_chan_create_pdu(chan, rsp, 0); in att_write_rsp()
2112 data.conn = chan->att->conn; in att_write_rsp()
2126 send_err_rsp(chan, req, handle, data.err); in att_write_rsp()
2132 bt_att_chan_send_rsp(chan, data.buf); in att_write_rsp()
2138 static uint8_t att_write_req(struct bt_att_chan *chan, struct net_buf *buf) in att_write_req() argument
2146 return att_write_rsp(chan, BT_ATT_OP_WRITE_REQ, BT_ATT_OP_WRITE_RSP, in att_write_req()
2214 static uint8_t att_prep_write_rsp(struct bt_att_chan *chan, uint16_t handle, in att_prep_write_rsp() argument
2220 if (!bt_gatt_change_aware(chan->att->conn, true)) { in att_prep_write_rsp()
2221 if (!atomic_test_and_set_bit(chan->flags, ATT_OUT_OF_SYNC_SENT)) { in att_prep_write_rsp()
2234 data.conn = chan->att->conn; in att_prep_write_rsp()
2244 send_err_rsp(chan, BT_ATT_OP_PREPARE_WRITE_REQ, handle, in att_prep_write_rsp()
2252 net_buf_slist_put(&chan->att->prep_queue, data.buf); in att_prep_write_rsp()
2255 data.buf = bt_att_create_rsp_pdu(chan, BT_ATT_OP_PREPARE_WRITE_RSP); in att_prep_write_rsp()
2266 bt_att_chan_send_rsp(chan, data.buf); in att_prep_write_rsp()
2272 static uint8_t att_prepare_write_req(struct bt_att_chan *chan, struct net_buf *buf) in att_prepare_write_req() argument
2287 return att_prep_write_rsp(chan, handle, offset, buf->data, buf->len); in att_prepare_write_req()
2345 static uint8_t att_exec_write_rsp(struct bt_att_chan *chan, uint8_t flags) in att_exec_write_rsp() argument
2355 while (!sys_slist_is_empty(&chan->att->prep_queue)) { in att_exec_write_rsp()
2363 buf = net_buf_slist_get(&chan->att->prep_queue); in att_exec_write_rsp()
2373 &chan->att->prep_queue, in att_exec_write_rsp()
2376 send_err_rsp(chan, BT_ATT_OP_EXEC_WRITE_REQ, in att_exec_write_rsp()
2383 err = att_write_rsp(chan, BT_ATT_OP_EXEC_WRITE_REQ, 0, in att_exec_write_rsp()
2389 send_err_rsp(chan, BT_ATT_OP_EXEC_WRITE_REQ, in att_exec_write_rsp()
2402 buf = bt_att_create_rsp_pdu(chan, BT_ATT_OP_EXEC_WRITE_RSP); in att_exec_write_rsp()
2407 bt_att_chan_send_rsp(chan, buf); in att_exec_write_rsp()
2414 static uint8_t att_exec_write_req(struct bt_att_chan *chan, struct net_buf *buf) in att_exec_write_req() argument
2425 return att_exec_write_rsp(chan, req->flags); in att_exec_write_req()
2429 static uint8_t att_write_cmd(struct bt_att_chan *chan, struct net_buf *buf) in att_write_cmd() argument
2437 return att_write_rsp(chan, 0, 0, handle, 0, buf->data, buf->len); in att_write_cmd()
2441 static uint8_t att_signed_write_cmd(struct bt_att_chan *chan, struct net_buf *buf) in att_signed_write_cmd() argument
2443 struct bt_conn *conn = chan->chan.chan.conn; in att_signed_write_cmd()
2451 if (bt_att_is_enhanced(chan)) { in att_signed_write_cmd()
2474 return att_write_rsp(chan, 0, 0, handle, 0, buf->data, in att_signed_write_cmd()
2543 static uint8_t att_error_rsp(struct bt_att_chan *chan, struct net_buf *buf) in att_error_rsp() argument
2564 if (!chan->req || chan->req == &cancel || !rsp->error) { in att_error_rsp()
2575 ret = att_change_security(chan->chan.chan.conn, err); in att_error_rsp()
2581 k_work_cancel_delayable(&chan->timeout_work); in att_error_rsp()
2583 chan->req->retrying = true; in att_error_rsp()
2589 return att_handle_rsp(chan, NULL, 0, err); in att_error_rsp()
2592 static uint8_t att_handle_find_info_rsp(struct bt_att_chan *chan, in att_handle_find_info_rsp() argument
2597 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_find_info_rsp()
2600 static uint8_t att_handle_find_type_rsp(struct bt_att_chan *chan, in att_handle_find_type_rsp() argument
2605 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_find_type_rsp()
2608 static uint8_t att_handle_read_type_rsp(struct bt_att_chan *chan, in att_handle_read_type_rsp() argument
2613 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_read_type_rsp()
2616 static uint8_t att_handle_read_rsp(struct bt_att_chan *chan, in att_handle_read_rsp() argument
2621 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_read_rsp()
2624 static uint8_t att_handle_read_blob_rsp(struct bt_att_chan *chan, in att_handle_read_blob_rsp() argument
2629 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_read_blob_rsp()
2633 static uint8_t att_handle_read_mult_rsp(struct bt_att_chan *chan, in att_handle_read_mult_rsp() argument
2638 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_read_mult_rsp()
2644 static uint8_t att_handle_read_mult_vl_rsp(struct bt_att_chan *chan, in att_handle_read_mult_vl_rsp() argument
2649 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_read_mult_vl_rsp()
2653 static uint8_t att_handle_read_group_rsp(struct bt_att_chan *chan, in att_handle_read_group_rsp() argument
2658 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_read_group_rsp()
2661 static uint8_t att_handle_write_rsp(struct bt_att_chan *chan, in att_handle_write_rsp() argument
2666 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_write_rsp()
2669 static uint8_t att_handle_prepare_write_rsp(struct bt_att_chan *chan, in att_handle_prepare_write_rsp() argument
2674 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_prepare_write_rsp()
2677 static uint8_t att_handle_exec_write_rsp(struct bt_att_chan *chan, in att_handle_exec_write_rsp() argument
2682 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_handle_exec_write_rsp()
2685 static uint8_t att_notify(struct bt_att_chan *chan, struct net_buf *buf) in att_notify() argument
2691 LOG_DBG("chan %p handle 0x%04x", chan, handle); in att_notify()
2693 bt_gatt_notification(chan->att->conn, handle, buf->data, buf->len); in att_notify()
2698 static uint8_t att_indicate(struct bt_att_chan *chan, struct net_buf *buf) in att_indicate() argument
2704 LOG_DBG("chan %p handle 0x%04x", chan, handle); in att_indicate()
2706 bt_gatt_notification(chan->att->conn, handle, buf->data, buf->len); in att_indicate()
2708 buf = bt_att_chan_create_pdu(chan, BT_ATT_OP_CONFIRM, 0); in att_indicate()
2713 bt_att_chan_send_rsp(chan, buf); in att_indicate()
2718 static uint8_t att_notify_mult(struct bt_att_chan *chan, struct net_buf *buf) in att_notify_mult() argument
2720 LOG_DBG("chan %p", chan); in att_notify_mult()
2722 bt_gatt_mult_notification(chan->att->conn, buf->data, buf->len); in att_notify_mult()
2728 static uint8_t att_confirm(struct bt_att_chan *chan, struct net_buf *buf) in att_confirm() argument
2732 return att_handle_rsp(chan, buf->data, buf->len, 0); in att_confirm()
2739 uint8_t (*func)(struct bt_att_chan *chan, struct net_buf *buf);
2931 return att_chan->chan.chan.conn; in get_conn()
2934 static int bt_att_recv(struct bt_l2cap_chan *chan, struct net_buf *buf) in bt_att_recv() argument
2936 struct bt_att_chan *att_chan = ATT_CHAN(chan); in bt_att_recv()
2996 struct bt_l2cap_chan *chan; in att_get() local
3004 chan = bt_l2cap_le_lookup_rx_cid(conn, BT_L2CAP_CID_ATT); in att_get()
3005 if (!chan) { in att_get()
3010 att_chan = ATT_CHAN(chan); in att_get()
3022 struct bt_att_chan *chan, *tmp; in bt_att_create_pdu() local
3030 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&att->chans, chan, tmp, node) { in bt_att_create_pdu()
3031 if (len + sizeof(op) > bt_att_mtu(chan)) { in bt_att_create_pdu()
3035 return bt_att_chan_create_pdu(chan, op, len); in bt_att_create_pdu()
3043 struct net_buf *bt_att_create_rsp_pdu(struct bt_att_chan *chan, uint8_t op) in bt_att_create_rsp_pdu() argument
3058 if (bt_att_is_enhanced(chan)) { in bt_att_create_rsp_pdu()
3065 data->att_chan = chan; in bt_att_create_rsp_pdu()
3116 static void att_chan_detach(struct bt_att_chan *chan) in att_chan_detach() argument
3120 LOG_DBG("chan %p", chan); in att_chan_detach()
3122 sys_slist_find_and_remove(&chan->att->chans, &chan->node); in att_chan_detach()
3125 while ((buf = k_fifo_get(&chan->tx_queue, K_NO_WAIT))) { in att_chan_detach()
3129 if (chan->req) { in att_chan_detach()
3131 att_handle_rsp(chan, NULL, 0, -ECONNRESET); in att_chan_detach()
3134 chan->att = NULL; in att_chan_detach()
3135 atomic_clear_bit(chan->flags, ATT_CONNECTED); in att_chan_detach()
3142 struct bt_att_chan *chan = CONTAINER_OF(dwork, struct bt_att_chan, in att_timeout() local
3146 bt_addr_le_to_str(bt_conn_get_dst(chan->att->conn), addr, sizeof(addr)); in att_timeout()
3157 bt_att_disconnected(&chan->chan.chan); in att_timeout()
3164 err = bt_conn_disconnect(chan->chan.chan.conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); in att_timeout()
3172 struct bt_l2cap_chan *chan; in att_get_fixed_chan() local
3174 chan = bt_l2cap_le_lookup_tx_cid(conn, BT_L2CAP_CID_ATT); in att_get_fixed_chan()
3175 __ASSERT(chan, "No ATT channel found"); in att_get_fixed_chan()
3177 return ATT_CHAN(chan); in att_get_fixed_chan()
3180 static void att_chan_attach(struct bt_att *att, struct bt_att_chan *chan) in att_chan_attach() argument
3182 LOG_DBG("att %p chan %p flags %lu", att, chan, atomic_get(chan->flags)); in att_chan_attach()
3192 sys_slist_prepend(&att->chans, &chan->node); in att_chan_attach()
3195 static void bt_att_connected(struct bt_l2cap_chan *chan) in bt_att_connected() argument
3197 struct bt_att_chan *att_chan = ATT_CHAN(chan); in bt_att_connected()
3198 struct bt_l2cap_le_chan *le_chan = BT_L2CAP_LE_CHAN(chan); in bt_att_connected()
3208 bt_gatt_connected(le_chan->chan.conn); in bt_att_connected()
3211 static void bt_att_disconnected(struct bt_l2cap_chan *chan) in bt_att_disconnected() argument
3213 struct bt_att_chan *att_chan = ATT_CHAN(chan); in bt_att_disconnected()
3215 struct bt_l2cap_le_chan *le_chan = BT_L2CAP_LE_CHAN(chan); in bt_att_disconnected()
3233 bt_gatt_disconnected(le_chan->chan.conn); in bt_att_disconnected()
3267 static void bt_att_encrypt_change(struct bt_l2cap_chan *chan, in bt_att_encrypt_change() argument
3270 struct bt_att_chan *att_chan = ATT_CHAN(chan); in bt_att_encrypt_change()
3271 struct bt_l2cap_le_chan *le_chan = BT_L2CAP_LE_CHAN(chan); in bt_att_encrypt_change()
3272 struct bt_conn *conn = le_chan->chan.conn; in bt_att_encrypt_change()
3318 struct bt_att_chan *chan = ATT_CHAN(ch); in bt_att_status() local
3327 if (!chan->att) { in bt_att_status()
3333 if (chan->req) { in bt_att_status()
3338 node = sys_slist_get(&chan->att->reqs); in bt_att_status()
3343 if (bt_att_chan_req_send(chan, ATT_REQ(node)) >= 0) { in bt_att_status()
3348 sys_slist_prepend(&chan->att->reqs, node); in bt_att_status()
3353 struct bt_att_chan *chan = ATT_CHAN(ch); in bt_att_released() local
3355 LOG_DBG("chan %p", chan); in bt_att_released()
3357 k_mem_slab_free(&chan_slab, (void *)chan); in bt_att_released()
3388 struct bt_att_chan *chan; in att_chan_new() local
3390 SYS_SLIST_FOR_EACH_CONTAINER(&att->chans, chan, node) { in att_chan_new()
3391 if (chan->att == att) { in att_chan_new()
3401 if (k_mem_slab_alloc(&chan_slab, (void **)&chan, K_NO_WAIT)) { in att_chan_new()
3406 (void)memset(chan, 0, sizeof(*chan)); in att_chan_new()
3407 chan->chan.chan.ops = &ops; in att_chan_new()
3408 k_fifo_init(&chan->tx_queue); in att_chan_new()
3409 atomic_set(chan->flags, flags); in att_chan_new()
3410 chan->att = att; in att_chan_new()
3411 att_chan_attach(att, chan); in att_chan_new()
3413 if (bt_att_is_enhanced(chan)) { in att_chan_new()
3417 chan->chan.rx.mtu = BT_LOCAL_ATT_MTU_EATT; in att_chan_new()
3423 chan->chan.tx.mtu = BT_ATT_DEFAULT_LE_MTU; in att_chan_new()
3424 chan->chan.rx.mtu = BT_ATT_DEFAULT_LE_MTU; in att_chan_new()
3427 return chan; in att_chan_new()
3434 struct bt_att_chan *chan; in bt_eatt_count() local
3446 SYS_SLIST_FOR_EACH_CONTAINER(&att->chans, chan, node) { in bt_eatt_count()
3447 if (bt_att_is_enhanced(chan) && in bt_eatt_count()
3448 atomic_test_bit(chan->flags, ATT_CONNECTED)) { in bt_eatt_count()
3477 struct bt_att_chan *chan; in bt_att_accept() local
3498 chan = att_chan_new(att, 0); in bt_att_accept()
3499 if (!chan) { in bt_att_accept()
3503 *ch = &chan->chan.chan; in bt_att_accept()
3639 struct bt_l2cap_chan *chan[CONFIG_BT_EATT_MAX + 1] = {}; in bt_eatt_connect() local
3669 chan[i] = &att_chan->chan.chan; in bt_eatt_connect()
3681 err = bt_l2cap_ecred_chan_connect(conn, &chan[offset], BT_EATT_PSM); in bt_eatt_connect()
3718 struct bt_att_chan *chan; in bt_eatt_disconnect() local
3726 chan = att_get_fixed_chan(conn); in bt_eatt_disconnect()
3727 att = chan->att; in bt_eatt_disconnect()
3729 SYS_SLIST_FOR_EACH_CONTAINER(&att->chans, chan, node) { in bt_eatt_disconnect()
3730 if (bt_att_is_enhanced(chan)) { in bt_eatt_disconnect()
3731 err = bt_l2cap_chan_disconnect(&chan->chan.chan); in bt_eatt_disconnect()
3742 struct bt_att_chan *chan; in bt_eatt_disconnect_one() local
3748 chan = att_get_fixed_chan(conn); in bt_eatt_disconnect_one()
3749 att = chan->att; in bt_eatt_disconnect_one()
3751 SYS_SLIST_FOR_EACH_CONTAINER(&att->chans, chan, node) { in bt_eatt_disconnect_one()
3752 if (bt_att_is_enhanced(chan)) { in bt_eatt_disconnect_one()
3753 return bt_l2cap_chan_disconnect(&chan->chan.chan); in bt_eatt_disconnect_one()
3771 chans[i] = &att_chan->chan.chan; in bt_eatt_reconfigure()
3794 struct bt_l2cap_chan **chan) in bt_eatt_accept() argument
3803 *chan = &att_chan->chan.chan; in bt_eatt_accept()
3852 struct bt_att_chan *chan, *tmp; in bt_att_get_mtu() local
3861 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&att->chans, chan, tmp, node) { in bt_att_get_mtu()
3862 if (bt_att_mtu(chan) > mtu) { in bt_att_get_mtu()
3863 mtu = bt_att_mtu(chan); in bt_att_get_mtu()
3872 struct bt_att_chan *chan, *tmp; in bt_att_get_uatt_mtu() local
3880 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&att->chans, chan, tmp, node) { in bt_att_get_uatt_mtu()
3881 if (!bt_att_is_enhanced(chan)) { in bt_att_get_uatt_mtu()
3882 return bt_att_mtu(chan); in bt_att_get_uatt_mtu()
3894 struct bt_att_chan *chan, *tmp; in att_chan_mtu_updated() local
3898 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&att->chans, chan, tmp, node) { in att_chan_mtu_updated()
3899 if (chan == updated_chan) { in att_chan_mtu_updated()
3902 max_tx = MAX(max_tx, chan->chan.tx.mtu); in att_chan_mtu_updated()
3903 max_rx = MAX(max_rx, chan->chan.rx.mtu); in att_chan_mtu_updated()
3907 if ((updated_chan->chan.tx.mtu > max_tx) || in att_chan_mtu_updated()
3908 (updated_chan->chan.rx.mtu > max_rx)) { in att_chan_mtu_updated()
3909 max_tx = MAX(max_tx, updated_chan->chan.tx.mtu); in att_chan_mtu_updated()
3910 max_rx = MAX(max_rx, updated_chan->chan.rx.mtu); in att_chan_mtu_updated()
3996 static bool bt_att_chan_req_cancel(struct bt_att_chan *chan, in bt_att_chan_req_cancel() argument
3999 if (chan->req != req) { in bt_att_chan_req_cancel()
4003 chan->req = &cancel; in bt_att_chan_req_cancel()
4013 struct bt_att_chan *chan, *tmp; in bt_att_req_cancel() local
4026 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&att->chans, chan, tmp, node) { in bt_att_req_cancel()
4028 if (bt_att_chan_req_cancel(chan, req)) { in bt_att_req_cancel()
4042 struct bt_att_chan *chan; in bt_att_find_req_by_user_data() local
4050 SYS_SLIST_FOR_EACH_CONTAINER(&att->chans, chan, node) { in bt_att_find_req_by_user_data()
4051 if (chan->req->user_data == user_data) { in bt_att_find_req_by_user_data()
4052 return chan->req; in bt_att_find_req_by_user_data()
4077 struct bt_att_chan *chan; in bt_att_clear_out_of_sync_sent() local
4083 SYS_SLIST_FOR_EACH_CONTAINER(&att->chans, chan, node) { in bt_att_clear_out_of_sync_sent()
4084 atomic_clear_bit(chan->flags, ATT_OUT_OF_SYNC_SENT); in bt_att_clear_out_of_sync_sent()