Lines Matching +full:txq +full:- +full:size
5 * Copyright (c) 2021-2024 Nordic Semiconductor ASA
7 * SPDX-License-Identifier: Apache-2.0
51 #define iso_chan(_iso) ((_iso)->iso.chan);
100 struct bt_iso_chan *chan = iso->iso.chan; in bt_iso_sent_cb()
105 ops = chan->ops; in bt_iso_sent_cb()
107 if (!err && ops != NULL && ops->sent != NULL) { in bt_iso_sent_cb()
108 ops->sent(chan); in bt_iso_sent_cb()
122 if (buf->len < sizeof(*hdr)) { in hci_iso()
123 LOG_ERR("Invalid HCI ISO packet size (%u)", buf->len); in hci_iso()
129 len = bt_iso_hdr_len(sys_le16_to_cpu(hdr->len)); in hci_iso()
130 handle = sys_le16_to_cpu(hdr->handle); in hci_iso()
133 iso(buf)->handle = bt_iso_handle(handle); in hci_iso()
134 iso(buf)->index = BT_CONN_INDEX_INVALID; in hci_iso()
136 BT_ISO_DATA_DBG("handle %u len %u flags %u", iso(buf)->handle, len, flags); in hci_iso()
138 if (buf->len != len) { in hci_iso()
139 LOG_ERR("ISO data length mismatch (%u != %u)", buf->len, len); in hci_iso()
144 iso = bt_conn_lookup_handle(iso(buf)->handle, BT_CONN_TYPE_ISO); in hci_iso()
146 LOG_ERR("Unable to find conn for handle %u", iso(buf)->handle); in hci_iso()
151 iso(buf)->index = bt_conn_index(iso); in hci_iso()
180 iso->type = BT_CONN_TYPE_ISO; in iso_new()
181 iso->tx_data_pull = iso_data_pull; in iso_new()
182 iso->get_and_clear_cb = iso_get_and_clear_cb; in iso_new()
183 iso->has_data = iso_has_data; in iso_new()
203 if ((path->cc == NULL && path->cc_len != 0)) { in hci_le_setup_iso_data_path()
204 LOG_DBG("Invalid ISO data path CC: %p %u", path->cc, path->cc_len); in hci_le_setup_iso_data_path()
206 return -EINVAL; in hci_le_setup_iso_data_path()
209 buf = bt_hci_cmd_create(BT_HCI_OP_LE_SETUP_ISO_PATH, sizeof(*cp) + path->cc_len); in hci_le_setup_iso_data_path()
211 return -ENOBUFS; in hci_le_setup_iso_data_path()
215 cp->handle = sys_cpu_to_le16(iso->handle); in hci_le_setup_iso_data_path()
216 cp->path_dir = dir; in hci_le_setup_iso_data_path()
217 cp->path_id = path->pid; in hci_le_setup_iso_data_path()
218 cp->codec_id.coding_format = path->format; in hci_le_setup_iso_data_path()
219 cp->codec_id.company_id = sys_cpu_to_le16(path->cid); in hci_le_setup_iso_data_path()
220 cp->codec_id.vs_codec_id = sys_cpu_to_le16(path->vid); in hci_le_setup_iso_data_path()
221 sys_put_le24(path->delay, cp->controller_delay); in hci_le_setup_iso_data_path()
222 cp->codec_config_len = path->cc_len; in hci_le_setup_iso_data_path()
223 cc = net_buf_add(buf, path->cc_len); in hci_le_setup_iso_data_path()
224 if (path->cc_len) { in hci_le_setup_iso_data_path()
225 memcpy(cc, path->cc, path->cc_len); in hci_le_setup_iso_data_path()
232 rp = (void *)rsp->data; in hci_le_setup_iso_data_path()
233 if (rp->status || (sys_le16_to_cpu(rp->handle) != iso->handle)) { in hci_le_setup_iso_data_path()
234 err = -EIO; in hci_le_setup_iso_data_path()
245 chan->iso = iso; in bt_iso_chan_add()
246 iso->iso.chan = chan; in bt_iso_chan_add()
247 k_fifo_init(&iso->iso.txq); in bt_iso_chan_add()
265 iso = chan->iso; in bt_iso_setup_data_path()
267 tx_qos = chan->qos->tx; in bt_iso_setup_data_path()
268 rx_qos = chan->qos->rx; in bt_iso_setup_data_path()
279 if (tx_qos != NULL && iso->iso.info.can_send) { in bt_iso_setup_data_path()
280 if (tx_qos->path != NULL) { /* Use application path */ in bt_iso_setup_data_path()
281 in_path = tx_qos->path; in bt_iso_setup_data_path()
287 if (rx_qos != NULL && iso->iso.info.can_recv) { in bt_iso_setup_data_path()
288 if (rx_qos->path != NULL) { /* Use application path */ in bt_iso_setup_data_path()
289 out_path = rx_qos->path; in bt_iso_setup_data_path()
299 iso->iso.info.type == BT_ISO_CHAN_TYPE_BROADCASTER && in_path) { in bt_iso_setup_data_path()
308 iso->iso.info.type == BT_ISO_CHAN_TYPE_SYNC_RECEIVER && out_path) { in bt_iso_setup_data_path()
317 iso->iso.info.type == BT_ISO_CHAN_TYPE_CONNECTED) { in bt_iso_setup_data_path()
323 LOG_DBG("Failed to setup host-to-ctrl path: %d", err); in bt_iso_setup_data_path()
333 LOG_DBG("Failed to setup ctlr-to-host path: %d", err); in bt_iso_setup_data_path()
340 __ASSERT(false, "Invalid iso.info.type: %u", iso->iso.info.type); in bt_iso_setup_data_path()
341 return -EINVAL; in bt_iso_setup_data_path()
350 if (iso == NULL || iso->type != BT_CONN_TYPE_ISO) { in bt_iso_connected()
351 LOG_DBG("Invalid parameters: iso %p iso->type %u", iso, iso ? iso->type : 0); in bt_iso_connected()
368 } else if (iso->iso.info.type == BT_ISO_CHAN_TYPE_BROADCASTER || in bt_iso_connected()
369 iso->iso.info.type == BT_ISO_CHAN_TYPE_SYNC_RECEIVER) { in bt_iso_connected()
372 big = lookup_big_by_handle(iso->iso.big_handle); in bt_iso_connected()
381 iso->iso.info.type == BT_ISO_CHAN_TYPE_CONNECTED) { in bt_iso_connected()
384 __ASSERT(false, "Invalid iso.info.type: %u", iso->iso.info.type); in bt_iso_connected()
391 if (chan->ops->connected) { in bt_iso_connected()
392 chan->ops->connected(chan); in bt_iso_connected()
400 __ASSERT(chan->iso != NULL, "NULL conn for iso chan %p", chan); in bt_iso_chan_disconnected()
403 bt_conn_set_state(chan->iso, BT_CONN_DISCONNECT_COMPLETE); in bt_iso_chan_disconnected()
409 chan->iso->iso.info.type == BT_ISO_CHAN_TYPE_CONNECTED) { in bt_iso_chan_disconnected()
410 bt_iso_cleanup_acl(chan->iso); in bt_iso_chan_disconnected()
412 if (chan->iso->role == BT_HCI_ROLE_PERIPHERAL) { in bt_iso_chan_disconnected()
413 bt_conn_unref(chan->iso); in bt_iso_chan_disconnected()
414 chan->iso = NULL; in bt_iso_chan_disconnected()
421 bt_iso_remove_data_path(chan->iso); in bt_iso_chan_disconnected()
431 SYS_SLIST_FOR_EACH_CONTAINER(&cig->cis_channels, cis_chan, node) { in bt_iso_chan_disconnected()
432 if (cis_chan->state == BT_ISO_STATE_CONNECTED || in bt_iso_chan_disconnected()
433 cis_chan->state == BT_ISO_STATE_CONNECTING) { in bt_iso_chan_disconnected()
440 cig->state = BT_ISO_CIG_STATE_INACTIVE; in bt_iso_chan_disconnected()
446 if (chan->ops->disconnected) { in bt_iso_chan_disconnected()
447 chan->ops->disconnected(chan, reason); in bt_iso_chan_disconnected()
455 if (iso == NULL || iso->type != BT_CONN_TYPE_ISO) { in bt_iso_disconnected()
456 LOG_DBG("Invalid parameters: iso %p iso->type %u", iso, iso ? iso->type : 0); in bt_iso_disconnected()
468 bt_iso_chan_disconnected(chan, iso->err); in bt_iso_disconnected()
493 LOG_DBG("chan %p iso %p %s -> %s", chan, chan->iso, bt_iso_chan_state_str(chan->state), in bt_iso_chan_set_state_debug()
504 if (chan->state != BT_ISO_STATE_DISCONNECTED) { in bt_iso_chan_set_state_debug()
509 if (chan->state != BT_ISO_STATE_CONNECTING) { in bt_iso_chan_set_state_debug()
514 if (chan->state != BT_ISO_STATE_CONNECTING && in bt_iso_chan_set_state_debug()
515 chan->state != BT_ISO_STATE_CONNECTED) { in bt_iso_chan_set_state_debug()
524 chan->state = state; in bt_iso_chan_set_state_debug()
529 chan->state = state; in bt_iso_chan_set_state()
537 return -EINVAL; in bt_iso_chan_get_info()
540 CHECKIF(chan->iso == NULL) { in bt_iso_chan_get_info()
541 LOG_DBG("chan->iso is NULL"); in bt_iso_chan_get_info()
542 return -EINVAL; in bt_iso_chan_get_info()
547 return -EINVAL; in bt_iso_chan_get_info()
550 (void)memcpy(info, &chan->iso->iso.info, sizeof(*info)); in bt_iso_chan_get_info()
583 BT_ISO_DATA_DBG("handle %u len %u flags 0x%02x pb 0x%02x ts 0x%02x", iso->handle, buf->len, in bt_iso_recv()
593 iso_info(buf)->flags = 0; in bt_iso_recv()
602 iso_info(buf)->ts = sys_le32_to_cpu(ts_hdr->ts); in bt_iso_recv()
604 hdr = &ts_hdr->sdu; in bt_iso_recv()
605 iso_info(buf)->flags |= BT_ISO_FLAGS_TS; in bt_iso_recv()
609 iso_info(buf)->ts = 0x00000000; in bt_iso_recv()
612 len = sys_le16_to_cpu(hdr->slen); in bt_iso_recv()
615 pkt_seq_no = sys_le16_to_cpu(hdr->sn); in bt_iso_recv()
616 iso_info(buf)->seq_num = pkt_seq_no; in bt_iso_recv()
618 iso_info(buf)->flags |= BT_ISO_FLAGS_VALID; in bt_iso_recv()
620 iso_info(buf)->flags |= BT_ISO_FLAGS_ERROR; in bt_iso_recv()
622 iso_info(buf)->flags |= BT_ISO_FLAGS_LOST; in bt_iso_recv()
625 iso_info(buf)->flags = 0; in bt_iso_recv()
629 pb == BT_ISO_START ? "Start" : "Single", buf->len, len, flags, in bt_iso_recv()
630 iso_info(buf)->ts); in bt_iso_recv()
632 if (iso->rx) { in bt_iso_recv()
638 iso->rx = buf; in bt_iso_recv()
639 iso->rx_len = len - buf->len; in bt_iso_recv()
640 if (iso->rx_len) { in bt_iso_recv()
641 /* if iso->rx_len then package is longer than the in bt_iso_recv()
642 * buf->len and cannot fit in a SINGLE package in bt_iso_recv()
656 if (!iso->rx) { in bt_iso_recv()
662 BT_ISO_DATA_DBG("Cont, len %u rx_len %u", buf->len, iso->rx_len); in bt_iso_recv()
664 if (buf->len > net_buf_tailroom(iso->rx)) { in bt_iso_recv()
671 net_buf_add_mem(iso->rx, buf->data, buf->len); in bt_iso_recv()
672 iso->rx_len -= buf->len; in bt_iso_recv()
680 BT_ISO_DATA_DBG("End, len %u rx_len %u", buf->len, iso->rx_len); in bt_iso_recv()
682 if (iso->rx == NULL) { in bt_iso_recv()
688 if (buf->len > net_buf_tailroom(iso->rx)) { in bt_iso_recv()
695 (void)net_buf_add_mem(iso->rx, buf->data, buf->len); in bt_iso_recv()
696 iso->rx_len -= buf->len; in bt_iso_recv()
710 } else if (chan->ops->recv != NULL) { in bt_iso_recv()
711 chan->ops->recv(chan, iso_info(iso->rx), iso->rx); in bt_iso_recv()
721 return !k_fifo_is_empty(&conn->iso.txq); in iso_has_data()
735 struct net_buf *frag = k_fifo_peek_head(&conn->iso.txq); in iso_data_pull()
745 if (conn->iso.chan->state != BT_ISO_STATE_CONNECTED) { in iso_data_pull()
746 __maybe_unused struct net_buf *b = k_fifo_get(&conn->iso.txq, K_NO_WAIT); in iso_data_pull()
767 bool last_frag = amount >= frag->len; in iso_data_pull()
770 __maybe_unused struct net_buf *b = k_fifo_get(&conn->iso.txq, K_NO_WAIT); in iso_data_pull()
776 *length = frag->len; in iso_data_pull()
790 if (chan->qos->tx == NULL) { in iso_chan_max_data_len()
794 max_data_len = chan->qos->tx->sdu; in iso_chan_max_data_len()
807 if (buf->user_data_size < CONFIG_BT_CONN_TX_USER_DATA_SIZE) { in conn_iso_send()
808 LOG_ERR("not enough room in user_data %d < %d pool %u", buf->user_data_size, in conn_iso_send()
809 CONFIG_BT_CONN_TX_USER_DATA_SIZE, buf->pool_id); in conn_iso_send()
810 return -EINVAL; in conn_iso_send()
813 k_fifo_put(&conn->iso.txq, buf); in conn_iso_send()
816 /* only one ISO channel per conn-object */ in conn_iso_send()
830 return -EINVAL; in validate_send()
835 if (chan->state != BT_ISO_STATE_CONNECTED) { in validate_send()
837 return -ENOTCONN; in validate_send()
840 iso_conn = chan->iso; in validate_send()
841 if (!iso_conn->iso.info.can_send) { in validate_send()
843 return -EINVAL; in validate_send()
855 return -EMSGSIZE; in validate_send()
858 if (buf->size < hdr_size) { in validate_send()
859 LOG_DBG("Channel %p cannot send ISO packet with buffer size %u", chan, buf->size); in validate_send()
861 return -EMSGSIZE; in validate_send()
865 if (buf->len > max_data_len) { in validate_send()
866 LOG_DBG("Channel %p cannot send %u octets, maximum %u", chan, buf->len, in validate_send()
868 return -EMSGSIZE; in validate_send()
888 hdr->sn = sys_cpu_to_le16(seq_num); in bt_iso_chan_send()
889 hdr->slen = sys_cpu_to_le16( in bt_iso_chan_send()
890 bt_iso_pkt_len_pack(net_buf_frags_len(buf) - sizeof(*hdr), BT_ISO_DATA_VALID)); in bt_iso_chan_send()
892 iso_conn = chan->iso; in bt_iso_chan_send()
894 BT_ISO_DATA_DBG("send-iso (no ts)"); in bt_iso_chan_send()
913 hdr->ts = ts; in bt_iso_chan_send_ts()
914 hdr->sdu.sn = sys_cpu_to_le16(seq_num); in bt_iso_chan_send_ts()
915 hdr->sdu.slen = sys_cpu_to_le16( in bt_iso_chan_send_ts()
916 bt_iso_pkt_len_pack(net_buf_frags_len(buf) - sizeof(*hdr), BT_ISO_DATA_VALID)); in bt_iso_chan_send_ts()
918 iso_conn = chan->iso; in bt_iso_chan_send_ts()
920 LOG_DBG("send-iso (ts)"); in bt_iso_chan_send_ts()
931 if (io_qos->sdu > max_sdu) { in valid_chan_io_qos()
932 LOG_DBG("sdu (%u) shall be smaller or equal to %zu", io_qos->sdu, max_sdu); in valid_chan_io_qos()
937 if (!IN_RANGE(io_qos->phy, BT_GAP_LE_PHY_1M, BT_GAP_LE_PHY_CODED)) { in valid_chan_io_qos()
938 LOG_DBG("Invalid PHY %u", io_qos->phy); in valid_chan_io_qos()
944 io_qos->rtn > BT_ISO_BROADCAST_RTN_MAX) { in valid_chan_io_qos()
945 LOG_DBG("Invalid RTN %u", io_qos->phy); in valid_chan_io_qos()
953 if (!IN_RANGE(io_qos->max_pdu, BT_ISO_BROADCAST_PDU_MIN, BT_ISO_PDU_MAX)) { in valid_chan_io_qos()
954 LOG_DBG("Invalid broadcast PDU %u", io_qos->max_pdu); in valid_chan_io_qos()
959 if (!IN_RANGE(io_qos->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX)) { in valid_chan_io_qos()
960 LOG_DBG("Invalid unicast PDU %u", io_qos->max_pdu); in valid_chan_io_qos()
966 if (!IN_RANGE(io_qos->burst_number, BT_ISO_BN_MIN, BT_ISO_BN_MAX)) { in valid_chan_io_qos()
967 LOG_DBG("Invalid BN %u", io_qos->burst_number); in valid_chan_io_qos()
990 return -EINVAL; in bt_iso_chan_get_tx_sync()
993 CHECKIF(chan->iso == NULL) { in bt_iso_chan_get_tx_sync()
994 LOG_DBG("chan->iso is NULL"); in bt_iso_chan_get_tx_sync()
995 return -EINVAL; in bt_iso_chan_get_tx_sync()
1000 return -EINVAL; in bt_iso_chan_get_tx_sync()
1003 CHECKIF(chan->state != BT_ISO_STATE_CONNECTED) { in bt_iso_chan_get_tx_sync()
1004 return -ENOTCONN; in bt_iso_chan_get_tx_sync()
1009 return -ENOMEM; in bt_iso_chan_get_tx_sync()
1013 cp->handle = sys_cpu_to_le16(chan->iso->handle); in bt_iso_chan_get_tx_sync()
1021 rp = (struct bt_hci_rp_le_read_iso_tx_sync *)rsp->data; in bt_iso_chan_get_tx_sync()
1023 info->ts = sys_le32_to_cpu(rp->timestamp); in bt_iso_chan_get_tx_sync()
1024 info->seq_num = sys_le16_to_cpu(rp->seq); in bt_iso_chan_get_tx_sync()
1025 info->offset = sys_get_le24(rp->offset); in bt_iso_chan_get_tx_sync()
1029 return -ENOTSUP; in bt_iso_chan_get_tx_sync()
1043 return -EINVAL; in bt_iso_chan_disconnect()
1046 CHECKIF(chan->iso == NULL) { in bt_iso_chan_disconnect()
1048 return -EINVAL; in bt_iso_chan_disconnect()
1051 if (chan->iso->iso.acl == NULL || chan->state == BT_ISO_STATE_DISCONNECTED) { in bt_iso_chan_disconnect()
1053 return -ENOTCONN; in bt_iso_chan_disconnect()
1056 if (chan->state == BT_ISO_STATE_ENCRYPT_PENDING) { in bt_iso_chan_disconnect()
1060 if (chan->ops->disconnected) { in bt_iso_chan_disconnect()
1061 chan->ops->disconnected(chan, BT_HCI_ERR_LOCALHOST_TERM_CONN); in bt_iso_chan_disconnect()
1067 if (chan->state == BT_ISO_STATE_DISCONNECTING) { in bt_iso_chan_disconnect()
1070 return -EALREADY; in bt_iso_chan_disconnect()
1073 if (IS_ENABLED(CONFIG_BT_ISO_PERIPHERAL) && chan->iso->role == BT_HCI_ROLE_PERIPHERAL && in bt_iso_chan_disconnect()
1074 chan->state == BT_ISO_STATE_CONNECTING) { in bt_iso_chan_disconnect()
1075 /* A CIS peripheral is not allowed to disconnect a CIS in the connecting state - It in bt_iso_chan_disconnect()
1078 return -EAGAIN; in bt_iso_chan_disconnect()
1081 err = bt_conn_disconnect(chan->iso, BT_HCI_ERR_REMOTE_USER_TERM_CONN); in bt_iso_chan_disconnect()
1093 if (iso->iso.acl) { in bt_iso_cleanup_acl()
1094 bt_conn_unref(iso->iso.acl); in bt_iso_cleanup_acl()
1095 iso->iso.acl = NULL; in bt_iso_cleanup_acl()
1101 struct bt_conn_iso *iso_conn = &iso->iso; in store_cis_info()
1102 struct bt_iso_info *info = &iso_conn->info; in store_cis_info()
1103 struct bt_iso_unicast_info *unicast_info = &info->unicast; in store_cis_info()
1104 struct bt_iso_unicast_tx_info *peripheral = &unicast_info->peripheral; in store_cis_info()
1105 struct bt_iso_unicast_tx_info *central = &unicast_info->central; in store_cis_info()
1106 const uint8_t c_phy = bt_get_phy(evt->c_phy); in store_cis_info()
1107 const uint8_t p_phy = bt_get_phy(evt->p_phy); in store_cis_info()
1112 iso_conn = &iso->iso; in store_cis_info()
1113 chan = iso_conn->chan; in store_cis_info()
1114 rx = chan->qos->rx; in store_cis_info()
1115 tx = chan->qos->tx; in store_cis_info()
1119 if (iso->role == BT_HCI_ROLE_PERIPHERAL) { in store_cis_info()
1120 /* As of BT Core 6.0, we can only get the SDU size if the controller in store_cis_info()
1122 * we fallback to using the PDU size as the SDU size. in store_cis_info()
1125 rx->phy = c_phy; in store_cis_info()
1126 rx->sdu = sys_le16_to_cpu(evt->c_max_pdu); in store_cis_info()
1130 tx->phy = p_phy; in store_cis_info()
1131 tx->sdu = sys_le16_to_cpu(evt->p_max_pdu); in store_cis_info()
1134 iso_conn->info.type = BT_ISO_CHAN_TYPE_CONNECTED; in store_cis_info()
1136 /* values are already set for central - Verify */ in store_cis_info()
1137 if (tx != NULL && tx->phy != c_phy) { in store_cis_info()
1138 LOG_WRN("Unexpected C to P PHY: %u != %u", c_phy, tx->phy); in store_cis_info()
1139 /* We assume that tx->phy has become invalid, and will use the event from in store_cis_info()
1142 tx->phy = c_phy; in store_cis_info()
1145 if (rx != NULL && rx->phy != p_phy) { in store_cis_info()
1146 LOG_WRN("Unexpected P to C max SDU: %u != %u", p_phy, rx->phy); in store_cis_info()
1147 /* We assume that rx->phy has become invalid, and will use the event from in store_cis_info()
1150 rx->phy = p_phy; in store_cis_info()
1155 iso_conn->info.can_send = false; in store_cis_info()
1157 if (iso->role == BT_HCI_ROLE_PERIPHERAL && evt->p_bn > 0) { in store_cis_info()
1158 iso_conn->info.can_send = true; in store_cis_info()
1159 } else if (iso->role == BT_HCI_ROLE_CENTRAL && evt->c_bn > 0) { in store_cis_info()
1160 iso_conn->info.can_send = true; in store_cis_info()
1165 iso_conn->info.can_recv = false; in store_cis_info()
1167 if (iso->role == BT_HCI_ROLE_PERIPHERAL && evt->c_bn > 0) { in store_cis_info()
1168 iso_conn->info.can_recv = true; in store_cis_info()
1169 } else if (iso->role == BT_HCI_ROLE_CENTRAL && evt->p_bn > 0) { in store_cis_info()
1170 iso_conn->info.can_recv = true; in store_cis_info()
1174 info->iso_interval = sys_le16_to_cpu(evt->interval); in store_cis_info()
1175 info->max_subevent = evt->nse; in store_cis_info()
1177 unicast_info->cig_sync_delay = sys_get_le24(evt->cig_sync_delay); in store_cis_info()
1178 unicast_info->cis_sync_delay = sys_get_le24(evt->cis_sync_delay); in store_cis_info()
1180 central->bn = evt->c_bn; in store_cis_info()
1181 central->phy = bt_get_phy(evt->c_phy); in store_cis_info()
1182 central->latency = sys_get_le16(evt->c_latency); in store_cis_info()
1183 central->max_pdu = sys_le16_to_cpu(evt->c_max_pdu); in store_cis_info()
1185 central->flush_timeout = info->iso_interval * evt->c_ft; in store_cis_info()
1187 peripheral->bn = evt->p_bn; in store_cis_info()
1188 peripheral->phy = bt_get_phy(evt->p_phy); in store_cis_info()
1189 peripheral->latency = sys_get_le16(evt->p_latency); in store_cis_info()
1190 peripheral->max_pdu = sys_le16_to_cpu(evt->p_max_pdu); in store_cis_info()
1192 peripheral->flush_timeout = info->iso_interval * evt->p_ft; in store_cis_info()
1197 unicast_info->subinterval = BT_ISO_SUBINTERVAL_UNKNOWN; in store_cis_info()
1199 if (iso->role == BT_HCI_ROLE_PERIPHERAL) { in store_cis_info()
1200 central->max_sdu = central->max_pdu; in store_cis_info()
1201 central->sdu_interval = BT_ISO_SDU_INTERVAL_UNKNOWN; in store_cis_info()
1203 peripheral->max_sdu = peripheral->max_pdu; in store_cis_info()
1204 peripheral->sdu_interval = BT_ISO_SDU_INTERVAL_UNKNOWN; in store_cis_info()
1206 central->max_sdu = tx == NULL ? 0 : tx->sdu; in store_cis_info()
1207 central->sdu_interval = BT_ISO_SDU_INTERVAL_UNKNOWN; in store_cis_info()
1209 peripheral->max_sdu = rx == NULL ? 0 : rx->sdu; in store_cis_info()
1210 peripheral->sdu_interval = BT_ISO_SDU_INTERVAL_UNKNOWN; in store_cis_info()
1220 struct bt_conn_iso *iso_conn = &iso->iso; in store_cis_info_v2()
1221 struct bt_iso_info *info = &iso_conn->info; in store_cis_info_v2()
1222 struct bt_iso_unicast_info *unicast_info = &info->unicast; in store_cis_info_v2()
1223 struct bt_iso_unicast_tx_info *peripheral = &unicast_info->peripheral; in store_cis_info_v2()
1224 struct bt_iso_unicast_tx_info *central = &unicast_info->central; in store_cis_info_v2()
1225 const uint16_t c_max_sdu = sys_le16_to_cpu(evt->c_max_sdu); in store_cis_info_v2()
1226 const uint16_t p_max_sdu = sys_le16_to_cpu(evt->p_max_sdu); in store_cis_info_v2()
1231 /* The v1 version of the event is a subset of the v2 version - We can thus use the in store_cis_info_v2()
1236 chan = iso_conn->chan; in store_cis_info_v2()
1237 rx = chan->qos->rx; in store_cis_info_v2()
1238 tx = chan->qos->tx; in store_cis_info_v2()
1240 if (iso->role == BT_HCI_ROLE_PERIPHERAL) { in store_cis_info_v2()
1243 rx->sdu = c_max_sdu; in store_cis_info_v2()
1247 tx->sdu = p_max_sdu; in store_cis_info_v2()
1250 /* values are already set for central - Verify */ in store_cis_info_v2()
1251 if (tx != NULL && tx->sdu != c_max_sdu) { in store_cis_info_v2()
1252 LOG_WRN("Unexpected C to P max SDU: %u != %u", c_max_sdu, tx->sdu); in store_cis_info_v2()
1253 /* We assume that tx->sdu has become invalid, and will use the event from in store_cis_info_v2()
1256 tx->sdu = c_max_sdu; in store_cis_info_v2()
1259 if (rx != NULL && rx->sdu != p_max_sdu) { in store_cis_info_v2()
1260 LOG_WRN("Unexpected P to C max SDU: %u != %u", p_max_sdu, rx->sdu); in store_cis_info_v2()
1261 /* We assume that rx->sdu has become invalid, and will use the event from in store_cis_info_v2()
1264 rx->sdu = p_max_sdu; in store_cis_info_v2()
1268 unicast_info->subinterval = sys_get_le24(evt->sub_interval); in store_cis_info_v2()
1270 central->max_sdu = sys_le16_to_cpu(evt->c_max_sdu); in store_cis_info_v2()
1271 central->sdu_interval = sys_get_le24(evt->c_sdu_interval); in store_cis_info_v2()
1273 peripheral->max_sdu = sys_le16_to_cpu(evt->p_max_sdu); in store_cis_info_v2()
1274 peripheral->sdu_interval = sys_get_le24(evt->p_sdu_interval); in store_cis_info_v2()
1279 struct bt_hci_evt_le_cis_established *evt = (void *)buf->data; in hci_le_cis_established()
1280 uint16_t handle = sys_le16_to_cpu(evt->conn_handle); in hci_le_cis_established()
1283 LOG_DBG("status 0x%02x %s handle %u", evt->status, bt_hci_err_to_str(evt->status), handle); in hci_le_cis_established()
1292 if (evt->status != BT_HCI_ERR_OP_CANCELLED_BY_HOST) { in hci_le_cis_established()
1299 if (evt->status == BT_HCI_ERR_SUCCESS) { in hci_le_cis_established()
1302 } else if (iso->role == BT_HCI_ROLE_PERIPHERAL || in hci_le_cis_established()
1303 evt->status != BT_HCI_ERR_OP_CANCELLED_BY_HOST) { in hci_le_cis_established()
1304 iso->err = evt->status; in hci_le_cis_established()
1313 struct bt_hci_evt_le_cis_established_v2 *evt = (void *)buf->data; in hci_le_cis_established_v2()
1314 uint16_t handle = sys_le16_to_cpu(evt->conn_handle); in hci_le_cis_established_v2()
1317 LOG_DBG("status 0x%02x %s handle %u", evt->status, bt_hci_err_to_str(evt->status), handle); in hci_le_cis_established_v2()
1326 if (evt->status != BT_HCI_ERR_OP_CANCELLED_BY_HOST) { in hci_le_cis_established_v2()
1333 if (evt->status == BT_HCI_ERR_SUCCESS) { in hci_le_cis_established_v2()
1336 } else if (iso->role == BT_HCI_ROLE_PERIPHERAL || in hci_le_cis_established_v2()
1337 evt->status != BT_HCI_ERR_OP_CANCELLED_BY_HOST) { in hci_le_cis_established_v2()
1338 iso->err = evt->status; in hci_le_cis_established_v2()
1350 return -EINVAL; in bt_iso_server_register()
1355 return -ENOTSUP; in bt_iso_server_register()
1359 return -EADDRINUSE; in bt_iso_server_register()
1362 if (!server->accept) { in bt_iso_server_register()
1363 return -EINVAL; in bt_iso_server_register()
1367 if (server->sec_level > BT_SECURITY_L3) { in bt_iso_server_register()
1368 return -EINVAL; in bt_iso_server_register()
1369 } else if (server->sec_level < BT_SECURITY_L1) { in bt_iso_server_register()
1371 server->sec_level = BT_SECURITY_L1; in bt_iso_server_register()
1386 return -EINVAL; in bt_iso_server_unregister()
1390 return -EINVAL; in bt_iso_server_unregister()
1404 CHECKIF(!iso || iso->type != BT_CONN_TYPE_ISO) { in iso_accept()
1405 LOG_DBG("Invalid parameters: iso %p iso->type %u", iso, iso ? iso->type : 0); in iso_accept()
1406 return -EINVAL; in iso_accept()
1412 accept_info.cig_id = iso->iso.cig_id; in iso_accept()
1413 accept_info.cis_id = iso->iso.cis_id; in iso_accept()
1415 err = iso_server->accept(&accept_info, &chan); in iso_accept()
1422 chan->required_sec_level = iso_server->sec_level; in iso_accept()
1439 return -ENOBUFS; in hci_le_reject_cis()
1443 cp->handle = sys_cpu_to_le16(handle); in hci_le_reject_cis()
1444 cp->reason = reason; in hci_le_reject_cis()
1462 return -ENOBUFS; in hci_le_accept_cis()
1466 cp->handle = sys_cpu_to_le16(handle); in hci_le_accept_cis()
1483 if (conn->sec_level >= iso_server->sec_level) { in iso_server_check_security()
1495 struct bt_hci_evt_le_cis_req *evt = (void *)buf->data; in hci_le_cis_req()
1496 uint16_t acl_handle = sys_le16_to_cpu(evt->acl_handle); in hci_le_cis_req()
1497 uint16_t cis_handle = sys_le16_to_cpu(evt->cis_handle); in hci_le_cis_req()
1502 LOG_DBG("acl_handle %u cis_handle %u cig_id %u cis %u", acl_handle, cis_handle, evt->cig_id, in hci_le_cis_req()
1503 evt->cis_id); in hci_le_cis_req()
1551 iso->iso.info.type = BT_ISO_CHAN_TYPE_CONNECTED; in hci_le_cis_req()
1552 iso->iso.cig_id = evt->cig_id; in hci_le_cis_req()
1553 iso->iso.cis_id = evt->cis_id; in hci_le_cis_req()
1565 iso->handle = cis_handle; in hci_le_cis_req()
1566 iso->role = BT_HCI_ROLE_PERIPHERAL; in hci_le_cis_req()
1587 iso->iso.acl = bt_conn_ref(acl); in bt_conn_add_iso()
1603 return -ENOBUFS; in hci_le_remove_iso_data_path()
1607 cp->handle = sys_cpu_to_le16(iso->handle); in hci_le_remove_iso_data_path()
1608 cp->path_dir = dir; in hci_le_remove_iso_data_path()
1615 rp = (void *)rsp->data; in hci_le_remove_iso_data_path()
1616 if (rp->status || (sys_le16_to_cpu(rp->handle) != iso->handle)) { in hci_le_remove_iso_data_path()
1617 err = -EIO; in hci_le_remove_iso_data_path()
1627 enum bt_iso_chan_type type = iso->iso.info.type; in bt_iso_remove_data_path()
1645 tx_qos = chan->qos->tx; in bt_iso_remove_data_path()
1671 if (advanced && !IN_RANGE(qos->num_subevents, BT_ISO_NSE_MIN, BT_ISO_NSE_MAX)) { in valid_chan_qos()
1672 LOG_DBG("Invalid NSE: %u", qos->num_subevents); in valid_chan_qos()
1678 if (qos->rx != NULL) { in valid_chan_qos()
1679 if (!valid_chan_io_qos(qos->rx, false, false, advanced)) { in valid_chan_qos()
1683 } else if (qos->tx == NULL) { in valid_chan_qos()
1688 if (qos->tx != NULL) { in valid_chan_qos()
1689 if (!valid_chan_io_qos(qos->tx, true, false, advanced)) { in valid_chan_qos()
1705 return -ENOBUFS; in hci_le_remove_cig()
1712 req->cig_id = cig_id; in hci_le_remove_cig()
1727 sizeof(*req) + sizeof(*cis_param) * param->num_cis); in hci_le_set_cig_params()
1736 req->cig_id = cig->id; in hci_le_set_cig_params()
1737 req->c_latency = sys_cpu_to_le16(param->c_to_p_latency); in hci_le_set_cig_params()
1738 req->p_latency = sys_cpu_to_le16(param->p_to_c_latency); in hci_le_set_cig_params()
1739 sys_put_le24(param->c_to_p_interval, req->c_interval); in hci_le_set_cig_params()
1740 sys_put_le24(param->p_to_c_interval, req->p_interval); in hci_le_set_cig_params()
1742 req->sca = param->sca; in hci_le_set_cig_params()
1743 req->packing = param->packing; in hci_le_set_cig_params()
1744 req->framing = param->framing; in hci_le_set_cig_params()
1745 req->num_cis = param->num_cis; in hci_le_set_cig_params()
1750 cig->id, param->c_to_p_latency, param->p_to_c_latency, param->c_to_p_interval, in hci_le_set_cig_params()
1751 param->p_to_c_interval, param->sca, param->packing, param->framing, param->num_cis); in hci_le_set_cig_params()
1754 for (i = 0; i < param->num_cis; i++) { in hci_le_set_cig_params()
1755 struct bt_iso_chan *cis = param->cis_channels[i]; in hci_le_set_cig_params()
1756 struct bt_iso_chan_qos *qos = cis->qos; in hci_le_set_cig_params()
1762 cis_param->cis_id = cis->iso->iso.cis_id; in hci_le_set_cig_params()
1764 if (!qos->tx && !qos->rx) { in hci_le_set_cig_params()
1770 if (!qos->tx) { in hci_le_set_cig_params()
1774 cis_param->c_phy = qos->rx->phy; in hci_le_set_cig_params()
1776 cis_param->c_sdu = sys_cpu_to_le16(qos->tx->sdu); in hci_le_set_cig_params()
1777 cis_param->c_phy = qos->tx->phy; in hci_le_set_cig_params()
1778 cis_param->c_rtn = qos->tx->rtn; in hci_le_set_cig_params()
1781 if (!qos->rx) { in hci_le_set_cig_params()
1785 cis_param->p_phy = qos->tx->phy; in hci_le_set_cig_params()
1787 cis_param->p_sdu = sys_cpu_to_le16(qos->rx->sdu); in hci_le_set_cig_params()
1788 cis_param->p_phy = qos->rx->phy; in hci_le_set_cig_params()
1789 cis_param->p_rtn = qos->rx->rtn; in hci_le_set_cig_params()
1793 i, cis_param->cis_id, cis_param->c_phy, cis_param->c_sdu, cis_param->c_rtn, in hci_le_set_cig_params()
1794 cis_param->p_phy, cis_param->p_sdu, cis_param->p_rtn); in hci_le_set_cig_params()
1816 sizeof(*req) + sizeof(*cis_param) * param->num_cis); in hci_le_set_cig_test_params()
1825 req->cig_id = cig->id; in hci_le_set_cig_test_params()
1826 sys_put_le24(param->c_to_p_interval, req->c_interval); in hci_le_set_cig_test_params()
1827 sys_put_le24(param->p_to_c_interval, req->p_interval); in hci_le_set_cig_test_params()
1829 req->c_ft = param->c_to_p_ft; in hci_le_set_cig_test_params()
1830 req->p_ft = param->p_to_c_ft; in hci_le_set_cig_test_params()
1831 req->iso_interval = sys_cpu_to_le16(param->iso_interval); in hci_le_set_cig_test_params()
1832 req->sca = param->sca; in hci_le_set_cig_test_params()
1833 req->packing = param->packing; in hci_le_set_cig_test_params()
1834 req->framing = param->framing; in hci_le_set_cig_test_params()
1835 req->num_cis = param->num_cis; in hci_le_set_cig_test_params()
1839 cig->id, param->c_to_p_interval, param->p_to_c_interval, param->c_to_p_ft, in hci_le_set_cig_test_params()
1840 param->p_to_c_ft, param->iso_interval, param->sca, param->packing, param->framing, in hci_le_set_cig_test_params()
1841 param->num_cis); in hci_le_set_cig_test_params()
1844 for (uint8_t i = 0U; i < param->num_cis; i++) { in hci_le_set_cig_test_params()
1845 const struct bt_iso_chan *cis = param->cis_channels[i]; in hci_le_set_cig_test_params()
1846 const struct bt_iso_chan_qos *qos = cis->qos; in hci_le_set_cig_test_params()
1852 cis_param->cis_id = cis->iso->iso.cis_id; in hci_le_set_cig_test_params()
1853 cis_param->nse = qos->num_subevents; in hci_le_set_cig_test_params()
1855 if (!qos->tx && !qos->rx) { in hci_le_set_cig_test_params()
1861 if (!qos->tx) { in hci_le_set_cig_test_params()
1865 cis_param->c_phy = qos->rx->phy; in hci_le_set_cig_test_params()
1867 cis_param->c_sdu = sys_cpu_to_le16(qos->tx->sdu); in hci_le_set_cig_test_params()
1868 cis_param->c_pdu = sys_cpu_to_le16(qos->tx->max_pdu); in hci_le_set_cig_test_params()
1869 cis_param->c_phy = qos->tx->phy; in hci_le_set_cig_test_params()
1870 cis_param->c_bn = qos->tx->burst_number; in hci_le_set_cig_test_params()
1873 if (!qos->rx) { in hci_le_set_cig_test_params()
1877 cis_param->p_phy = qos->tx->phy; in hci_le_set_cig_test_params()
1879 cis_param->p_sdu = sys_cpu_to_le16(qos->rx->sdu); in hci_le_set_cig_test_params()
1880 cis_param->p_pdu = sys_cpu_to_le16(qos->rx->max_pdu); in hci_le_set_cig_test_params()
1881 cis_param->p_phy = qos->rx->phy; in hci_le_set_cig_test_params()
1882 cis_param->p_bn = qos->rx->burst_number; in hci_le_set_cig_test_params()
1887 i, cis_param->cis_id, cis_param->nse, cis_param->c_sdu, cis_param->p_sdu, in hci_le_set_cig_test_params()
1888 cis_param->c_pdu, cis_param->p_pdu, cis_param->c_phy, cis_param->p_phy, in hci_le_set_cig_test_params()
1889 cis_param->c_bn, cis_param->p_bn); in hci_le_set_cig_test_params()
1902 if (param->c_to_p_ft != 0U || param->p_to_c_ft != 0U || param->iso_interval != 0U) { in is_advanced_cig_param()
1906 /* Check if any of the CIS contain any test-param-only values */ in is_advanced_cig_param()
1907 for (uint8_t i = 0U; i < param->num_cis; i++) { in is_advanced_cig_param()
1908 const struct bt_iso_chan *cis = param->cis_channels[i]; in is_advanced_cig_param()
1909 const struct bt_iso_chan_qos *qos = cis->qos; in is_advanced_cig_param()
1911 if (qos->num_subevents > 0U) { in is_advanced_cig_param()
1915 if (qos->tx != NULL) { in is_advanced_cig_param()
1916 if (qos->tx->max_pdu > 0U || qos->tx->burst_number > 0U) { in is_advanced_cig_param()
1921 if (qos->rx != NULL) { in is_advanced_cig_param()
1922 if (qos->rx->max_pdu > 0U || qos->rx->burst_number > 0U) { in is_advanced_cig_param()
1934 if (iso_chan == NULL || iso_chan->iso == NULL) { in get_cig()
1938 __ASSERT(iso_chan->iso->iso.cig_id < ARRAY_SIZE(cigs), "Invalid cig_id %u", in get_cig()
1939 iso_chan->iso->iso.cig_id); in get_cig()
1941 return &cigs[iso_chan->iso->iso.cig_id]; in get_cig()
1964 if (cig == NULL || cis == NULL || cis->iso == NULL) { in cis_is_in_cig()
1968 return cig->id == cis->iso->iso.cig_id; in cis_is_in_cig()
1973 for (uint8_t i = 0; i < param->num_cis; i++) { in cig_init_cis()
1974 struct bt_iso_chan *cis = param->cis_channels[i]; in cig_init_cis()
1976 if (cis->iso == NULL) { in cig_init_cis()
1979 cis->iso = iso_new(); in cig_init_cis()
1980 if (cis->iso == NULL) { in cig_init_cis()
1982 return -ENOMEM; in cig_init_cis()
1984 iso_conn = &cis->iso->iso; in cig_init_cis()
1986 iso_conn->cig_id = cig->id; in cig_init_cis()
1987 iso_conn->info.type = BT_ISO_CHAN_TYPE_CONNECTED; in cig_init_cis()
1988 iso_conn->cis_id = cig->num_cis++; in cig_init_cis()
1990 bt_iso_chan_add(cis->iso, cis); in cig_init_cis()
1992 sys_slist_append(&cig->cis_channels, &cis->node); in cig_init_cis()
2003 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&cig->cis_channels, cis, tmp, node) { in cleanup_cig()
2004 if (cis->iso != NULL) { in cleanup_cig()
2005 bt_conn_unref(cis->iso); in cleanup_cig()
2006 cis->iso = NULL; in cleanup_cig()
2009 sys_slist_remove(&cig->cis_channels, NULL, &cis->node); in cleanup_cig()
2025 for (uint8_t i = 0; i < param->num_cis; i++) { in valid_cig_param()
2026 struct bt_iso_chan *cis = param->cis_channels[i]; in valid_cig_param()
2033 if (cis->qos == NULL) { in valid_cig_param()
2038 if (cis->iso != NULL && !cis_is_in_cig(cig, cis)) { in valid_cig_param()
2043 if (!valid_chan_qos(cis->qos, advanced)) { in valid_cig_param()
2049 if (cis == param->cis_channels[j]) { in valid_cig_param()
2055 if (cis->qos->rx != NULL && cis->qos->rx->sdu != 0U) { in valid_cig_param()
2059 if (cis->qos->tx != NULL && cis->qos->tx->sdu != 0U) { in valid_cig_param()
2064 if (param->framing != BT_ISO_FRAMING_UNFRAMED && param->framing != BT_ISO_FRAMING_FRAMED) { in valid_cig_param()
2065 LOG_DBG("Invalid framing parameter: %u", param->framing); in valid_cig_param()
2069 if (param->packing != BT_ISO_PACKING_SEQUENTIAL && in valid_cig_param()
2070 param->packing != BT_ISO_PACKING_INTERLEAVED) { in valid_cig_param()
2071 LOG_DBG("Invalid packing parameter: %u", param->packing); in valid_cig_param()
2075 if (param->num_cis > BT_ISO_MAX_GROUP_ISO_COUNT || in valid_cig_param()
2076 param->num_cis > CONFIG_BT_ISO_MAX_CHAN) { in valid_cig_param()
2077 LOG_DBG("num_cis (%u) shall be lower than: %u", param->num_cis, in valid_cig_param()
2083 !IN_RANGE(param->c_to_p_interval, BT_ISO_SDU_INTERVAL_MIN, BT_ISO_SDU_INTERVAL_MAX)) { in valid_cig_param()
2084 LOG_DBG("Invalid C to P interval: %u", param->c_to_p_interval); in valid_cig_param()
2089 !IN_RANGE(param->p_to_c_interval, BT_ISO_SDU_INTERVAL_MIN, BT_ISO_SDU_INTERVAL_MAX)) { in valid_cig_param()
2090 LOG_DBG("Invalid P to C interval: %u", param->p_to_c_interval); in valid_cig_param()
2096 !IN_RANGE(param->c_to_p_latency, BT_ISO_LATENCY_MIN, BT_ISO_LATENCY_MAX)) { in valid_cig_param()
2097 LOG_DBG("Invalid C to P latency: %u", param->c_to_p_latency); in valid_cig_param()
2102 !IN_RANGE(param->p_to_c_latency, BT_ISO_LATENCY_MIN, BT_ISO_LATENCY_MAX)) { in valid_cig_param()
2103 LOG_DBG("Invalid P to C latency: %u", param->p_to_c_latency); in valid_cig_param()
2110 if (!IN_RANGE(param->c_to_p_ft, BT_ISO_FT_MIN, BT_ISO_FT_MAX)) { in valid_cig_param()
2111 LOG_DBG("Invalid Central to Peripheral FT %u", param->c_to_p_ft); in valid_cig_param()
2116 if (!IN_RANGE(param->p_to_c_ft, BT_ISO_FT_MIN, BT_ISO_FT_MAX)) { in valid_cig_param()
2117 LOG_DBG("Invalid Peripheral to Central FT %u", param->p_to_c_ft); in valid_cig_param()
2122 if (!IN_RANGE(param->iso_interval, BT_ISO_ISO_INTERVAL_MIN, in valid_cig_param()
2124 LOG_DBG("Invalid ISO interval %u", param->iso_interval); in valid_cig_param()
2146 return -EINVAL; in bt_iso_cig_create()
2151 return -EINVAL; in bt_iso_cig_create()
2158 return -ENOTSUP; in bt_iso_cig_create()
2162 CHECKIF(param->cis_channels == NULL) { in bt_iso_cig_create()
2164 return -EINVAL; in bt_iso_cig_create()
2167 CHECKIF(param->num_cis == 0) { in bt_iso_cig_create()
2168 LOG_DBG("Invalid number of CIS %u", param->num_cis); in bt_iso_cig_create()
2169 return -EINVAL; in bt_iso_cig_create()
2178 return -EINVAL; in bt_iso_cig_create()
2184 return -ENOMEM; in bt_iso_cig_create()
2204 err = -EIO; in bt_iso_cig_create()
2209 cig_rsp = (void *)rsp->data; in bt_iso_cig_create()
2211 if (rsp->len < sizeof(cig_rsp) || cig_rsp->num_handles != param->num_cis) { in bt_iso_cig_create()
2213 err = -EIO; in bt_iso_cig_create()
2220 SYS_SLIST_FOR_EACH_CONTAINER(&cig->cis_channels, cis, node) { in bt_iso_cig_create()
2221 const uint16_t handle = cig_rsp->handle[i++]; in bt_iso_cig_create()
2224 cis->iso->handle = sys_le16_to_cpu(handle); in bt_iso_cig_create()
2238 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&cig->cis_channels, cis, tmp, node) { in restore_cig()
2243 if (cis->iso != NULL && cis->iso->iso.cis_id >= existing_num_cis) { in restore_cig()
2244 bt_conn_unref(cis->iso); in restore_cig()
2245 cis->iso = NULL; in restore_cig()
2247 sys_slist_remove(&cig->cis_channels, NULL, &cis->node); in restore_cig()
2248 cig->num_cis--; in restore_cig()
2263 return -EINVAL; in bt_iso_cig_reconfigure()
2268 return -EINVAL; in bt_iso_cig_reconfigure()
2271 if (cig->state != BT_ISO_CIG_STATE_CONFIGURED) { in bt_iso_cig_reconfigure()
2272 LOG_DBG("Invalid CIG state: %u", cig->state); in bt_iso_cig_reconfigure()
2273 return -EINVAL; in bt_iso_cig_reconfigure()
2282 return -EINVAL; in bt_iso_cig_reconfigure()
2286 existing_num_cis = cig->num_cis; in bt_iso_cig_reconfigure()
2305 err = -EIO; in bt_iso_cig_reconfigure()
2310 cig_rsp = (void *)rsp->data; in bt_iso_cig_reconfigure()
2312 if (rsp->len < sizeof(*cig_rsp)) { in bt_iso_cig_reconfigure()
2313 LOG_WRN("Unexpected response len to hci_le_set_cig_params %u != %zu", rsp->len, in bt_iso_cig_reconfigure()
2315 err = -EIO; in bt_iso_cig_reconfigure()
2321 if (cig_rsp->num_handles != param->num_cis) { in bt_iso_cig_reconfigure()
2323 cig_rsp->num_handles, param->num_cis); in bt_iso_cig_reconfigure()
2324 err = -EIO; in bt_iso_cig_reconfigure()
2330 for (uint8_t i = 0u; i < param->num_cis; i++) { in bt_iso_cig_reconfigure()
2331 const uint16_t handle = cig_rsp->handle[i]; in bt_iso_cig_reconfigure()
2332 struct bt_iso_chan *cis = param->cis_channels[i]; in bt_iso_cig_reconfigure()
2335 cis->iso->handle = sys_le16_to_cpu(handle); in bt_iso_cig_reconfigure()
2349 return -EINVAL; in bt_iso_cig_terminate()
2352 if (cig->state != BT_ISO_CIG_STATE_INACTIVE && cig->state != BT_ISO_CIG_STATE_CONFIGURED) { in bt_iso_cig_terminate()
2353 LOG_DBG("Invalid CIG state: %u", cig->state); in bt_iso_cig_terminate()
2354 return -EINVAL; in bt_iso_cig_terminate()
2357 err = hci_le_remove_cig(cig->id); in bt_iso_cig_terminate()
2378 if (!IS_ENABLED(CONFIG_BT_CENTRAL) || acl->role != BT_CONN_ROLE_CENTRAL) { in bt_iso_security_changed()
2387 if (iso == NULL || iso->iso.acl != acl) { in bt_iso_security_changed()
2392 if (iso_chan->state != BT_ISO_STATE_ENCRYPT_PENDING) { in bt_iso_security_changed()
2414 if (iso_chan->ops->disconnected) { in bt_iso_security_changed()
2415 iso_chan->ops->disconnected(iso_chan, hci_status); in bt_iso_security_changed()
2437 if (iso_chan->ops->disconnected) { in bt_iso_security_changed()
2438 iso_chan->ops->disconnected(iso_chan, hci_status); in bt_iso_security_changed()
2451 cig->state = BT_ISO_CIG_STATE_ACTIVE; in bt_iso_security_changed()
2453 bt_conn_set_state(iso_chan->iso, BT_CONN_INITIATING); in bt_iso_security_changed()
2466 return -ENOBUFS; in hci_le_create_cis()
2477 if (iso_chan->state == BT_ISO_STATE_ENCRYPT_PENDING) { in hci_le_create_cis()
2485 cis->cis_handle = sys_cpu_to_le16(param[i].iso_chan->iso->handle); in hci_le_create_cis()
2486 cis->acl_handle = sys_cpu_to_le16(param[i].acl->handle); in hci_le_create_cis()
2487 req->num_cis++; in hci_le_create_cis()
2493 if (req->num_cis == 0) { in hci_le_create_cis()
2496 return -ECANCELED; in hci_le_create_cis()
2518 if (acl->sec_level < iso_chan->required_sec_level) { in iso_chan_connect_security()
2522 err = bt_conn_set_security(acl, iso_chan->required_sec_level); in iso_chan_connect_security()
2530 bt_iso_cleanup_acl(iso_chan->iso); in iso_chan_connect_security()
2541 iso_chan->iso->iso.acl = bt_conn_ref(acl); in iso_chan_connect_security()
2556 if (iso == NULL || iso->iso.info.type != BT_ISO_CHAN_TYPE_CONNECTED) { in iso_chans_connecting()
2561 if (iso_chan->state == BT_ISO_STATE_CONNECTING || in iso_chans_connecting()
2562 iso_chan->state == BT_ISO_STATE_ENCRYPT_PENDING) { in iso_chans_connecting()
2576 return -EINVAL; in bt_iso_chan_connect()
2581 return -EINVAL; in bt_iso_chan_connect()
2585 return -EINVAL; in bt_iso_chan_connect()
2592 return -EINVAL; in bt_iso_chan_connect()
2597 return -EINVAL; in bt_iso_chan_connect()
2600 CHECKIF((param[i].acl->type & BT_CONN_TYPE_LE) == 0) { in bt_iso_chan_connect()
2602 param[i].acl->type); in bt_iso_chan_connect()
2603 return -EINVAL; in bt_iso_chan_connect()
2606 if (param[i].iso_chan->iso == NULL) { in bt_iso_chan_connect()
2608 return -EINVAL; in bt_iso_chan_connect()
2611 if (param[i].iso_chan->state != BT_ISO_STATE_DISCONNECTED) { in bt_iso_chan_connect()
2613 param[i].iso_chan->state); in bt_iso_chan_connect()
2614 return -EINVAL; in bt_iso_chan_connect()
2620 return -EBUSY; in bt_iso_chan_connect()
2635 if (err == -ECANCELED) { in bt_iso_chan_connect()
2650 if (iso_chan->state == BT_ISO_STATE_ENCRYPT_PENDING) { in bt_iso_chan_connect()
2654 iso_chan->iso->iso.acl = bt_conn_ref(param[i].acl); in bt_iso_chan_connect()
2655 bt_conn_set_state(iso_chan->iso, BT_CONN_INITIATING); in bt_iso_chan_connect()
2660 cig->state = BT_ISO_CIG_STATE_ACTIVE; in bt_iso_chan_connect()
2712 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&big->bis_channels, bis, tmp, node) { in cleanup_big()
2713 if (bis->iso != NULL) { in cleanup_big()
2714 bt_conn_unref(bis->iso); in cleanup_big()
2715 bis->iso = NULL; in cleanup_big()
2718 sys_slist_remove(&big->bis_channels, NULL, &bis->node); in cleanup_big()
2728 SYS_SLIST_FOR_EACH_CONTAINER(&big->bis_channels, bis, node) { in big_disconnect()
2729 bis->iso->err = reason; in big_disconnect()
2738 if (listener->stopped != NULL) { in big_disconnect()
2739 listener->stopped(big, reason); in big_disconnect()
2752 bis->iso = iso_new(); in big_init_bis()
2754 if (!bis->iso) { in big_init_bis()
2756 return -ENOMEM; in big_init_bis()
2758 iso_conn = &bis->iso->iso; in big_init_bis()
2760 iso_conn->big_handle = big->handle; in big_init_bis()
2761 iso_conn->info.type = in big_init_bis()
2763 iso_conn->bis_id = bt_conn_index(bis->iso); in big_init_bis()
2765 bt_iso_chan_add(bis->iso, bis); in big_init_bis()
2767 sys_slist_append(&big->bis_channels, &bis->node); in big_init_bis()
2778 return -EINVAL; in bt_iso_big_register_cb()
2781 if (sys_slist_find(&iso_big_cbs, &cb->_node, NULL)) { in bt_iso_big_register_cb()
2784 return -EEXIST; in bt_iso_big_register_cb()
2787 sys_slist_append(&iso_big_cbs, &cb->_node); in bt_iso_big_register_cb()
2806 return -ENOBUFS; in hci_le_create_big()
2809 bis = SYS_SLIST_PEEK_HEAD_CONTAINER(&big->bis_channels, bis, node); in hci_le_create_big()
2813 qos = bis->qos->tx; in hci_le_create_big()
2816 req->big_handle = big->handle; in hci_le_create_big()
2817 req->adv_handle = padv->handle; in hci_le_create_big()
2818 req->num_bis = big->num_bis; in hci_le_create_big()
2819 sys_put_le24(param->interval, req->sdu_interval); in hci_le_create_big()
2820 req->max_sdu = sys_cpu_to_le16(qos->sdu); in hci_le_create_big()
2821 req->max_latency = sys_cpu_to_le16(param->latency); in hci_le_create_big()
2822 req->rtn = qos->rtn; in hci_le_create_big()
2823 req->phy = qos->phy; in hci_le_create_big()
2824 req->packing = param->packing; in hci_le_create_big()
2825 req->framing = param->framing; in hci_le_create_big()
2826 req->encryption = param->encryption; in hci_le_create_big()
2827 if (req->encryption) { in hci_le_create_big()
2828 memcpy(req->bcode, param->bcode, sizeof(req->bcode)); in hci_le_create_big()
2830 memset(req->bcode, 0, sizeof(req->bcode)); in hci_le_create_big()
2835 big->handle, padv->handle, big->num_bis, param->interval, qos->sdu, param->latency, in hci_le_create_big()
2836 qos->rtn, qos->phy, param->packing, param->framing, param->encryption); in hci_le_create_big()
2838 bt_hci_cmd_state_set_init(buf, &state, big->flags, BT_BIG_PENDING, true); in hci_le_create_big()
2845 SYS_SLIST_FOR_EACH_CONTAINER(&big->bis_channels, bis, node) { in hci_le_create_big()
2866 return -ENOBUFS; in hci_le_create_big_test()
2869 bis = SYS_SLIST_PEEK_HEAD_CONTAINER(&big->bis_channels, bis, node); in hci_le_create_big_test()
2873 qos = bis->qos; in hci_le_create_big_test()
2876 req->big_handle = big->handle; in hci_le_create_big_test()
2877 req->adv_handle = padv->handle; in hci_le_create_big_test()
2878 req->num_bis = big->num_bis; in hci_le_create_big_test()
2879 sys_put_le24(param->interval, req->sdu_interval); in hci_le_create_big_test()
2880 req->iso_interval = sys_cpu_to_le16(param->iso_interval); in hci_le_create_big_test()
2881 req->nse = qos->num_subevents; in hci_le_create_big_test()
2882 req->max_sdu = sys_cpu_to_le16(qos->tx->sdu); in hci_le_create_big_test()
2883 req->max_pdu = sys_cpu_to_le16(qos->tx->max_pdu); in hci_le_create_big_test()
2884 req->phy = qos->tx->phy; in hci_le_create_big_test()
2885 req->packing = param->packing; in hci_le_create_big_test()
2886 req->framing = param->framing; in hci_le_create_big_test()
2887 req->bn = qos->tx->burst_number; in hci_le_create_big_test()
2888 req->irc = param->irc; in hci_le_create_big_test()
2889 req->pto = param->pto; in hci_le_create_big_test()
2890 req->encryption = param->encryption; in hci_le_create_big_test()
2891 if (req->encryption) { in hci_le_create_big_test()
2892 memcpy(req->bcode, param->bcode, sizeof(req->bcode)); in hci_le_create_big_test()
2894 memset(req->bcode, 0, sizeof(req->bcode)); in hci_le_create_big_test()
2900 req->big_handle, req->adv_handle, req->num_bis, param->interval, in hci_le_create_big_test()
2901 param->iso_interval, req->nse, req->max_sdu, req->max_pdu, req->phy, req->packing, in hci_le_create_big_test()
2902 req->framing, req->bn, req->irc, req->pto, req->encryption); in hci_le_create_big_test()
2904 bt_hci_cmd_state_set_init(buf, &state, big->flags, BT_BIG_PENDING, true); in hci_le_create_big_test()
2910 SYS_SLIST_FOR_EACH_CONTAINER(&big->bis_channels, bis, node) { in hci_le_create_big_test()
2919 if (param->irc != 0U || param->iso_interval != 0U) { in is_advanced_big_param()
2923 /* Check if any of the CIS contain any test-param-only values */ in is_advanced_big_param()
2924 for (uint8_t i = 0U; i < param->num_bis; i++) { in is_advanced_big_param()
2925 const struct bt_iso_chan *bis = param->bis_channels[i]; in is_advanced_big_param()
2926 const struct bt_iso_chan_qos *qos = bis->qos; in is_advanced_big_param()
2928 if (qos->num_subevents > 0U) { in is_advanced_big_param()
2932 __ASSERT(qos->tx != NULL, "TX cannot be NULL for broadcaster"); in is_advanced_big_param()
2934 if (qos->tx->max_pdu > 0U || qos->tx->burst_number > 0U) { in is_advanced_big_param()
2945 CHECKIF(!param->bis_channels) { in valid_big_param()
2951 CHECKIF(!param->num_bis) { in valid_big_param()
2952 LOG_DBG("Invalid number of BIS %u", param->num_bis); in valid_big_param()
2957 for (uint8_t i = 0; i < param->num_bis; i++) { in valid_big_param()
2958 struct bt_iso_chan *bis = param->bis_channels[i]; in valid_big_param()
2966 if (bis->iso) { in valid_big_param()
2972 CHECKIF(bis->qos == NULL) { in valid_big_param()
2978 CHECKIF(bis->qos->tx == NULL || in valid_big_param()
2979 !valid_chan_io_qos(bis->qos->tx, true, true, advanced)) { in valid_big_param()
2986 CHECKIF(param->framing != BT_ISO_FRAMING_UNFRAMED && in valid_big_param()
2987 param->framing != BT_ISO_FRAMING_FRAMED) { in valid_big_param()
2988 LOG_DBG("Invalid framing parameter: %u", param->framing); in valid_big_param()
2993 CHECKIF(param->packing != BT_ISO_PACKING_SEQUENTIAL && in valid_big_param()
2994 param->packing != BT_ISO_PACKING_INTERLEAVED) { in valid_big_param()
2995 LOG_DBG("Invalid packing parameter: %u", param->packing); in valid_big_param()
3000 CHECKIF(param->num_bis > BT_ISO_MAX_GROUP_ISO_COUNT || in valid_big_param()
3001 param->num_bis > CONFIG_BT_ISO_MAX_CHAN) { in valid_big_param()
3002 LOG_DBG("num_bis (%u) shall be lower than: %u", param->num_bis, in valid_big_param()
3008 CHECKIF(!IN_RANGE(param->interval, BT_ISO_SDU_INTERVAL_MIN, BT_ISO_SDU_INTERVAL_MAX)) { in valid_big_param()
3009 LOG_DBG("Invalid interval: %u", param->interval); in valid_big_param()
3014 CHECKIF(!advanced && !IN_RANGE(param->latency, BT_ISO_LATENCY_MIN, BT_ISO_LATENCY_MAX)) { in valid_big_param()
3015 LOG_DBG("Invalid latency: %u", param->latency); in valid_big_param()
3022 CHECKIF(!IN_RANGE(param->irc, BT_ISO_IRC_MIN, BT_ISO_IRC_MAX)) { in valid_big_param()
3023 LOG_DBG("Invalid IRC %u", param->irc); in valid_big_param()
3028 CHECKIF(!IN_RANGE(param->pto, BT_ISO_PTO_MIN, BT_ISO_PTO_MAX)) { in valid_big_param()
3029 LOG_DBG("Invalid PTO %u", param->pto); in valid_big_param()
3034 CHECKIF(!IN_RANGE(param->iso_interval, BT_ISO_ISO_INTERVAL_MIN, in valid_big_param()
3036 LOG_DBG("Invalid ISO interval %u", param->iso_interval); in valid_big_param()
3055 return -EINVAL; in bt_iso_big_create()
3060 return -EINVAL; in bt_iso_big_create()
3065 return -EINVAL; in bt_iso_big_create()
3068 if (!atomic_test_bit(padv->flags, BT_PER_ADV_PARAMS_SET)) { in bt_iso_big_create()
3070 return -EINVAL; in bt_iso_big_create()
3080 return -EINVAL; in bt_iso_big_create()
3086 return -ENOMEM; in bt_iso_big_create()
3089 err = big_init_bis(big, param->bis_channels, param->num_bis, true); in bt_iso_big_create()
3095 big->num_bis = param->num_bis; in bt_iso_big_create()
3119 struct bt_iso_broadcaster_info *broadcaster_info = &info->broadcaster; in store_bis_broadcaster_info()
3121 info->iso_interval = sys_le16_to_cpu(evt->iso_interval); in store_bis_broadcaster_info()
3122 info->max_subevent = evt->nse; in store_bis_broadcaster_info()
3124 broadcaster_info->sync_delay = sys_get_le24(evt->sync_delay); in store_bis_broadcaster_info()
3125 broadcaster_info->latency = sys_get_le24(evt->latency); in store_bis_broadcaster_info()
3126 broadcaster_info->phy = bt_get_phy(evt->phy); in store_bis_broadcaster_info()
3127 broadcaster_info->bn = evt->bn; in store_bis_broadcaster_info()
3128 broadcaster_info->irc = evt->irc; in store_bis_broadcaster_info()
3130 broadcaster_info->pto = info->iso_interval * evt->pto; in store_bis_broadcaster_info()
3131 broadcaster_info->max_pdu = sys_le16_to_cpu(evt->max_pdu); in store_bis_broadcaster_info()
3133 info->can_send = true; in store_bis_broadcaster_info()
3134 info->can_recv = false; in store_bis_broadcaster_info()
3139 struct bt_hci_evt_le_big_complete *evt = (void *)buf->data; in hci_le_big_complete()
3144 if (evt->big_handle >= ARRAY_SIZE(bigs)) { in hci_le_big_complete()
3149 big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED); in hci_le_big_complete()
3156 big = lookup_big_by_handle(evt->big_handle); in hci_le_big_complete()
3157 atomic_clear_bit(big->flags, BT_BIG_PENDING); in hci_le_big_complete()
3159 LOG_DBG("BIG[%u] %p completed, status 0x%02x %s", big->handle, big, evt->status, in hci_le_big_complete()
3160 bt_hci_err_to_str(evt->status)); in hci_le_big_complete()
3162 if (evt->status || evt->num_bis != big->num_bis) { in hci_le_big_complete()
3163 if (evt->status == BT_HCI_ERR_SUCCESS && evt->num_bis != big->num_bis) { in hci_le_big_complete()
3164 LOG_ERR("Invalid number of BIS created, was %u expected %u", evt->num_bis, in hci_le_big_complete()
3165 big->num_bis); in hci_le_big_complete()
3167 big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED); in hci_le_big_complete()
3173 SYS_SLIST_FOR_EACH_CONTAINER(&big->bis_channels, bis, node) { in hci_le_big_complete()
3174 const uint16_t handle = evt->handle[i++]; in hci_le_big_complete()
3175 struct bt_conn *iso_conn = bis->iso; in hci_le_big_complete()
3177 iso_conn->handle = sys_le16_to_cpu(handle); in hci_le_big_complete()
3178 store_bis_broadcaster_info(evt, &iso_conn->iso.info); in hci_le_big_complete()
3186 if (listener->started != NULL) { in hci_le_big_complete()
3187 listener->started(big); in hci_le_big_complete()
3195 struct bt_hci_evt_le_big_terminate *evt = (void *)buf->data; in hci_le_big_terminate()
3198 if (evt->big_handle >= ARRAY_SIZE(bigs)) { in hci_le_big_terminate()
3203 big = lookup_big_by_handle(evt->big_handle); in hci_le_big_terminate()
3205 LOG_DBG("BIG[%u] %p terminated", big->handle, big); in hci_le_big_terminate()
3207 big_disconnect(big, evt->reason); in hci_le_big_terminate()
3219 return -ENOBUFS; in hci_le_terminate_big()
3223 req->big_handle = big->handle; in hci_le_terminate_big()
3224 req->reason = BT_HCI_ERR_REMOTE_USER_TERM_CONN; in hci_le_terminate_big()
3239 return -ENOBUFS; in hci_le_big_sync_term()
3243 req->big_handle = big->handle; in hci_le_big_sync_term()
3249 evt = (struct bt_hci_rp_le_big_terminate_sync *)rsp->data; in hci_le_big_sync_term()
3250 if (evt->status || (evt->big_handle != big->handle)) { in hci_le_big_sync_term()
3251 err = -EIO; in hci_le_big_sync_term()
3266 return -EINVAL; in bt_iso_big_terminate()
3269 if (!atomic_test_bit(big->flags, BT_BIG_INITIALIZED) || !big->num_bis) { in bt_iso_big_terminate()
3271 return -EINVAL; in bt_iso_big_terminate()
3274 bis = SYS_SLIST_PEEK_HEAD_CONTAINER(&big->bis_channels, bis, node); in bt_iso_big_terminate()
3278 bis->iso->iso.info.type == BT_ISO_CHAN_TYPE_BROADCASTER) { in bt_iso_big_terminate()
3285 SYS_SLIST_FOR_EACH_CONTAINER(&big->bis_channels, bis, node) { in bt_iso_big_terminate()
3290 bis->iso->iso.info.type == BT_ISO_CHAN_TYPE_SYNC_RECEIVER) { in bt_iso_big_terminate()
3298 err = -EINVAL; in bt_iso_big_terminate()
3312 struct bt_iso_sync_receiver_info *receiver_info = &info->sync_receiver; in store_bis_sync_receiver_info()
3314 info->max_subevent = evt->nse; in store_bis_sync_receiver_info()
3315 info->iso_interval = sys_le16_to_cpu(evt->iso_interval); in store_bis_sync_receiver_info()
3317 receiver_info->latency = sys_get_le24(evt->latency); in store_bis_sync_receiver_info()
3318 receiver_info->bn = evt->bn; in store_bis_sync_receiver_info()
3319 receiver_info->irc = evt->irc; in store_bis_sync_receiver_info()
3321 receiver_info->pto = info->iso_interval * evt->pto; in store_bis_sync_receiver_info()
3322 receiver_info->max_pdu = sys_le16_to_cpu(evt->max_pdu); in store_bis_sync_receiver_info()
3324 info->can_send = false; in store_bis_sync_receiver_info()
3325 info->can_recv = true; in store_bis_sync_receiver_info()
3330 struct bt_hci_evt_le_big_sync_established *evt = (void *)buf->data; in hci_le_big_sync_established()
3335 if (evt->big_handle >= ARRAY_SIZE(bigs)) { in hci_le_big_sync_established()
3339 big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED); in hci_le_big_sync_established()
3346 big = lookup_big_by_handle(evt->big_handle); in hci_le_big_sync_established()
3347 atomic_clear_bit(big->flags, BT_BIG_SYNCING); in hci_le_big_sync_established()
3349 LOG_DBG("BIG[%u] %p sync established, status 0x%02x %s", big->handle, big, evt->status, in hci_le_big_sync_established()
3350 bt_hci_err_to_str(evt->status)); in hci_le_big_sync_established()
3352 if (evt->status || evt->num_bis != big->num_bis) { in hci_le_big_sync_established()
3353 if (evt->status == BT_HCI_ERR_SUCCESS && evt->num_bis != big->num_bis) { in hci_le_big_sync_established()
3354 LOG_ERR("Invalid number of BIS synced, was %u expected %u", evt->num_bis, in hci_le_big_sync_established()
3355 big->num_bis); in hci_le_big_sync_established()
3357 big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED); in hci_le_big_sync_established()
3363 SYS_SLIST_FOR_EACH_CONTAINER(&big->bis_channels, bis, node) { in hci_le_big_sync_established()
3364 const uint16_t handle = evt->handle[i++]; in hci_le_big_sync_established()
3365 struct bt_conn *iso_conn = bis->iso; in hci_le_big_sync_established()
3367 iso_conn->handle = sys_le16_to_cpu(handle); in hci_le_big_sync_established()
3368 store_bis_sync_receiver_info(evt, &iso_conn->iso.info); in hci_le_big_sync_established()
3376 if (listener->started != NULL) { in hci_le_big_sync_established()
3377 listener->started(big); in hci_le_big_sync_established()
3385 struct bt_hci_evt_le_big_sync_lost *evt = (void *)buf->data; in hci_le_big_sync_lost()
3388 if (evt->big_handle >= ARRAY_SIZE(bigs)) { in hci_le_big_sync_lost()
3393 big = lookup_big_by_handle(evt->big_handle); in hci_le_big_sync_lost()
3395 LOG_DBG("BIG[%u] %p sync lost", big->handle, big); in hci_le_big_sync_lost()
3397 big_disconnect(big, evt->reason); in hci_le_big_sync_lost()
3410 buf = bt_hci_cmd_create(BT_HCI_OP_LE_BIG_CREATE_SYNC, sizeof(*req) + big->num_bis); in hci_le_big_create_sync()
3412 return -ENOBUFS; in hci_le_big_create_sync()
3415 req = net_buf_add(buf, sizeof(*req) + big->num_bis); in hci_le_big_create_sync()
3416 req->big_handle = big->handle; in hci_le_big_create_sync()
3417 req->sync_handle = sys_cpu_to_le16(sync->handle); in hci_le_big_create_sync()
3418 req->encryption = param->encryption; in hci_le_big_create_sync()
3419 if (req->encryption) { in hci_le_big_create_sync()
3420 memcpy(req->bcode, param->bcode, sizeof(req->bcode)); in hci_le_big_create_sync()
3422 memset(req->bcode, 0, sizeof(req->bcode)); in hci_le_big_create_sync()
3424 req->mse = param->mse; in hci_le_big_create_sync()
3425 req->sync_timeout = sys_cpu_to_le16(param->sync_timeout); in hci_le_big_create_sync()
3426 req->num_bis = big->num_bis; in hci_le_big_create_sync()
3429 if (param->bis_bitfield & BT_ISO_BIS_INDEX_BIT(i)) { in hci_le_big_create_sync()
3430 if (bit_idx == big->num_bis) { in hci_le_big_create_sync()
3432 return -EINVAL; in hci_le_big_create_sync()
3434 req->bis[bit_idx++] = i; in hci_le_big_create_sync()
3438 if (bit_idx != big->num_bis) { in hci_le_big_create_sync()
3440 big->num_bis); in hci_le_big_create_sync()
3441 return -EINVAL; in hci_le_big_create_sync()
3444 bt_hci_cmd_state_set_init(buf, &state, big->flags, BT_BIG_SYNCING, true); in hci_le_big_create_sync()
3459 return -EINVAL; in bt_iso_big_sync()
3464 return -EINVAL; in bt_iso_big_sync()
3469 return -EINVAL; in bt_iso_big_sync()
3472 if (!atomic_test_bit(sync->flags, BT_PER_ADV_SYNC_SYNCED)) { in bt_iso_big_sync()
3474 return -EINVAL; in bt_iso_big_sync()
3477 CHECKIF(param->mse > BT_ISO_SYNC_MSE_MAX) { in bt_iso_big_sync()
3478 LOG_DBG("Invalid MSE 0x%02x", param->mse); in bt_iso_big_sync()
3479 return -EINVAL; in bt_iso_big_sync()
3482 CHECKIF(param->sync_timeout < BT_ISO_SYNC_TIMEOUT_MIN || in bt_iso_big_sync()
3483 param->sync_timeout > BT_ISO_SYNC_TIMEOUT_MAX) { in bt_iso_big_sync()
3484 LOG_DBG("Invalid sync timeout 0x%04x", param->sync_timeout); in bt_iso_big_sync()
3485 return -EINVAL; in bt_iso_big_sync()
3488 CHECKIF(!BT_ISO_VALID_BIS_BITFIELD(param->bis_bitfield)) { in bt_iso_big_sync()
3489 LOG_DBG("Invalid BIS bitfield 0x%08x", param->bis_bitfield); in bt_iso_big_sync()
3490 return -EINVAL; in bt_iso_big_sync()
3493 CHECKIF(!param->bis_channels) { in bt_iso_big_sync()
3495 return -EINVAL; in bt_iso_big_sync()
3498 CHECKIF(!param->num_bis) { in bt_iso_big_sync()
3499 LOG_DBG("Invalid number of BIS %u", param->num_bis); in bt_iso_big_sync()
3500 return -EINVAL; in bt_iso_big_sync()
3503 for (uint8_t i = 0; i < param->num_bis; i++) { in bt_iso_big_sync()
3504 struct bt_iso_chan *param_bis = param->bis_channels[i]; in bt_iso_big_sync()
3508 return -EINVAL; in bt_iso_big_sync()
3511 if (param_bis->iso) { in bt_iso_big_sync()
3513 return -EALREADY; in bt_iso_big_sync()
3516 CHECKIF(param_bis->qos == NULL) { in bt_iso_big_sync()
3518 return -EINVAL; in bt_iso_big_sync()
3521 CHECKIF(param_bis->qos->rx == NULL) { in bt_iso_big_sync()
3522 LOG_DBG("bis_channels[%u]: qos->rx is NULL", i); in bt_iso_big_sync()
3523 return -EINVAL; in bt_iso_big_sync()
3530 return -ENOMEM; in bt_iso_big_sync()
3533 err = big_init_bis(big, param->bis_channels, param->num_bis, false); in bt_iso_big_sync()
3539 big->num_bis = param->num_bis; in bt_iso_big_sync()
3548 SYS_SLIST_FOR_EACH_CONTAINER(&big->bis_channels, bis, node) { in bt_iso_big_sync()
3571 SYS_SLIST_FOR_EACH_CONTAINER(&cig->cis_channels, cis, node) { in bt_iso_reset()
3572 if (cis->state != BT_ISO_STATE_DISCONNECTED) { in bt_iso_reset()
3574 bt_iso_cleanup_acl(cis->iso); in bt_iso_reset()
3575 if (cis->ops != NULL && cis->ops->disconnected != NULL) { in bt_iso_reset()
3576 cis->ops->disconnected(cis, BT_HCI_ERR_UNSPECIFIED); in bt_iso_reset()