Lines Matching +full:rx +full:- +full:wake +full:- +full:timeout
1 /* conn.c - Bluetooth connection handling */
4 * Copyright (c) 2015-2016 Intel Corporation
6 * SPDX-License-Identifier: Apache-2.0
66 bt_conn_tx_cb_t cb = tx->cb; in conn_tx_destroy()
67 void *user_data = tx->user_data; in conn_tx_destroy()
77 cb(conn, user_data, -ESHUTDOWN); in conn_tx_destroy()
91 /* Peripheral timeout to initialize Connection Parameter Update procedure */
123 /* TODO: remove user-data requirements */
140 bt_buf_destroy_view(frag, &get_frag_md(frag)->view_meta); in frag_destroy()
161 winsize, &get_frag_md(window)->view_meta); in get_data_frag()
163 LOG_DBG("get-acl-frag: outside %p window %p size %zu", outside, window, winsize); in get_data_frag()
200 if (conn->type == BT_CONN_TYPE_BR || !bt_dev.le.acl_mtu) { in bt_conn_get_pkts()
209 if (conn->type == BT_CONN_TYPE_ISO) { in bt_conn_get_pkts()
233 return "disconnect-complete"; in state2str()
237 return "scan-before-initiating"; in state2str()
239 return "initiating-filter-list"; in state2str()
241 return "adv-connectable"; in state2str()
243 return "adv-dir-connectable"; in state2str()
256 tx->cb = NULL; in tx_free()
257 tx->user_data = NULL; in tx_free()
285 if (!sys_slist_is_empty(&conn->tx_complete)) { in tx_notify_process()
286 const sys_snode_t *node = sys_slist_get_not_empty(&conn->tx_complete); in tx_notify_process()
296 LOG_DBG("tx %p cb %p user_data %p", tx, tx->cb, tx->user_data); in tx_notify_process()
299 cb = tx->cb; in tx_notify_process()
300 user_data = tx->user_data; in tx_notify_process()
329 err = k_work_submit_to_queue(tx_notify_workqueue_get(), &conn->tx_complete_work); in bt_conn_tx_notify()
333 (void)k_work_flush(&conn->tx_complete_work, &sync); in bt_conn_tx_notify()
361 k_work_init_delayable(&conn->deferred_work, deferred_work); in bt_conn_new()
364 k_work_init(&conn->tx_complete_work, tx_complete_work); in bt_conn_new()
372 if (!conn->rx) { in bt_conn_reset_rx_state()
376 net_buf_unref(conn->rx); in bt_conn_reset_rx_state()
377 conn->rx = NULL; in bt_conn_reset_rx_state()
389 if (conn->rx) { in bt_acl_recv()
394 LOG_DBG("First, len %u final %u", buf->len, in bt_acl_recv()
395 (buf->len < sizeof(uint16_t)) ? 0 : sys_get_le16(buf->data)); in bt_acl_recv()
397 conn->rx = net_buf_ref(buf); in bt_acl_recv()
400 if (!conn->rx) { in bt_acl_recv()
407 if (!buf->len) { in bt_acl_recv()
413 if (buf->len > net_buf_tailroom(conn->rx)) { in bt_acl_recv()
420 bt_l2cap_recv(conn, conn->rx, false); in bt_acl_recv()
421 conn->rx = NULL; in bt_acl_recv()
426 net_buf_add_mem(conn->rx, buf->data, buf->len); in bt_acl_recv()
430 * LE-U from Controller to Host. in bt_acl_recv()
439 if (conn->rx->len < sizeof(uint16_t)) { in bt_acl_recv()
443 bt_send_one_host_num_completed_packets(conn->handle); in bt_acl_recv()
450 acl_total_len = sys_get_le16(conn->rx->data) + sizeof(struct bt_l2cap_hdr); in bt_acl_recv()
452 if (conn->rx->len < acl_total_len) { in bt_acl_recv()
454 bt_send_one_host_num_completed_packets(conn->handle); in bt_acl_recv()
463 if (conn->rx->len > acl_total_len) { in bt_acl_recv()
464 LOG_ERR("ACL len mismatch (%u > %u)", conn->rx->len, acl_total_len); in bt_acl_recv()
470 buf = conn->rx; in bt_acl_recv()
471 conn->rx = NULL; in bt_acl_recv()
473 __ASSERT(buf->ref == 1, "buf->ref %d", buf->ref); in bt_acl_recv()
475 LOG_DBG("Successfully parsed %u byte L2CAP packet", buf->len); in bt_acl_recv()
489 LOG_DBG("handle %u len %u flags %02x", conn->handle, buf->len, flags); in bt_conn_recv()
491 if (IS_ENABLED(CONFIG_BT_ISO_RX) && conn->type == BT_CONN_TYPE_ISO) { in bt_conn_recv()
497 __ASSERT(false, "Invalid connection type %u", conn->type); in bt_conn_recv()
536 return -EINVAL; in send_acl()
540 hdr->handle = sys_cpu_to_le16(bt_acl_handle_pack(conn->handle, flags)); in send_acl()
541 hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr)); in send_acl()
553 (BT_BUF_ISO_SIZE(0) - sizeof(struct bt_hci_iso_sdu_ts_hdr))) { in contains_iso_timestamp()
581 return -EINVAL; in send_iso()
598 hdr->handle = sys_cpu_to_le16(bt_iso_handle_pack(conn->handle, flags, ts)); in send_iso()
599 hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr)); in send_iso()
609 if (conn->type == BT_CONN_TYPE_BR || in conn_mtu()
610 (conn->type != BT_CONN_TYPE_ISO && !bt_dev.le.acl_mtu)) { in conn_mtu()
615 if (conn->type == BT_CONN_TYPE_ISO) { in conn_mtu()
629 conn->type == BT_CONN_TYPE_BR); in is_classic_conn()
635 conn->type == BT_CONN_TYPE_ISO; in is_iso_tx_conn()
640 return IS_ENABLED(CONFIG_BT_CONN) && conn->type == BT_CONN_TYPE_LE; in is_le_conn()
656 if (buf->len == 0) { in send_buf()
659 return -EMSGSIZE; in send_buf()
665 return -EIO; in send_buf()
668 LOG_DBG("conn %p buf %p len %zu buf->len %u cb %p ud %p", in send_buf()
669 conn, buf, len, buf->len, cb, ud); in send_buf()
675 * "acquire" as `tx_processor()` is not re-entrant and the in send_buf()
676 * thread is non-preemptible. So the sem value shouldn't change. in send_buf()
680 return -ENOMEM; in send_buf()
690 return -ENOMEM; in send_buf()
693 tx->cb = cb; in send_buf()
694 tx->user_data = ud; in send_buf()
698 __ASSERT_NO_MSG(buf->ref == 1); in send_buf()
700 if (buf->len > frag_len) { in send_buf()
716 flags = conn->next_is_frag ? FRAG_CONT : FRAG_START; in send_buf()
717 conn->next_is_frag = true; in send_buf()
719 flags = conn->next_is_frag ? FRAG_END : FRAG_SINGLE; in send_buf()
720 conn->next_is_frag = false; in send_buf()
729 conn, frag, frag->len, flags); in send_buf()
732 * sending, as we might get pre-empted if the HCI driver calls in send_buf()
735 * In that case, the controller could also send a num-complete-packets in send_buf()
739 atomic_inc(&conn->in_ll); in send_buf()
740 sys_slist_append(&conn->tx_pending, &tx->node); in send_buf()
747 err = -EINVAL; /* Some animals disable asserts (╯°□°)╯︵ ┻━┻ */ in send_buf()
748 __ASSERT(false, "Invalid connection type %u", conn->type); in send_buf()
756 atomic_dec(&conn->in_ll); in send_buf()
757 (void)sys_slist_find_and_remove(&conn->tx_pending, &tx->node); in send_buf()
774 return -EIO; in send_buf()
782 if (conn->state == BT_CONN_CONNECTED || in conn_destroy()
783 conn->state == BT_CONN_DISCONNECTING) { in conn_destroy()
787 if (conn->state != BT_CONN_DISCONNECTED) { in conn_destroy()
801 return sys_slist_peek_head(&conn->l2cap_data_ready) != NULL; in acl_has_data()
818 if (conn->state != BT_CONN_CONNECTED) { in should_stop_tx()
825 if (!conn->has_data(conn)) { in should_stop_tx()
830 /* Queue only 3 buffers per-conn for now */ in should_stop_tx()
831 if (atomic_get(&conn->in_ll) < 3) { in should_stop_tx()
832 /* The goal of this heuristic is to allow the link-layer to in should_stop_tx()
837 * packets to be able to set the more-data bit, and one more in should_stop_tx()
839 * being sent over-the-air. in should_stop_tx()
852 if (!atomic_set(&conn->_conn_ready_lock, 1)) { in bt_conn_data_ready()
860 &conn->_conn_ready); in bt_conn_data_ready()
896 return (conn->tx_data_pull == NULL) || in dont_have_methods()
897 (conn->get_and_clear_cb == NULL) || in dont_have_methods()
898 (conn->has_data == NULL); in dont_have_methods()
942 conn, conn->type); in get_conn_ready()
952 (void)atomic_set(&conn->_conn_ready_lock, 0); in get_conn_ready()
955 if (conn->has_data(conn)) { in get_conn_ready()
973 *cb = closure_cb(buf->user_data); in acl_get_and_clear_cb()
974 *ud = closure_data(buf->user_data); in acl_get_and_clear_cb()
975 memset(buf->user_data, 0, buf->user_data_size); in acl_get_and_clear_cb()
979 /* Acts as a "null-routed" bt_send(). This fn will decrease the refcount of
988 conn->get_and_clear_cb(conn, buf, &cb, &ud); in destroy_and_callback()
999 cb(conn, ud, -ESHUTDOWN); in destroy_and_callback()
1043 if (conn->state != BT_CONN_CONNECTED) { in bt_conn_tx_processor()
1046 /* Call the user callbacks & destroy (final-unref) the buffers in bt_conn_tx_processor()
1049 buf = conn->tx_data_pull(conn, SIZE_MAX, &buf_len); in bt_conn_tx_processor()
1052 buf = conn->tx_data_pull(conn, SIZE_MAX, &buf_len); in bt_conn_tx_processor()
1061 buf = conn->tx_data_pull(conn, conn_mtu(conn), &buf_len); in bt_conn_tx_processor()
1063 /* Either there is no more data, or the buffer is already in-use in bt_conn_tx_processor()
1077 * We still allocate one TX context per-fragment though. in bt_conn_tx_processor()
1079 conn->get_and_clear_cb(conn, buf, &cb, &ud); in bt_conn_tx_processor()
1089 /* -EIO means `unrecoverable error`. It can be an assertion that in bt_conn_tx_processor()
1092 * -ENOMEM means we thought we had all the resources to send the in bt_conn_tx_processor()
1095 * assumption, likely that we have been pre-empted somehow and in bt_conn_tx_processor()
1096 * that `tx_processor()` has been re-entered. in bt_conn_tx_processor()
1108 /* Always kick the TX work. It will self-suspend if it doesn't get in bt_conn_tx_processor()
1127 node = sys_slist_get(&conn->tx_pending); in process_unack_tx()
1159 if (conn->handle != handle) { in conn_lookup_handle()
1174 LOG_DBG("%s -> %s", state2str(conn->state), state2str(state)); in bt_conn_set_state()
1176 if (conn->state == state) { in bt_conn_set_state()
1181 old_state = conn->state; in bt_conn_set_state()
1182 conn->state = state; in bt_conn_set_state()
1191 if (conn->type != BT_CONN_TYPE_ISO) { in bt_conn_set_state()
1197 conn->type == BT_CONN_TYPE_LE) { in bt_conn_set_state()
1198 k_work_cancel_delayable(&conn->deferred_work); in bt_conn_set_state()
1206 switch (conn->state) { in bt_conn_set_state()
1208 if (conn->type == BT_CONN_TYPE_SCO) { in bt_conn_set_state()
1217 conn->type == BT_CONN_TYPE_ISO) { in bt_conn_set_state()
1223 sys_slist_init(&conn->channels); in bt_conn_set_state()
1226 conn->role == BT_CONN_ROLE_PERIPHERAL) { in bt_conn_set_state()
1229 if (conn->type == BT_CONN_TYPE_LE) { in bt_conn_set_state()
1230 conn->le.conn_param_retry_countdown = in bt_conn_set_state()
1235 k_work_schedule(&conn->deferred_work, in bt_conn_set_state()
1243 if (conn->type == BT_CONN_TYPE_SCO) { in bt_conn_set_state()
1251 /* Notify disconnection and queue a dummy buffer to wake in bt_conn_set_state()
1260 k_work_cancel_delayable(&conn->deferred_work); in bt_conn_set_state()
1267 k_work_reschedule(&conn->deferred_work, K_NO_WAIT); in bt_conn_set_state()
1276 if (conn->err) { in bt_conn_set_state()
1286 * timeout set by bt_conn_le_create_param.timeout. in bt_conn_set_state()
1296 if (conn->err) { in bt_conn_set_state()
1304 if (conn->err) { in bt_conn_set_state()
1319 * advertiser, conn->err is never set in this case. in bt_conn_set_state()
1340 if (conn->type == BT_CONN_TYPE_SCO) { in bt_conn_set_state()
1345 * will handle connection timeout. in bt_conn_set_state()
1348 conn->type == BT_CONN_TYPE_LE && in bt_conn_set_state()
1349 bt_dev.create_param.timeout != 0) { in bt_conn_set_state()
1350 k_work_schedule(&conn->deferred_work, in bt_conn_set_state()
1351 K_MSEC(10 * bt_dev.create_param.timeout)); in bt_conn_set_state()
1359 if (conn->err == BT_HCI_ERR_CONN_FAIL_TO_ESTAB) { in bt_conn_set_state()
1405 if (type & conn->type) { in bt_conn_lookup_handle()
1433 if (!(conn->type & type)) { in bt_conn_foreach()
1481 * Loop on clear-and-set in case someone has modified the reference in bt_conn_ref()
1485 old = atomic_get(&conn->ref); in bt_conn_ref()
1490 } while (!atomic_cas(&conn->ref, old, old + 1)); in bt_conn_ref()
1492 LOG_DBG("handle %u ref %ld -> %ld", conn->handle, old, old + 1); in bt_conn_ref()
1520 * after decrementing its ref-count in bt_conn_unref()
1522 conn_type = conn->type; in bt_conn_unref()
1523 conn_role = conn->role; in bt_conn_unref()
1524 conn_handle = conn->handle; in bt_conn_unref()
1526 old = atomic_dec(&conn->ref); in bt_conn_unref()
1531 LOG_DBG("handle %u ref %ld -> %ld", conn_handle, old, (old - 1)); in bt_conn_unref()
1553 switch (conn->type) { in bt_conn_index()
1556 index = conn - iso_conns; in bt_conn_index()
1563 index = conn - sco_conns; in bt_conn_index()
1570 index = conn - acl_conns; in bt_conn_index()
1574 __ASSERT(false, "Invalid connection type %u", conn->type); in bt_conn_index()
1586 k_timeout_t timeout, in bt_conn_create_pdu_timeout_debug() argument
1590 size_t reserve, k_timeout_t timeout) in bt_conn_create_pdu_timeout_debug()
1601 if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT) && in bt_conn_create_pdu_timeout_debug()
1603 LOG_WRN("Timeout discarded. No blocking in syswq."); in bt_conn_create_pdu_timeout_debug()
1604 timeout = K_NO_WAIT; in bt_conn_create_pdu_timeout_debug()
1624 buf = net_buf_alloc_fixed_debug(pool, timeout, func, in bt_conn_create_pdu_timeout_debug()
1627 buf = net_buf_alloc(pool, timeout); in bt_conn_create_pdu_timeout_debug()
1632 buf = net_buf_alloc_fixed_debug(pool, timeout, func, in bt_conn_create_pdu_timeout_debug()
1635 buf = net_buf_alloc(pool, timeout); in bt_conn_create_pdu_timeout_debug()
1640 LOG_WRN("Unable to allocate buffer within timeout"); in bt_conn_create_pdu_timeout_debug()
1665 if (callback->recycled) { in notify_recycled_conn_slot()
1666 callback->recycled(); in notify_recycled_conn_slot()
1671 if (cb->recycled) { in notify_recycled_conn_slot()
1672 cb->recycled(); in notify_recycled_conn_slot()
1703 if (conn->le.phy.tx_phy == BT_HCI_LE_PHY_2M && in uses_symmetric_2mbit_phy()
1704 conn->le.phy.rx_phy == BT_HCI_LE_PHY_2M) { in uses_symmetric_2mbit_phy()
1718 * peripheral-initiated feature exchange is an optional feature. in can_initiate_feature_exchange()
1725 if (IS_ENABLED(CONFIG_BT_CENTRAL) && (conn->role == BT_HCI_ROLE_CENTRAL)) { in can_initiate_feature_exchange()
1742 LOG_DBG("[%p] Running auto-initiated procedures", conn); in perform_auto_initiated_procedures()
1744 if (conn->state != BT_CONN_CONNECTED) { in perform_auto_initiated_procedures()
1752 if (atomic_test_and_set_bit(conn->flags, BT_CONN_AUTO_INIT_PROCEDURES_DONE)) { in perform_auto_initiated_procedures()
1753 /* We have already run the auto-initiated procedures */ in perform_auto_initiated_procedures()
1757 if (!atomic_test_bit(conn->flags, BT_CONN_LE_FEATURES_EXCHANGED) && in perform_auto_initiated_procedures()
1763 if (conn->state != BT_CONN_CONNECTED) { in perform_auto_initiated_procedures()
1769 !atomic_test_bit(conn->flags, BT_CONN_AUTO_VERSION_INFO)) { in perform_auto_initiated_procedures()
1774 if (conn->state != BT_CONN_CONNECTED) { in perform_auto_initiated_procedures()
1786 if (conn->state != BT_CONN_CONNECTED) { in perform_auto_initiated_procedures()
1807 LOG_DBG("[%p] Successfully ran auto-initiated procedures", conn); in perform_auto_initiated_procedures()
1811 * - read remote features
1812 * - read remote version
1813 * - update PHY
1814 * - update data length
1827 LOG_DBG("[%p] Scheduling auto-init procedures", conn); in schedule_auto_initiated_procedures()
1842 err = bt_hci_disconnect(conn->handle, reason); in conn_disconnect()
1847 if (conn->state == BT_CONN_CONNECTED) { in conn_disconnect()
1856 switch (conn->state) { in bt_conn_disconnect()
1858 conn->err = reason; in bt_conn_disconnect()
1865 if (conn->type == BT_CONN_TYPE_LE) { in bt_conn_disconnect()
1867 k_work_cancel_delayable(&conn->deferred_work); in bt_conn_disconnect()
1872 else if (conn->type == BT_CONN_TYPE_ISO) { in bt_conn_disconnect()
1877 else if (conn->type == BT_CONN_TYPE_BR) { in bt_conn_disconnect()
1882 __ASSERT(false, "Invalid conn type %u", conn->type); in bt_conn_disconnect()
1892 return -ENOTCONN; in bt_conn_disconnect()
1902 if (callback->connected) { in notify_connected()
1903 callback->connected(conn, conn->err); in notify_connected()
1908 if (cb->connected) { in notify_connected()
1909 cb->connected(conn, conn->err); in notify_connected()
1919 if (callback->disconnected) { in notify_disconnected()
1920 callback->disconnected(conn, conn->err); in notify_disconnected()
1925 if (cb->disconnected) { in notify_disconnected()
1926 cb->disconnected(conn, conn->err); in notify_disconnected()
1946 if (callback->remote_info_available) { in notify_remote_info()
1947 callback->remote_info_available(conn, &remote_info); in notify_remote_info()
1952 if (cb->remote_info_available) { in notify_remote_info()
1953 cb->remote_info_available(conn, &remote_info); in notify_remote_info()
1962 * parameters don't send peripheral conn param request anymore on timeout in notify_le_param_updated()
1964 if (atomic_test_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_SET) && in notify_le_param_updated()
1965 conn->le.interval >= conn->le.interval_min && in notify_le_param_updated()
1966 conn->le.interval <= conn->le.interval_max && in notify_le_param_updated()
1967 conn->le.latency == conn->le.pending_latency && in notify_le_param_updated()
1968 conn->le.timeout == conn->le.pending_timeout) { in notify_le_param_updated()
1969 atomic_clear_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_SET); in notify_le_param_updated()
1975 if (callback->le_param_updated) { in notify_le_param_updated()
1976 callback->le_param_updated(conn, conn->le.interval, in notify_le_param_updated()
1977 conn->le.latency, in notify_le_param_updated()
1978 conn->le.timeout); in notify_le_param_updated()
1983 if (cb->le_param_updated) { in notify_le_param_updated()
1984 cb->le_param_updated(conn, conn->le.interval, in notify_le_param_updated()
1985 conn->le.latency, in notify_le_param_updated()
1986 conn->le.timeout); in notify_le_param_updated()
1997 if (callback->le_data_len_updated) { in notify_le_data_len_updated()
1998 callback->le_data_len_updated(conn, &conn->le.data_len); in notify_le_data_len_updated()
2003 if (cb->le_data_len_updated) { in notify_le_data_len_updated()
2004 cb->le_data_len_updated(conn, &conn->le.data_len); in notify_le_data_len_updated()
2016 if (callback->le_phy_updated) { in notify_le_phy_updated()
2017 callback->le_phy_updated(conn, &conn->le.phy); in notify_le_phy_updated()
2022 if (cb->le_phy_updated) { in notify_le_phy_updated()
2023 cb->le_phy_updated(conn, &conn->le.phy); in notify_le_phy_updated()
2038 if (!callback->le_param_req) { in le_param_req()
2042 if (!callback->le_param_req(conn, param)) { in le_param_req()
2047 * double-check that it returned valid parameters. in le_param_req()
2055 if (!cb->le_param_req) { in le_param_req()
2059 if (!cb->le_param_req(conn, param)) { in le_param_req()
2064 * double-check that it returned valid parameters. in le_param_req()
2078 LOG_DBG("conn %p features 0x%02x params (%d-%d %d %d)", conn, conn->le.features[0], in send_conn_le_param_update()
2079 param->interval_min, param->interval_max, param->latency, param->timeout); in send_conn_le_param_update()
2083 return -EINVAL; in send_conn_le_param_update()
2090 BT_FEAT_LE_CONN_PARAM_REQ_PROC(conn->le.features) && in send_conn_le_param_update()
2091 !atomic_test_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_L2CAP)) || in send_conn_le_param_update()
2092 (conn->role == BT_HCI_ROLE_CENTRAL)) { in send_conn_le_param_update()
2099 conn->le.interval_min = param->interval_min; in send_conn_le_param_update()
2100 conn->le.interval_max = param->interval_max; in send_conn_le_param_update()
2101 conn->le.pending_latency = param->latency; in send_conn_le_param_update()
2102 conn->le.pending_timeout = param->timeout; in send_conn_le_param_update()
2126 if (iso->iso.acl == conn) { in conn_lookup_iso()
2149 if (sco->sco.acl == conn) { in conn_lookup_sco()
2168 if (conn->state == BT_CONN_DISCONNECTED) { in deferred_work()
2172 if (conn->type == BT_CONN_TYPE_ISO) { in deferred_work()
2187 struct bt_iso_chan *chan = iso->iso.chan; in deferred_work()
2209 struct bt_sco_chan *chan = sco->sco.chan; in deferred_work()
2232 if (conn->type != BT_CONN_TYPE_LE) { in deferred_work()
2237 conn->role == BT_CONN_ROLE_CENTRAL) { in deferred_work()
2247 if (atomic_test_and_clear_bit(conn->flags, in deferred_work()
2251 param = BT_LE_CONN_PARAM(conn->le.interval_min, in deferred_work()
2252 conn->le.interval_max, in deferred_work()
2253 conn->le.pending_latency, in deferred_work()
2254 conn->le.pending_timeout); in deferred_work()
2258 atomic_clear_bit(conn->flags, in deferred_work()
2275 atomic_set_bit(conn->flags, in deferred_work()
2284 atomic_set_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_UPDATE); in deferred_work()
2313 switch (conn->state) { in bt_conn_create_br()
2338 memcpy(&cp->bdaddr, peer, sizeof(cp->bdaddr)); in bt_conn_create_br()
2339 cp->packet_type = sys_cpu_to_le16(0xcc18); /* DM1 DH1 DM3 DH5 DM5 DH5 */ in bt_conn_create_br()
2340 cp->pscan_rep_mode = 0x02; /* R2 */ in bt_conn_create_br()
2341 cp->allow_role_switch = param->allow_role_switch ? 0x01 : 0x00; in bt_conn_create_br()
2342 cp->clock_offset = 0x0000; /* TODO used cached clock offset */ in bt_conn_create_br()
2350 conn->role = BT_CONN_ROLE_CENTRAL; in bt_conn_create_br()
2366 if (conn->type != BT_CONN_TYPE_SCO) { in bt_conn_lookup_addr_sco()
2371 if (!bt_addr_eq(peer, &conn->sco.acl->br.dst)) { in bt_conn_lookup_addr_sco()
2393 if (conn->type != BT_CONN_TYPE_BR) { in bt_conn_lookup_addr_br()
2398 if (!bt_addr_eq(peer, &conn->br.dst)) { in bt_conn_lookup_addr_br()
2417 sco_conn->sco.acl = bt_conn_lookup_addr_br(peer); in bt_conn_add_sco()
2418 if (!sco_conn->sco.acl) { in bt_conn_add_sco()
2423 sco_conn->type = BT_CONN_TYPE_SCO; in bt_conn_add_sco()
2427 sco_conn->sco.pkt_type = (bt_dev.br.esco_pkt_type & in bt_conn_add_sco()
2430 sco_conn->sco.pkt_type = (bt_dev.br.esco_pkt_type & in bt_conn_add_sco()
2434 sco_conn->sco.pkt_type = (bt_dev.br.esco_pkt_type & in bt_conn_add_sco()
2449 bt_addr_copy(&conn->br.dst, peer); in bt_conn_add_br()
2450 conn->type = BT_CONN_TYPE_BR; in bt_conn_add_br()
2451 conn->tx_data_pull = l2cap_br_data_pull; in bt_conn_add_br()
2452 conn->get_and_clear_cb = acl_get_and_clear_cb; in bt_conn_add_br()
2453 conn->has_data = acl_has_data; in bt_conn_add_br()
2467 return -ENOBUFS; in bt_hci_connect_br_cancel()
2471 memcpy(&cp->bdaddr, &conn->br.dst, sizeof(cp->bdaddr)); in bt_hci_connect_br_cancel()
2478 rp = (void *)rsp->data; in bt_hci_connect_br_cancel()
2480 err = rp->status ? -EIO : 0; in bt_hci_connect_br_cancel()
2492 const struct bt_keys *keys = conn->le.keys; in bt_conn_ltk_present()
2495 keys = bt_keys_find_addr(conn->id, &conn->le.dst); in bt_conn_ltk_present()
2499 if (conn->role == BT_HCI_ROLE_CENTRAL) { in bt_conn_ltk_present()
2500 return keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_PERIPH_LTK); in bt_conn_ltk_present()
2502 return keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_LTK); in bt_conn_ltk_present()
2513 if (conn->role == BT_HCI_ROLE_CENTRAL) { in bt_conn_identity_resolved()
2514 rpa = &conn->le.resp_addr; in bt_conn_identity_resolved()
2516 rpa = &conn->le.init_addr; in bt_conn_identity_resolved()
2523 if (callback->identity_resolved) { in bt_conn_identity_resolved()
2524 callback->identity_resolved(conn, rpa, &conn->le.dst); in bt_conn_identity_resolved()
2529 if (cb->identity_resolved) { in bt_conn_identity_resolved()
2530 cb->identity_resolved(conn, rpa, &conn->le.dst); in bt_conn_identity_resolved()
2541 if (len > sizeof(cp->ltk)) { in bt_conn_le_start_encryption()
2542 return -EINVAL; in bt_conn_le_start_encryption()
2547 return -ENOBUFS; in bt_conn_le_start_encryption()
2551 cp->handle = sys_cpu_to_le16(conn->handle); in bt_conn_le_start_encryption()
2552 memcpy(&cp->rand, rand, sizeof(cp->rand)); in bt_conn_le_start_encryption()
2553 memcpy(&cp->ediv, ediv, sizeof(cp->ediv)); in bt_conn_le_start_encryption()
2555 memcpy(cp->ltk, ltk, len); in bt_conn_le_start_encryption()
2556 if (len < sizeof(cp->ltk)) { in bt_conn_le_start_encryption()
2557 (void)memset(cp->ltk + len, 0, sizeof(cp->ltk) - len); in bt_conn_le_start_encryption()
2567 if (!conn->encrypt) { in bt_conn_enc_key_size()
2572 conn->type == BT_CONN_TYPE_BR) { in bt_conn_enc_key_size()
2586 cp->handle = sys_cpu_to_le16(conn->handle); in bt_conn_enc_key_size()
2593 rp = (void *)rsp->data; in bt_conn_enc_key_size()
2595 key_size = rp->status ? 0 : rp->key_size; in bt_conn_enc_key_size()
2603 return conn->le.keys ? conn->le.keys->enc_size : 0; in bt_conn_enc_key_size()
2612 if (conn->type == BT_CONN_TYPE_BR) { in reset_pairing()
2613 atomic_clear_bit(conn->flags, BT_CONN_BR_PAIRING); in reset_pairing()
2614 atomic_clear_bit(conn->flags, BT_CONN_BR_PAIRED); in reset_pairing()
2615 atomic_clear_bit(conn->flags, BT_CONN_BR_PAIRING_INITIATOR); in reset_pairing()
2616 atomic_clear_bit(conn->flags, BT_CONN_BR_LEGACY_SECURE); in reset_pairing()
2617 atomic_clear_bit(conn->flags, BT_CONN_BR_GENERAL_BONDING); in reset_pairing()
2622 conn->required_sec_level = conn->sec_level; in reset_pairing()
2637 if (callback->security_changed) { in bt_conn_security_changed()
2638 callback->security_changed(conn, conn->sec_level, err); in bt_conn_security_changed()
2643 if (cb->security_changed) { in bt_conn_security_changed()
2644 cb->security_changed(conn, conn->sec_level, err); in bt_conn_security_changed()
2649 if (!err && conn->sec_level >= BT_SECURITY_L2) { in bt_conn_security_changed()
2650 if (conn->type == BT_CONN_TYPE_LE) { in bt_conn_security_changed()
2651 bt_keys_update_usage(conn->id, bt_conn_get_dst(conn)); in bt_conn_security_changed()
2655 if (conn->type == BT_CONN_TYPE_BR) { in bt_conn_security_changed()
2656 bt_keys_link_key_update_usage(&conn->br.dst); in bt_conn_security_changed()
2666 if (IS_ENABLED(CONFIG_BT_CLASSIC) && conn->type == BT_CONN_TYPE_BR) { in start_security()
2674 return -EINVAL; in start_security()
2682 if (conn->state != BT_CONN_CONNECTED) { in bt_conn_set_security()
2683 return -ENOTCONN; in bt_conn_set_security()
2698 if (!force_pair && (conn->sec_level >= sec || conn->required_sec_level >= sec)) { in bt_conn_set_security()
2702 atomic_set_bit_to(conn->flags, BT_CONN_FORCE_PAIR, force_pair); in bt_conn_set_security()
2703 conn->required_sec_level = sec; in bt_conn_set_security()
2709 conn->required_sec_level = conn->sec_level; in bt_conn_set_security()
2717 return conn->sec_level; in bt_conn_get_security()
2728 if (sys_slist_find(&conn_cbs, &cb->_node, NULL)) { in bt_conn_cb_register()
2729 return -EEXIST; in bt_conn_cb_register()
2732 sys_slist_append(&conn_cbs, &cb->_node); in bt_conn_cb_register()
2740 return -EINVAL; in bt_conn_cb_unregister()
2743 if (!sys_slist_find_and_remove(&conn_cbs, &cb->_node)) { in bt_conn_cb_unregister()
2744 return -ENOENT; in bt_conn_cb_unregister()
2763 bt_addr_le_str(peer), state2str(conn->state)); in bt_conn_exists_le()
2779 conn->id = id; in bt_conn_add_le()
2780 bt_addr_le_copy(&conn->le.dst, peer); in bt_conn_add_le()
2782 conn->sec_level = BT_SECURITY_L1; in bt_conn_add_le()
2783 conn->required_sec_level = BT_SECURITY_L1; in bt_conn_add_le()
2785 conn->type = BT_CONN_TYPE_LE; in bt_conn_add_le()
2786 conn->tx_data_pull = l2cap_data_pull; in bt_conn_add_le()
2787 conn->get_and_clear_cb = acl_get_and_clear_cb; in bt_conn_add_le()
2788 conn->has_data = acl_has_data; in bt_conn_add_le()
2789 conn->le.interval_min = BT_GAP_INIT_CONN_INT_MIN; in bt_conn_add_le()
2790 conn->le.interval_max = BT_GAP_INIT_CONN_INT_MAX; in bt_conn_add_le()
2798 if (id != conn->id) { in bt_conn_is_peer_addr_le()
2803 if (bt_addr_le_eq(peer, &conn->le.dst)) { in bt_conn_is_peer_addr_le()
2808 if (conn->role == BT_HCI_ROLE_CENTRAL) { in bt_conn_is_peer_addr_le()
2809 return bt_addr_le_eq(peer, &conn->le.resp_addr); in bt_conn_is_peer_addr_le()
2812 return bt_addr_le_eq(peer, &conn->le.init_addr); in bt_conn_is_peer_addr_le()
2826 if (conn->type != BT_CONN_TYPE_LE) { in bt_conn_lookup_addr_le()
2854 if (conn->type != BT_CONN_TYPE_LE) { in bt_conn_lookup_state_le()
2864 if (!(conn->state == state && conn->id == id)) { in bt_conn_lookup_state_le()
2877 return &conn->le.dst; in bt_conn_get_dst()
2904 info->type = conn->type; in bt_conn_get_info()
2905 info->role = conn->role; in bt_conn_get_info()
2906 info->id = conn->id; in bt_conn_get_info()
2907 info->state = conn_internal_to_public_state(conn->state); in bt_conn_get_info()
2908 info->security.flags = 0; in bt_conn_get_info()
2909 info->security.level = bt_conn_get_security(conn); in bt_conn_get_info()
2911 info->security.enc_key_size = bt_conn_enc_key_size(conn); in bt_conn_get_info()
2913 info->security.enc_key_size = 0; in bt_conn_get_info()
2916 switch (conn->type) { in bt_conn_get_info()
2918 info->le.dst = &conn->le.dst; in bt_conn_get_info()
2919 info->le.src = &bt_dev.id_addr[conn->id]; in bt_conn_get_info()
2920 if (conn->role == BT_HCI_ROLE_CENTRAL) { in bt_conn_get_info()
2921 info->le.local = &conn->le.init_addr; in bt_conn_get_info()
2922 info->le.remote = &conn->le.resp_addr; in bt_conn_get_info()
2924 info->le.local = &conn->le.resp_addr; in bt_conn_get_info()
2925 info->le.remote = &conn->le.init_addr; in bt_conn_get_info()
2927 info->le.interval = conn->le.interval; in bt_conn_get_info()
2928 info->le.latency = conn->le.latency; in bt_conn_get_info()
2929 info->le.timeout = conn->le.timeout; in bt_conn_get_info()
2931 info->le.phy = &conn->le.phy; in bt_conn_get_info()
2934 info->le.data_len = &conn->le.data_len; in bt_conn_get_info()
2937 info->le.subrate = &conn->le.subrate; in bt_conn_get_info()
2939 if (conn->le.keys && (conn->le.keys->flags & BT_KEYS_SC)) { in bt_conn_get_info()
2940 info->security.flags |= BT_SECURITY_FLAG_SC; in bt_conn_get_info()
2942 if (conn->le.keys && (conn->le.keys->flags & BT_KEYS_OOB)) { in bt_conn_get_info()
2943 info->security.flags |= BT_SECURITY_FLAG_OOB; in bt_conn_get_info()
2948 info->br.dst = &conn->br.dst; in bt_conn_get_info()
2954 conn->iso.info.type == BT_ISO_CHAN_TYPE_CONNECTED && conn->iso.acl != NULL) { in bt_conn_get_info()
2955 info->le.dst = &conn->iso.acl->le.dst; in bt_conn_get_info()
2956 info->le.src = &bt_dev.id_addr[conn->iso.acl->id]; in bt_conn_get_info()
2958 info->le.src = BT_ADDR_LE_NONE; in bt_conn_get_info()
2959 info->le.dst = BT_ADDR_LE_NONE; in bt_conn_get_info()
2967 return -EINVAL; in bt_conn_get_info()
2973 if (!atomic_test_bit(conn->flags, BT_CONN_LE_FEATURES_EXCHANGED) || in bt_conn_get_remote_info()
2975 !atomic_test_bit(conn->flags, BT_CONN_AUTO_VERSION_INFO))) { in bt_conn_get_remote_info()
2976 return -EBUSY; in bt_conn_get_remote_info()
2979 remote_info->type = conn->type; in bt_conn_get_remote_info()
2981 /* The conn->rv values will be just zeroes if the operation failed */ in bt_conn_get_remote_info()
2982 remote_info->version = conn->rv.version; in bt_conn_get_remote_info()
2983 remote_info->manufacturer = conn->rv.manufacturer; in bt_conn_get_remote_info()
2984 remote_info->subversion = conn->rv.subversion; in bt_conn_get_remote_info()
2986 remote_info->version = 0; in bt_conn_get_remote_info()
2987 remote_info->manufacturer = 0; in bt_conn_get_remote_info()
2988 remote_info->subversion = 0; in bt_conn_get_remote_info()
2991 switch (conn->type) { in bt_conn_get_remote_info()
2993 remote_info->le.features = conn->le.features; in bt_conn_get_remote_info()
2999 return -ENOTSUP; in bt_conn_get_remote_info()
3002 return -EINVAL; in bt_conn_get_remote_info()
3018 return -ENOBUFS; in bt_conn_get_tx_power_level()
3022 cp->type = type; in bt_conn_get_tx_power_level()
3023 cp->handle = sys_cpu_to_le16(conn->handle); in bt_conn_get_tx_power_level()
3030 rp = (void *) rsp->data; in bt_conn_get_tx_power_level()
3031 *tx_power_level = rp->tx_power_level; in bt_conn_get_tx_power_level()
3044 if (callback->tx_power_report) { in notify_tx_power_report()
3045 callback->tx_power_report(conn, &report); in notify_tx_power_report()
3051 if (cb->tx_power_report) { in notify_tx_power_report()
3052 cb->tx_power_report(conn, &report); in notify_tx_power_report()
3066 if (!tx_power->phy) { in bt_conn_le_enhanced_get_tx_power_level()
3067 return -EINVAL; in bt_conn_le_enhanced_get_tx_power_level()
3072 return -ENOBUFS; in bt_conn_le_enhanced_get_tx_power_level()
3076 cp->handle = sys_cpu_to_le16(conn->handle); in bt_conn_le_enhanced_get_tx_power_level()
3077 cp->phy = tx_power->phy; in bt_conn_le_enhanced_get_tx_power_level()
3084 rp = (void *) rsp->data; in bt_conn_le_enhanced_get_tx_power_level()
3085 tx_power->phy = rp->phy; in bt_conn_le_enhanced_get_tx_power_level()
3086 tx_power->current_level = rp->current_tx_power_level; in bt_conn_le_enhanced_get_tx_power_level()
3087 tx_power->max_level = rp->max_tx_power_level; in bt_conn_le_enhanced_get_tx_power_level()
3100 return -EINVAL; in bt_conn_le_get_remote_tx_power_level()
3105 return -ENOBUFS; in bt_conn_le_get_remote_tx_power_level()
3109 cp->handle = sys_cpu_to_le16(conn->handle); in bt_conn_le_get_remote_tx_power_level()
3110 cp->phy = phy; in bt_conn_le_get_remote_tx_power_level()
3124 return -ENOBUFS; in bt_conn_le_set_tx_power_report_enable()
3128 cp->handle = sys_cpu_to_le16(conn->handle); in bt_conn_le_set_tx_power_report_enable()
3129 cp->local_enable = local_enable ? BT_HCI_LE_TX_POWER_REPORT_ENABLE : in bt_conn_le_set_tx_power_report_enable()
3131 cp->remote_enable = remote_enable ? BT_HCI_LE_TX_POWER_REPORT_ENABLE : in bt_conn_le_set_tx_power_report_enable()
3143 if (tx_power_level->phy != 0) { in bt_conn_le_get_tx_power_level()
3147 return -ENOTSUP; in bt_conn_le_get_tx_power_level()
3152 &tx_power_level->current_level); in bt_conn_le_get_tx_power_level()
3158 &tx_power_level->max_level); in bt_conn_le_get_tx_power_level()
3169 if (callback->path_loss_threshold_report) { in notify_path_loss_threshold_report()
3170 callback->path_loss_threshold_report(conn, &report); in notify_path_loss_threshold_report()
3176 if (cb->path_loss_threshold_report) { in notify_path_loss_threshold_report()
3177 cb->path_loss_threshold_report(conn, &report); in notify_path_loss_threshold_report()
3190 return -ENOBUFS; in bt_conn_le_set_path_loss_mon_param()
3194 cp->handle = sys_cpu_to_le16(conn->handle); in bt_conn_le_set_path_loss_mon_param()
3195 cp->high_threshold = params->high_threshold; in bt_conn_le_set_path_loss_mon_param()
3196 cp->high_hysteresis = params->high_hysteresis; in bt_conn_le_set_path_loss_mon_param()
3197 cp->low_threshold = params->low_threshold; in bt_conn_le_set_path_loss_mon_param()
3198 cp->low_hysteresis = params->low_hysteresis; in bt_conn_le_set_path_loss_mon_param()
3199 cp->min_time_spent = sys_cpu_to_le16(params->min_time_spent); in bt_conn_le_set_path_loss_mon_param()
3211 return -ENOBUFS; in bt_conn_le_set_path_loss_mon_enable()
3215 cp->handle = sys_cpu_to_le16(conn->handle); in bt_conn_le_set_path_loss_mon_enable()
3216 cp->enable = reporting_enable ? BT_HCI_LE_PATH_LOSS_REPORTING_ENABLE : in bt_conn_le_set_path_loss_mon_enable()
3230 if (callback->subrate_changed) { in notify_subrate_change()
3231 callback->subrate_changed(conn, ¶ms); in notify_subrate_change()
3237 if (cb->subrate_changed) { in notify_subrate_change()
3238 cb->subrate_changed(conn, ¶ms); in notify_subrate_change()
3247 if (param->subrate_min < 0x0001 || param->subrate_min > 0x01F4 || in le_subrate_common_params_valid()
3248 param->subrate_max < 0x0001 || param->subrate_max > 0x01F4 || in le_subrate_common_params_valid()
3249 param->subrate_min > param->subrate_max) { in le_subrate_common_params_valid()
3253 if (param->max_latency > 0x01F3 || in le_subrate_common_params_valid()
3254 param->subrate_max * (param->max_latency + 1) > 500) { in le_subrate_common_params_valid()
3258 if (param->continuation_number > 0x01F3 || in le_subrate_common_params_valid()
3259 param->continuation_number >= param->subrate_max) { in le_subrate_common_params_valid()
3263 if (param->supervision_timeout < 0x000A || in le_subrate_common_params_valid()
3264 param->supervision_timeout > 0xC80) { in le_subrate_common_params_valid()
3277 return -ENOTSUP; in bt_conn_le_subrate_set_defaults()
3281 return -EINVAL; in bt_conn_le_subrate_set_defaults()
3286 return -ENOBUFS; in bt_conn_le_subrate_set_defaults()
3290 cp->subrate_min = sys_cpu_to_le16(params->subrate_min); in bt_conn_le_subrate_set_defaults()
3291 cp->subrate_max = sys_cpu_to_le16(params->subrate_max); in bt_conn_le_subrate_set_defaults()
3292 cp->max_latency = sys_cpu_to_le16(params->max_latency); in bt_conn_le_subrate_set_defaults()
3293 cp->continuation_number = sys_cpu_to_le16(params->continuation_number); in bt_conn_le_subrate_set_defaults()
3294 cp->supervision_timeout = sys_cpu_to_le16(params->supervision_timeout); in bt_conn_le_subrate_set_defaults()
3306 return -EINVAL; in bt_conn_le_subrate_request()
3311 return -ENOBUFS; in bt_conn_le_subrate_request()
3315 cp->handle = sys_cpu_to_le16(conn->handle); in bt_conn_le_subrate_request()
3316 cp->subrate_min = sys_cpu_to_le16(params->subrate_min); in bt_conn_le_subrate_request()
3317 cp->subrate_max = sys_cpu_to_le16(params->subrate_max); in bt_conn_le_subrate_request()
3318 cp->max_latency = sys_cpu_to_le16(params->max_latency); in bt_conn_le_subrate_request()
3319 cp->continuation_number = sys_cpu_to_le16(params->continuation_number); in bt_conn_le_subrate_request()
3320 cp->supervision_timeout = sys_cpu_to_le16(params->supervision_timeout); in bt_conn_le_subrate_request()
3332 if (callback->le_cs_remote_capabilities_available) { in notify_remote_cs_capabilities()
3333 callback->le_cs_remote_capabilities_available(conn, ¶ms); in notify_remote_cs_capabilities()
3338 if (cb->le_cs_remote_capabilities_available) { in notify_remote_cs_capabilities()
3339 cb->le_cs_remote_capabilities_available(conn, ¶ms); in notify_remote_cs_capabilities()
3349 if (callback->le_cs_remote_fae_table_available) { in notify_remote_cs_fae_table()
3350 callback->le_cs_remote_fae_table_available(conn, ¶ms); in notify_remote_cs_fae_table()
3355 if (cb->le_cs_remote_fae_table_available) { in notify_remote_cs_fae_table()
3356 cb->le_cs_remote_fae_table_available(conn, ¶ms); in notify_remote_cs_fae_table()
3366 if (callback->le_cs_config_created) { in notify_cs_config_created()
3367 callback->le_cs_config_created(conn, params); in notify_cs_config_created()
3372 if (cb->le_cs_config_created) { in notify_cs_config_created()
3373 cb->le_cs_config_created(conn, params); in notify_cs_config_created()
3383 if (callback->le_cs_config_removed) { in notify_cs_config_removed()
3384 callback->le_cs_config_removed(conn, config_id); in notify_cs_config_removed()
3389 if (cb->le_cs_config_removed) { in notify_cs_config_removed()
3390 cb->le_cs_config_removed(conn, config_id); in notify_cs_config_removed()
3400 if (callback->le_cs_security_enabled) { in notify_cs_security_enable_available()
3401 callback->le_cs_security_enabled(conn); in notify_cs_security_enable_available()
3406 if (cb->le_cs_security_enabled) { in notify_cs_security_enable_available()
3407 cb->le_cs_security_enabled(conn); in notify_cs_security_enable_available()
3418 if (callback->le_cs_procedure_enabled) { in notify_cs_procedure_enable_available()
3419 callback->le_cs_procedure_enabled(conn, params); in notify_cs_procedure_enable_available()
3424 if (cb->le_cs_procedure_enabled) { in notify_cs_procedure_enable_available()
3425 cb->le_cs_procedure_enabled(conn, params); in notify_cs_procedure_enable_available()
3435 if (callback->le_cs_subevent_data_available) { in notify_cs_subevent_result()
3436 callback->le_cs_subevent_data_available(conn, result); in notify_cs_subevent_result()
3441 if (cb->le_cs_subevent_data_available) { in notify_cs_subevent_result()
3442 cb->le_cs_subevent_data_available(conn, result); in notify_cs_subevent_result()
3451 LOG_DBG("conn %p features 0x%02x params (%d-%d %d %d)", conn, conn->le.features[0], in bt_conn_le_param_update()
3452 param->interval_min, param->interval_max, param->latency, param->timeout); in bt_conn_le_param_update()
3455 conn->role == BT_CONN_ROLE_CENTRAL) { in bt_conn_le_param_update()
3461 if (atomic_test_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_UPDATE)) { in bt_conn_le_param_update()
3466 conn->le.interval_min = param->interval_min; in bt_conn_le_param_update()
3467 conn->le.interval_max = param->interval_max; in bt_conn_le_param_update()
3468 conn->le.pending_latency = param->latency; in bt_conn_le_param_update()
3469 conn->le.pending_timeout = param->timeout; in bt_conn_le_param_update()
3470 atomic_set_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_SET); in bt_conn_le_param_update()
3480 if (conn->le.data_len.tx_max_len == param->tx_max_len && in bt_conn_le_data_len_update()
3481 conn->le.data_len.tx_max_time == param->tx_max_time) { in bt_conn_le_data_len_update()
3482 return -EALREADY; in bt_conn_le_data_len_update()
3485 return bt_le_set_data_len(conn, param->tx_max_len, param->tx_max_time); in bt_conn_le_data_len_update()
3495 if ((param->options & BT_CONN_LE_PHY_OPT_CODED_S2) && in bt_conn_le_phy_update()
3496 (param->options & BT_CONN_LE_PHY_OPT_CODED_S8)) { in bt_conn_le_phy_update()
3498 } else if (param->options & BT_CONN_LE_PHY_OPT_CODED_S2) { in bt_conn_le_phy_update()
3500 } else if (param->options & BT_CONN_LE_PHY_OPT_CODED_S8) { in bt_conn_le_phy_update()
3507 if (param->pref_tx_phy == BT_GAP_LE_PHY_NONE) { in bt_conn_le_phy_update()
3511 if (param->pref_rx_phy == BT_GAP_LE_PHY_NONE) { in bt_conn_le_phy_update()
3515 return bt_le_set_phy(conn, all_phys, param->pref_tx_phy, in bt_conn_le_phy_update()
3516 param->pref_rx_phy, phy_opts); in bt_conn_le_phy_update()
3524 conn->le.interval_min = param->interval_min; in bt_conn_set_param_le()
3525 conn->le.interval_max = param->interval_max; in bt_conn_set_param_le()
3526 conn->le.latency = param->latency; in bt_conn_set_param_le()
3527 conn->le.timeout = param->timeout; in bt_conn_set_param_le()
3534 bt_dev.create_param.timeout = in create_param_setup()
3535 (bt_dev.create_param.timeout != 0) ? in create_param_setup()
3536 bt_dev.create_param.timeout : in create_param_setup()
3558 return -EAGAIN; in bt_conn_le_create_auto()
3562 return -EINVAL; in bt_conn_le_create_auto()
3569 return -EALREADY; in bt_conn_le_create_auto()
3577 return -EINVAL; in bt_conn_le_create_auto()
3581 return -EINVAL; in bt_conn_le_create_auto()
3585 return -EINVAL; in bt_conn_le_create_auto()
3590 return -ENOMEM; in bt_conn_le_create_auto()
3596 atomic_set_bit(conn->flags, BT_CONN_AUTO_CONNECT); in bt_conn_le_create_auto()
3602 conn->err = 0; in bt_conn_le_create_auto()
3621 return -EINVAL; in bt_conn_create_auto_stop()
3627 return -EINVAL; in bt_conn_create_auto_stop()
3631 return -EINVAL; in bt_conn_create_auto_stop()
3653 return -EAGAIN; in conn_le_create_common_checks()
3658 return -EINVAL; in conn_le_create_common_checks()
3663 return -EAGAIN; in conn_le_create_common_checks()
3668 return -EALREADY; in conn_le_create_common_checks()
3673 return -EINVAL; in conn_le_create_common_checks()
3678 return -EINVAL; in conn_le_create_common_checks()
3714 return -EINVAL; in bt_conn_le_create()
3726 return -EINVAL; in bt_conn_le_create()
3737 return -ENOMEM; in bt_conn_le_create()
3750 /* Use host-based identity resolving. */ in bt_conn_le_create()
3771 conn->err = 0; in bt_conn_le_create()
3775 /* Best-effort attempt to inform the scanner that the initiator stopped. */ in bt_conn_le_create()
3796 return -EINVAL; in bt_conn_le_create_synced()
3808 return -EINVAL; in bt_conn_le_create_synced()
3812 err = conn_le_create_common_checks(synced_param->peer, conn_param); in bt_conn_le_create_synced()
3817 if (!atomic_test_bit(adv->flags, BT_PER_ADV_ENABLED)) { in bt_conn_le_create_synced()
3818 return -EINVAL; in bt_conn_le_create_synced()
3822 return -ENOTSUP; in bt_conn_le_create_synced()
3825 if (synced_param->subevent >= BT_HCI_PAWR_SUBEVENT_MAX) { in bt_conn_le_create_synced()
3826 return -EINVAL; in bt_conn_le_create_synced()
3829 conn = conn_le_create_helper(synced_param->peer, conn_param); in bt_conn_le_create_synced()
3831 return -ENOMEM; in bt_conn_le_create_synced()
3834 /* The connection creation timeout is not really useful for PAwR. in bt_conn_le_create_synced()
3837 * used, so disable the timeout. in bt_conn_le_create_synced()
3839 bt_dev.create_param.timeout = 0; in bt_conn_le_create_synced()
3842 err = bt_le_create_conn_synced(conn, adv, synced_param->subevent); in bt_conn_le_create_synced()
3844 conn->err = 0; in bt_conn_le_create_synced()
3862 return -EAGAIN; in bt_le_set_auto_conn()
3866 return -EINVAL; in bt_le_set_auto_conn()
3870 return -EINVAL; in bt_le_set_auto_conn()
3878 return -ENOMEM; in bt_le_set_auto_conn()
3885 if (!atomic_test_and_set_bit(conn->flags, in bt_le_set_auto_conn()
3890 if (atomic_test_and_clear_bit(conn->flags, in bt_le_set_auto_conn()
3893 if (conn->state == BT_CONN_SCAN_BEFORE_INITIATING) { in bt_le_set_auto_conn()
3900 if (conn->state == BT_CONN_DISCONNECTED && in bt_le_set_auto_conn()
3924 return -ENOBUFS; in bt_conn_le_conn_update()
3929 conn_update->handle = sys_cpu_to_le16(conn->handle); in bt_conn_le_conn_update()
3930 conn_update->conn_interval_min = sys_cpu_to_le16(param->interval_min); in bt_conn_le_conn_update()
3931 conn_update->conn_interval_max = sys_cpu_to_le16(param->interval_max); in bt_conn_le_conn_update()
3932 conn_update->conn_latency = sys_cpu_to_le16(param->latency); in bt_conn_le_conn_update()
3933 conn_update->supervision_timeout = sys_cpu_to_le16(param->timeout); in bt_conn_le_conn_update()
3947 return -EALREADY; in bt_conn_auth_cb_register()
3953 if (!cb->cancel && in bt_conn_auth_cb_register()
3954 (cb->passkey_display || cb->passkey_entry || cb->passkey_confirm || in bt_conn_auth_cb_register()
3956 cb->pincode_entry || in bt_conn_auth_cb_register()
3958 cb->pairing_confirm)) { in bt_conn_auth_cb_register()
3959 return -EINVAL; in bt_conn_auth_cb_register()
3970 return -EINVAL; in bt_conn_auth_cb_overlay()
3976 if (cb && !cb->cancel && in bt_conn_auth_cb_overlay()
3977 (cb->passkey_display || cb->passkey_entry || cb->passkey_confirm || in bt_conn_auth_cb_overlay()
3978 cb->pairing_confirm)) { in bt_conn_auth_cb_overlay()
3979 return -EINVAL; in bt_conn_auth_cb_overlay()
3982 if (conn->type == BT_CONN_TYPE_LE) { in bt_conn_auth_cb_overlay()
3986 return -ENOTSUP; in bt_conn_auth_cb_overlay()
3993 return -EINVAL; in bt_conn_auth_info_cb_register()
3996 if (sys_slist_find(&bt_auth_info_cbs, &cb->node, NULL)) { in bt_conn_auth_info_cb_register()
3997 return -EALREADY; in bt_conn_auth_info_cb_register()
4000 sys_slist_append(&bt_auth_info_cbs, &cb->node); in bt_conn_auth_info_cb_register()
4008 return -EINVAL; in bt_conn_auth_info_cb_unregister()
4011 if (!sys_slist_find_and_remove(&bt_auth_info_cbs, &cb->node)) { in bt_conn_auth_info_cb_unregister()
4012 return -EALREADY; in bt_conn_auth_info_cb_unregister()
4020 if (IS_ENABLED(CONFIG_BT_SMP) && conn->type == BT_CONN_TYPE_LE) { in bt_conn_auth_passkey_entry()
4024 if (IS_ENABLED(CONFIG_BT_CLASSIC) && conn->type == BT_CONN_TYPE_BR) { in bt_conn_auth_passkey_entry()
4026 return -EINVAL; in bt_conn_auth_passkey_entry()
4032 return -EINVAL; in bt_conn_auth_passkey_entry()
4039 if (IS_ENABLED(CONFIG_BT_SMP) && conn->type == BT_CONN_TYPE_LE) { in bt_conn_auth_keypress_notify()
4043 LOG_ERR("Not implemented for conn type %d", conn->type); in bt_conn_auth_keypress_notify()
4044 return -EINVAL; in bt_conn_auth_keypress_notify()
4050 if (IS_ENABLED(CONFIG_BT_SMP) && conn->type == BT_CONN_TYPE_LE) { in bt_conn_auth_passkey_confirm()
4054 if (IS_ENABLED(CONFIG_BT_CLASSIC) && conn->type == BT_CONN_TYPE_BR) { in bt_conn_auth_passkey_confirm()
4056 return -EINVAL; in bt_conn_auth_passkey_confirm()
4062 return -EINVAL; in bt_conn_auth_passkey_confirm()
4067 if (IS_ENABLED(CONFIG_BT_SMP) && conn->type == BT_CONN_TYPE_LE) { in bt_conn_auth_cancel()
4071 if (IS_ENABLED(CONFIG_BT_CLASSIC) && conn->type == BT_CONN_TYPE_BR) { in bt_conn_auth_cancel()
4073 return -EINVAL; in bt_conn_auth_cancel()
4079 return -EINVAL; in bt_conn_auth_cancel()
4084 if (IS_ENABLED(CONFIG_BT_SMP) && conn->type == BT_CONN_TYPE_LE) { in bt_conn_auth_pairing_confirm()
4088 if (IS_ENABLED(CONFIG_BT_CLASSIC) && conn->type == BT_CONN_TYPE_BR) { in bt_conn_auth_pairing_confirm()
4090 return -EINVAL; in bt_conn_auth_pairing_confirm()
4096 return -EINVAL; in bt_conn_auth_pairing_confirm()
4137 if (atomic_test_bit(conn->flags, in bt_conn_init()
4140 conn->id = BT_ID_DEFAULT; in bt_conn_init()
4181 if (callback->cte_report_cb) { in bt_hci_le_df_connection_iq_report_common()
4182 callback->cte_report_cb(conn, &iq_report); in bt_hci_le_df_connection_iq_report_common()
4188 if (cb->cte_report_cb) { in bt_hci_le_df_connection_iq_report_common()
4189 cb->cte_report_cb(conn, &iq_report); in bt_hci_le_df_connection_iq_report_common()
4225 if (callback->cte_report_cb) { in bt_hci_le_df_cte_req_failed()
4226 callback->cte_report_cb(conn, &iq_report); in bt_hci_le_df_cte_req_failed()
4232 if (cb->cte_report_cb) { in bt_hci_le_df_cte_req_failed()
4233 cb->cte_report_cb(conn, &iq_report); in bt_hci_le_df_cte_req_failed()