|
2 | 2 |
|
3 | 3 | /*
|
4 | 4 | * Copyright (c) 2019 Bose Corporation
|
5 |
| - * Copyright (c) 2022-2023 Nordic Semiconductor ASA |
| 5 | + * Copyright (c) 2022-2025 Nordic Semiconductor ASA |
6 | 6 | * Copyright (c) 2024 Demant A/S
|
7 | 7 | *
|
8 | 8 | * SPDX-License-Identifier: Apache-2.0
|
@@ -565,20 +565,15 @@ static uint8_t read_recv_state_cb(struct bt_conn *conn, uint8_t err,
|
565 | 565 | const void *data, uint16_t length)
|
566 | 566 | {
|
567 | 567 | struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn);
|
| 568 | + bool active_recv_state = data != NULL && length != 0; |
| 569 | + struct bt_bap_scan_delegator_recv_state recv_state; |
| 570 | + uint16_t handle = params->single.handle; |
| 571 | + int cb_err = err; |
568 | 572 |
|
569 | 573 | if (inst == NULL) {
|
570 | 574 | return BT_GATT_ITER_STOP;
|
571 | 575 | }
|
572 | 576 |
|
573 |
| - uint16_t handle = params->single.handle; |
574 |
| - uint8_t last_handle_index = inst->recv_state_cnt - 1; |
575 |
| - uint16_t last_handle = inst->recv_state_handles[last_handle_index]; |
576 |
| - struct bt_bap_scan_delegator_recv_state recv_state; |
577 |
| - int cb_err = err; |
578 |
| - bool active_recv_state = data != NULL && length != 0; |
579 |
| - |
580 |
| - /* TODO: Split discovery and receive state characteristic read */ |
581 |
| - |
582 | 577 | (void)memset(params, 0, sizeof(*params));
|
583 | 578 |
|
584 | 579 | LOG_DBG("%s receive state", active_recv_state ? "Active " : "Inactive");
|
@@ -611,48 +606,12 @@ static uint8_t read_recv_state_cb(struct bt_conn *conn, uint8_t err,
|
611 | 606 |
|
612 | 607 | if (cb_err != 0) {
|
613 | 608 | LOG_DBG("err %d", cb_err);
|
614 |
| - |
615 |
| - if (atomic_test_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS)) { |
616 |
| - bap_broadcast_assistant_discover_complete(conn, cb_err, 0); |
617 |
| - } else { |
618 |
| - atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); |
619 |
| - bap_broadcast_assistant_recv_state_changed(conn, cb_err, NULL); |
620 |
| - } |
621 |
| - } else if (handle == last_handle) { |
622 |
| - if (atomic_test_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS)) { |
623 |
| - const uint8_t recv_state_cnt = inst->recv_state_cnt; |
624 |
| - |
625 |
| - bap_broadcast_assistant_discover_complete(conn, cb_err, recv_state_cnt); |
626 |
| - } else { |
627 |
| - atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); |
628 |
| - bap_broadcast_assistant_recv_state_changed(conn, cb_err, |
629 |
| - active_recv_state ? |
630 |
| - &recv_state : NULL); |
631 |
| - } |
| 609 | + atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); |
| 610 | + bap_broadcast_assistant_recv_state_changed(conn, cb_err, NULL); |
632 | 611 | } else {
|
633 |
| - for (uint8_t i = 0U; i < inst->recv_state_cnt; i++) { |
634 |
| - if (handle != inst->recv_state_handles[i]) { |
635 |
| - continue; |
636 |
| - } |
637 |
| - |
638 |
| - if (i + 1 < ARRAY_SIZE(inst->recv_state_handles)) { |
639 |
| - cb_err = read_recv_state(inst, i + 1); |
640 |
| - if (cb_err != 0) { |
641 |
| - LOG_DBG("Failed to read receive state: %d", cb_err); |
642 |
| - |
643 |
| - if (atomic_test_bit(inst->flags, |
644 |
| - BAP_BA_FLAG_DISCOVER_IN_PROGRESS)) { |
645 |
| - bap_broadcast_assistant_discover_complete( |
646 |
| - conn, cb_err, 0); |
647 |
| - } else { |
648 |
| - atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); |
649 |
| - bap_broadcast_assistant_recv_state_changed( |
650 |
| - conn, cb_err, NULL); |
651 |
| - } |
652 |
| - } |
653 |
| - } |
654 |
| - break; |
655 |
| - } |
| 612 | + atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); |
| 613 | + bap_broadcast_assistant_recv_state_changed(conn, cb_err, |
| 614 | + active_recv_state ? &recv_state : NULL); |
656 | 615 | }
|
657 | 616 |
|
658 | 617 | return BT_GATT_ITER_STOP;
|
@@ -686,10 +645,7 @@ static uint8_t char_discover_func(struct bt_conn *conn,
|
686 | 645 | LOG_DBG("Found %u BASS receive states", inst->recv_state_cnt);
|
687 | 646 | (void)memset(params, 0, sizeof(*params));
|
688 | 647 |
|
689 |
| - err = read_recv_state(inst, 0); |
690 |
| - if (err != 0) { |
691 |
| - bap_broadcast_assistant_discover_complete(conn, err, 0); |
692 |
| - } |
| 648 | + bap_broadcast_assistant_discover_complete(conn, 0, inst->recv_state_cnt); |
693 | 649 |
|
694 | 650 | return BT_GATT_ITER_STOP;
|
695 | 651 | }
|
|
0 commit comments