Lines Matching +full:merge +full:- +full:status
4 * Copyright (c) 2021-2024 Nordic Semiconductor ASA
6 * SPDX-License-Identifier: Apache-2.0
72 if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID) && in find_recv_state_by_sink_cb()
73 sink->bass_src_id == recv_state->src_id) { in find_recv_state_by_sink_cb()
94 if (bt_addr_le_eq(&recv_state->addr, &sync_info.addr) && in find_recv_state_by_pa_sync_cb()
95 recv_state->adv_sid == sync_info.sid) { in find_recv_state_by_pa_sync_cb()
115 mod_src_param.num_subgroups = sink->subgroup_count; in update_recv_state_big_synced()
116 for (uint8_t i = 0U; i < sink->subgroup_count; i++) { in update_recv_state_big_synced()
118 const struct bt_bap_broadcast_sink_subgroup *sink_subgroup = &sink->subgroups[i]; in update_recv_state_big_synced()
121 subgroup_param->bis_sync = sink_subgroup->bis_indexes & sink->indexes_bitfield; in update_recv_state_big_synced()
124 if (recv_state->encrypt_state == BT_BAP_BIG_ENC_STATE_BCODE_REQ) { in update_recv_state_big_synced()
127 mod_src_param.encrypt_state = recv_state->encrypt_state; in update_recv_state_big_synced()
130 /* Since the mod_src_param struct is 0-initialized the metadata won't in update_recv_state_big_synced()
135 mod_src_param.src_id = recv_state->src_id; in update_recv_state_big_synced()
136 mod_src_param.broadcast_id = recv_state->broadcast_id; in update_recv_state_big_synced()
159 if ((recv_state->encrypt_state == BT_BAP_BIG_ENC_STATE_BCODE_REQ || in update_recv_state_big_cleared()
160 recv_state->encrypt_state == BT_BAP_BIG_ENC_STATE_DEC) && in update_recv_state_big_cleared()
165 mod_src_param.encrypt_state = recv_state->encrypt_state; in update_recv_state_big_cleared()
169 for (uint8_t i = 0U; i < recv_state->num_subgroups; i++) { in update_recv_state_big_cleared()
177 mod_src_param.num_subgroups = recv_state->num_subgroups; in update_recv_state_big_cleared()
178 mod_src_param.src_id = recv_state->src_id; in update_recv_state_big_cleared()
179 mod_src_param.broadcast_id = recv_state->broadcast_id; in update_recv_state_big_cleared()
191 sink->big = NULL; in broadcast_sink_clear_big()
214 old_state = ep->status.state; in broadcast_sink_set_ep_state()
216 LOG_DBG("ep %p id 0x%02x %s -> %s", ep, ep->status.id, bt_bap_ep_state_str(old_state), in broadcast_sink_set_ep_state()
244 ep->status.state = state; in broadcast_sink_set_ep_state()
247 struct bt_bap_stream *stream = ep->stream; in broadcast_sink_set_ep_state()
250 bt_bap_iso_unbind_ep(ep->iso, ep); in broadcast_sink_set_ep_state()
251 stream->ep = NULL; in broadcast_sink_set_ep_state()
252 stream->codec_cfg = NULL; in broadcast_sink_set_ep_state()
253 ep->stream = NULL; in broadcast_sink_set_ep_state()
265 struct bt_bap_ep *ep = iso->rx.ep; in broadcast_sink_iso_recv()
273 stream = ep->stream; in broadcast_sink_iso_recv()
279 ops = stream->ops; in broadcast_sink_iso_recv()
283 LOG_DBG("stream %p ep %p len %zu", stream, stream->ep, buf_len); in broadcast_sink_iso_recv()
286 if (buf_len > stream->qos->sdu) { in broadcast_sink_iso_recv()
288 stream, stream->qos->sdu); in broadcast_sink_iso_recv()
291 if (ops != NULL && ops->recv != NULL) { in broadcast_sink_iso_recv()
292 ops->recv(stream, info, buf); in broadcast_sink_iso_recv()
309 if (sys_slist_is_empty(&sink->streams)) { in broadcast_sink_is_in_state()
315 SYS_SLIST_FOR_EACH_CONTAINER(&sink->streams, stream, _node) { in broadcast_sink_is_in_state()
316 if (stream->ep != NULL && stream->ep->status.state != state) { in broadcast_sink_is_in_state()
330 struct bt_bap_ep *ep = iso->rx.ep; in broadcast_sink_iso_connected()
337 stream = ep->stream; in broadcast_sink_iso_connected()
345 ops = stream->ops; in broadcast_sink_iso_connected()
346 if (ops != NULL && ops->connected != NULL) { in broadcast_sink_iso_connected()
347 ops->connected(stream); in broadcast_sink_iso_connected()
358 if (ops != NULL && ops->started != NULL) { in broadcast_sink_iso_connected()
359 ops->started(stream); in broadcast_sink_iso_connected()
375 struct bt_bap_ep *ep = iso->rx.ep; in broadcast_sink_iso_disconnected()
383 stream = ep->stream; in broadcast_sink_iso_disconnected()
391 ops = stream->ops; in broadcast_sink_iso_disconnected()
392 if (ops != NULL && ops->disconnected != NULL) { in broadcast_sink_iso_disconnected()
393 ops->disconnected(stream, reason); in broadcast_sink_iso_disconnected()
402 if (!sys_slist_find_and_remove(&sink->streams, &stream->_node)) { in broadcast_sink_iso_disconnected()
407 if (ops != NULL && ops->stopped != NULL) { in broadcast_sink_iso_disconnected()
408 ops->stopped(stream, reason); in broadcast_sink_iso_disconnected()
464 err = bt_le_per_adv_sync_get_info(sink->pa_sync, &sync_info); in broadcast_sink_add_src()
469 add_src_param.broadcast_id = sink->broadcast_id; in broadcast_sink_add_src()
479 sink->bass_src_id = (uint8_t)err; in broadcast_sink_add_src()
480 atomic_set_bit(sink->flags, in broadcast_sink_add_src()
497 subgroup_param = &mod_src_param->subgroups[mod_src_param->num_subgroups++]; in base_subgroup_meta_cb()
498 subgroup_param->metadata_len = (uint8_t)ret; in base_subgroup_meta_cb()
499 memcpy(subgroup_param->metadata, meta, subgroup_param->metadata_len); in base_subgroup_meta_cb()
539 mod_src_param.src_id = recv_state->src_id; in update_recv_state_base()
540 mod_src_param.encrypt_state = recv_state->encrypt_state; in update_recv_state_base()
541 mod_src_param.broadcast_id = recv_state->broadcast_id; in update_recv_state_base()
542 mod_src_param.num_subgroups = sink->subgroup_count; in update_recv_state_base()
543 for (uint8_t i = 0U; i < sink->subgroup_count; i++) { in update_recv_state_base()
547 subgroup_param->bis_sync = recv_state->subgroups[i].bis_sync; in update_recv_state_base()
560 if (cap->codec_cap->id == data->id) { in codec_lookup_id()
561 data->codec_cap = cap->codec_cap; in codec_lookup_id()
583 err = bt_audio_codec_cfg_set_val(codec_cfg, data->type, data->data, data->data_len); in merge_bis_and_subgroup_data_cb()
585 LOG_DBG("Failed to set type %u with len %u in codec_cfg: %d", data->type, in merge_bis_and_subgroup_data_cb()
586 data->data_len, err); in merge_bis_and_subgroup_data_cb()
600 if (data->bis_count == ARRAY_SIZE(data->bis)) { in base_subgroup_bis_index_cb()
602 LOG_DBG("Could only store %u BIS", data->bis_count); in base_subgroup_bis_index_cb()
606 sink_bis = &data->bis[data->bis_count]; in base_subgroup_bis_index_cb()
607 sink_subgroup = &data->subgroups[data->subgroup_count]; in base_subgroup_bis_index_cb()
609 sink_bis->index = bis->index; in base_subgroup_bis_index_cb()
610 sink_subgroup->bis_indexes |= BT_ISO_BIS_INDEX_BIT(bis->index); in base_subgroup_bis_index_cb()
614 memcpy(&sink_bis->codec_cfg, data->subgroup_codec_cfg, sizeof(sink_bis->codec_cfg)); in base_subgroup_bis_index_cb()
616 if (bis->data_len > 0) { in base_subgroup_bis_index_cb()
617 /* Merge subgroup codec configuration with the BIS configuration in base_subgroup_bis_index_cb()
621 if (sink_bis->codec_cfg.id == BT_HCI_CODING_FORMAT_LC3) { in base_subgroup_bis_index_cb()
624 memcpy(&sink_bis->codec_cfg, data->subgroup_codec_cfg, in base_subgroup_bis_index_cb()
625 sizeof(sink_bis->codec_cfg)); in base_subgroup_bis_index_cb()
627 err = bt_audio_data_parse(bis->data, bis->data_len, in base_subgroup_bis_index_cb()
629 &sink_bis->codec_cfg); in base_subgroup_bis_index_cb()
631 LOG_DBG("Could not merge BIS and subgroup config in codec_cfg: %d", in base_subgroup_bis_index_cb()
637 /* If it is not LC3, then we don't know how to merge the subgroup and BIS in base_subgroup_bis_index_cb()
640 if (sink_bis->codec_cfg.data_len + bis->data_len > in base_subgroup_bis_index_cb()
641 sizeof(sink_bis->codec_cfg.data)) { in base_subgroup_bis_index_cb()
644 sink_bis->codec_cfg.data_len + bis->data_len, in base_subgroup_bis_index_cb()
645 sizeof(sink_bis->codec_cfg.data)); in base_subgroup_bis_index_cb()
650 memcpy(&sink_bis->codec_cfg.data[sink_bis->codec_cfg.data_len], bis->data, in base_subgroup_bis_index_cb()
651 bis->data_len); in base_subgroup_bis_index_cb()
652 sink_bis->codec_cfg.data_len += bis->data_len; in base_subgroup_bis_index_cb()
657 data->bis_count++; in base_subgroup_bis_index_cb()
670 if (data->subgroup_count == ARRAY_SIZE(data->subgroups)) { in base_subgroup_cb()
672 LOG_DBG("Could only store %u subgroups", data->subgroup_count); in base_subgroup_cb()
676 sink_subgroup = &data->subgroups[data->subgroup_count]; in base_subgroup_cb()
691 codec_cfg.path_id = lookup_data.codec_cap->path_id; in base_subgroup_cb()
692 codec_cfg.ctlr_transcode = lookup_data.codec_cap->ctlr_transcode; in base_subgroup_cb()
694 data->subgroup_codec_cfg = &codec_cfg; in base_subgroup_cb()
703 data->valid_indexes_bitfield |= sink_subgroup->bis_indexes; in base_subgroup_cb()
704 data->subgroup_count++; in base_subgroup_cb()
734 if (sink->big == NULL) { in store_base_info()
735 sink->qos_cfg.pd = pres_delay; in store_base_info()
736 memcpy(sink->bis, data.bis, sizeof(sink->bis)); in store_base_info()
737 memcpy(sink->subgroups, data.subgroups, sizeof(sink->subgroups)); in store_base_info()
738 sink->subgroup_count = data.subgroup_count; in store_base_info()
739 sink->valid_indexes_bitfield = data.valid_indexes_bitfield; in store_base_info()
787 if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_BIGINFO_RECEIVED)) { in pa_decode_base()
793 } else if (ret != sink->biginfo_num_bis) { in pa_decode_base()
796 ret, sink->biginfo_num_bis); in pa_decode_base()
802 if (sink->big == NULL) { in pa_decode_base()
810 /* If it returns -ECANCELED it means that we stopped parsing ourselves due in pa_decode_base()
814 if (ret != -ECANCELED) { in pa_decode_base()
820 if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID)) { in pa_decode_base()
833 if (listener->base_recv != NULL) { in pa_decode_base()
834 listener->base_recv(sink, base, (size_t)base_size); in pa_decode_base()
866 sink->pa_sync = NULL; in pa_term_cb()
876 __ASSERT(sink->big == NULL, "Encryption state shall not be updated while synced"); in update_recv_state_encryption()
886 if (atomic_test_bit(sink->flags, in update_recv_state_encryption()
893 if (mod_src_param.encrypt_state == recv_state->encrypt_state) { in update_recv_state_encryption()
900 mod_src_param.src_id = recv_state->src_id; in update_recv_state_encryption()
901 mod_src_param.broadcast_id = recv_state->broadcast_id; in update_recv_state_encryption()
902 mod_src_param.num_subgroups = recv_state->num_subgroups; in update_recv_state_encryption()
904 recv_state->subgroups, in update_recv_state_encryption()
905 sizeof(recv_state->num_subgroups)); in update_recv_state_encryption()
925 if (sink->big != NULL) { in biginfo_recv()
926 /* Already synced - ignore */ in biginfo_recv()
930 atomic_set_bit(sink->flags, in biginfo_recv()
932 sink->iso_interval = biginfo->iso_interval; in biginfo_recv()
933 sink->biginfo_num_bis = biginfo->num_bis; in biginfo_recv()
934 if (biginfo->encryption != atomic_test_bit(sink->flags, in biginfo_recv()
936 atomic_set_bit_to(sink->flags, in biginfo_recv()
938 biginfo->encryption); in biginfo_recv()
940 if (atomic_test_bit(sink->flags, in biginfo_recv()
946 sink->qos_cfg.framing = biginfo->framing; in biginfo_recv()
947 sink->qos_cfg.phy = biginfo->phy; in biginfo_recv()
948 sink->qos_cfg.sdu = biginfo->max_sdu; in biginfo_recv()
949 sink->qos_cfg.interval = biginfo->sdu_interval; in biginfo_recv()
952 if (listener->syncable != NULL) { in biginfo_recv()
953 listener->syncable(sink, biginfo); in biginfo_recv()
985 if (listener->started != NULL) { in big_started_cb()
986 listener->started(sink); in big_started_cb()
1004 if (listener->stopped != NULL) { in big_stopped_cb()
1005 listener->stopped(sink, reason); in big_stopped_cb()
1017 return -EINVAL; in bt_bap_broadcast_sink_register_cb()
1020 if (sys_slist_find(&sink_cbs, &cb->_node, NULL)) { in bt_bap_broadcast_sink_register_cb()
1023 return -EEXIST; in bt_bap_broadcast_sink_register_cb()
1040 sys_slist_append(&sink_cbs, &cb->_node); in bt_bap_broadcast_sink_register_cb()
1061 ep->dir = BT_AUDIO_DIR_SINK; in broadcast_sink_ep_init()
1062 ep->iso = NULL; in broadcast_sink_ep_init()
1070 /* If ep->stream is NULL the endpoint is unallocated */ in broadcast_sink_new_ep()
1071 if (ep->stream == NULL) { in broadcast_sink_new_ep()
1087 if (stream->group != NULL) { in bt_bap_broadcast_sink_setup_stream()
1088 LOG_DBG("Stream %p already in group %p", stream, stream->group); in bt_bap_broadcast_sink_setup_stream()
1089 return -EALREADY; in bt_bap_broadcast_sink_setup_stream()
1092 ep = broadcast_sink_new_ep(sink->index); in bt_bap_broadcast_sink_setup_stream()
1095 return -ENOMEM; in bt_bap_broadcast_sink_setup_stream()
1101 return -ENOMEM; in bt_bap_broadcast_sink_setup_stream()
1107 bt_bap_qos_cfg_to_iso_qos(iso->chan.qos->rx, &sink->qos_cfg); in bt_bap_broadcast_sink_setup_stream()
1113 stream->qos = &sink->qos_cfg; in bt_bap_broadcast_sink_setup_stream()
1122 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&sink->streams, stream, next, _node) { in broadcast_sink_cleanup_streams()
1123 if (stream->ep != NULL) { in broadcast_sink_cleanup_streams()
1124 bt_bap_iso_unbind_ep(stream->ep->iso, stream->ep); in broadcast_sink_cleanup_streams()
1125 stream->ep->stream = NULL; in broadcast_sink_cleanup_streams()
1126 stream->ep = NULL; in broadcast_sink_cleanup_streams()
1129 stream->qos = NULL; in broadcast_sink_cleanup_streams()
1130 stream->codec_cfg = NULL; in broadcast_sink_cleanup_streams()
1131 stream->group = NULL; in broadcast_sink_cleanup_streams()
1133 sys_slist_remove(&sink->streams, NULL, &stream->_node); in broadcast_sink_cleanup_streams()
1136 sink->stream_count = 0; in broadcast_sink_cleanup_streams()
1137 sink->indexes_bitfield = 0U; in broadcast_sink_cleanup_streams()
1142 if (sink->stream_count > 0U) { in broadcast_sink_cleanup()
1152 for (size_t i = 0U; i < ARRAY_SIZE(sink->bis); i++) { in codec_cfg_from_base_by_index()
1153 struct bt_bap_broadcast_sink_bis *bis = &sink->bis[i]; in codec_cfg_from_base_by_index()
1155 if (bis->index == index) { in codec_cfg_from_base_by_index()
1156 return &bis->codec_cfg; in codec_cfg_from_base_by_index()
1157 } else if (bis->index == 0) { in codec_cfg_from_base_by_index()
1175 return -EINVAL; in bt_bap_broadcast_sink_create()
1181 return -EINVAL; in bt_bap_broadcast_sink_create()
1187 return -EINVAL; in bt_bap_broadcast_sink_create()
1194 return -ENOMEM; in bt_bap_broadcast_sink_create()
1197 sink->broadcast_id = broadcast_id; in bt_bap_broadcast_sink_create()
1198 sink->pa_sync = pa_sync; in bt_bap_broadcast_sink_create()
1206 if (recv_state->broadcast_id != broadcast_id) { in bt_bap_broadcast_sink_create()
1208 recv_state->broadcast_id, broadcast_id); in bt_bap_broadcast_sink_create()
1211 return -EINVAL; in bt_bap_broadcast_sink_create()
1214 sink->bass_src_id = recv_state->src_id; in bt_bap_broadcast_sink_create()
1215 atomic_set_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID); in bt_bap_broadcast_sink_create()
1217 atomic_set_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_INITIALIZED); in bt_bap_broadcast_sink_create()
1235 return -EINVAL; in bt_bap_broadcast_sink_sync()
1240 return -EINVAL; in bt_bap_broadcast_sink_sync()
1245 return -EINVAL; in bt_bap_broadcast_sink_sync()
1248 if (sink->pa_sync == NULL) { in bt_bap_broadcast_sink_sync()
1250 return -EINVAL; in bt_bap_broadcast_sink_sync()
1253 if (!atomic_test_bit(sink->flags, in bt_bap_broadcast_sink_sync()
1260 return -EAGAIN; in bt_bap_broadcast_sink_sync()
1263 if (atomic_test_bit(sink->flags, in bt_bap_broadcast_sink_sync()
1268 return -EINVAL; in bt_bap_broadcast_sink_sync()
1272 if ((indexes_bitfield & sink->valid_indexes_bitfield) != indexes_bitfield) { in bt_bap_broadcast_sink_sync()
1275 indexes_bitfield, sink->valid_indexes_bitfield); in bt_bap_broadcast_sink_sync()
1276 return -EINVAL; in bt_bap_broadcast_sink_sync()
1292 return -EINVAL; in bt_bap_broadcast_sink_sync()
1300 return -EINVAL; in bt_bap_broadcast_sink_sync()
1304 sink->stream_count = 0U; in bt_bap_broadcast_sink_sync()
1319 sink->bis[i].chan = bt_bap_stream_iso_chan_get(stream); in bt_bap_broadcast_sink_sync()
1320 sys_slist_append(&sink->streams, &stream->_node); in bt_bap_broadcast_sink_sync()
1321 sink->stream_count++; in bt_bap_broadcast_sink_sync()
1323 bis_channels[i] = sink->bis[i].chan; in bt_bap_broadcast_sink_sync()
1327 param.num_bis = sink->stream_count; in bt_bap_broadcast_sink_sync()
1330 param.sync_timeout = interval_to_sync_timeout(sink->iso_interval); in bt_bap_broadcast_sink_sync()
1331 param.encryption = atomic_test_bit(sink->flags, in bt_bap_broadcast_sink_sync()
1339 err = bt_iso_big_sync(sink->pa_sync, ¶m, &sink->big); in bt_bap_broadcast_sink_sync()
1345 sink->indexes_bitfield = indexes_bitfield; in bt_bap_broadcast_sink_sync()
1347 struct bt_bap_ep *ep = streams[i]->ep; in bt_bap_broadcast_sink_sync()
1349 ep->broadcast_sink = sink; in bt_bap_broadcast_sink_sync()
1362 return -EINVAL; in bt_bap_broadcast_sink_stop()
1365 if (sys_slist_is_empty(&sink->streams)) { in bt_bap_broadcast_sink_stop()
1367 return -EALREADY; in bt_bap_broadcast_sink_stop()
1372 return -EBADMSG; in bt_bap_broadcast_sink_stop()
1375 err = bt_iso_big_terminate(sink->big); in bt_bap_broadcast_sink_stop()
1389 return -EINVAL; in bt_bap_broadcast_sink_delete()
1394 return -EBADMSG; in bt_bap_broadcast_sink_delete()