Lines Matching full:inst
116 static int read_recv_state(struct bap_broadcast_assistant_instance *inst, uint8_t idx);
118 static int16_t lookup_index_by_handle(struct bap_broadcast_assistant_instance *inst, in lookup_index_by_handle() argument
121 for (size_t i = 0U; i < ARRAY_SIZE(inst->recv_state_handles); i++) { in lookup_index_by_handle()
122 if (inst->recv_state_handles[i] == handle) { in lookup_index_by_handle()
134 struct bap_broadcast_assistant_instance *inst; in inst_by_conn() local
141 inst = &broadcast_assistants[bt_conn_index(conn)]; in inst_by_conn()
143 if (inst->conn == conn) { in inst_by_conn()
144 return inst; in inst_by_conn()
153 struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn); in bap_broadcast_assistant_discover_complete() local
157 if (inst != NULL) { in bap_broadcast_assistant_discover_complete()
158 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bap_broadcast_assistant_discover_complete()
159 atomic_clear_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS); in bap_broadcast_assistant_discover_complete()
326 static void bap_long_read_reset(struct bap_broadcast_assistant_instance *inst) in bap_long_read_reset() argument
328 inst->long_read_handle = 0; in bap_long_read_reset()
330 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bap_long_read_reset()
339 struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn); in parse_and_send_recv_state() local
341 if (inst == NULL) { in parse_and_send_recv_state()
352 index = lookup_index_by_handle(inst, handle); in parse_and_send_recv_state()
359 inst->recv_states[index].src_id = recv_state->src_id; in parse_and_send_recv_state()
360 inst->recv_states[index].past_avail = past_available(conn, &recv_state->addr, in parse_and_send_recv_state()
375 struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn); in broadcast_assistant_bap_ntf_read_func() local
377 if (inst == NULL) { in broadcast_assistant_bap_ntf_read_func()
386 bap_long_read_reset(inst); in broadcast_assistant_bap_ntf_read_func()
398 bap_long_read_reset(inst); in broadcast_assistant_bap_ntf_read_func()
412 bap_long_read_reset(inst); in broadcast_assistant_bap_ntf_read_func()
423 struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn); in long_bap_read() local
425 if (inst == NULL) { in long_bap_read()
429 if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in long_bap_read()
443 err = k_work_reschedule(&inst->bap_read_work, in long_bap_read()
447 bap_long_read_reset(inst); in long_bap_read()
453 inst->read_params.func = broadcast_assistant_bap_ntf_read_func; in long_bap_read()
454 inst->read_params.handle_count = 1U; in long_bap_read()
455 inst->read_params.single.handle = handle; in long_bap_read()
456 inst->read_params.single.offset = att_buf.len; in long_bap_read()
458 err = bt_gatt_read(conn, &inst->read_params); in long_bap_read()
462 bap_long_read_reset(inst); in long_bap_read()
468 struct bap_broadcast_assistant_instance *inst = in delayed_bap_read_handler() local
471 long_bap_read(inst->conn, inst->long_read_handle); in delayed_bap_read_handler()
482 struct bap_broadcast_assistant_instance *inst; in notify_handler() local
489 inst = inst_by_conn(conn); in notify_handler()
491 if (inst == NULL) { in notify_handler()
495 if (atomic_test_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS)) { in notify_handler()
509 index = lookup_index_by_handle(inst, handle); in notify_handler()
521 (void)k_work_cancel_delayable(&inst->bap_read_work); in notify_handler()
529 inst->long_read_handle = handle; in notify_handler()
531 if (!atomic_test_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in notify_handler()
540 inst->recv_states[index].past_avail = false; in notify_handler()
541 bap_broadcast_assistant_recv_state_removed(conn, inst->recv_states[index].src_id); in notify_handler()
551 struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn); in read_recv_state_cb() local
553 if (inst == NULL) { in read_recv_state_cb()
558 uint8_t last_handle_index = inst->recv_state_cnt - 1; in read_recv_state_cb()
559 uint16_t last_handle = inst->recv_state_handles[last_handle_index]; in read_recv_state_cb()
573 index = lookup_index_by_handle(inst, handle); in read_recv_state_cb()
583 &inst->recv_states[index]; in read_recv_state_cb()
589 inst->recv_states[index].past_avail = in read_recv_state_cb()
599 if (atomic_test_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS)) { in read_recv_state_cb()
602 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in read_recv_state_cb()
606 if (atomic_test_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS)) { in read_recv_state_cb()
607 const uint8_t recv_state_cnt = inst->recv_state_cnt; in read_recv_state_cb()
611 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in read_recv_state_cb()
617 for (uint8_t i = 0U; i < inst->recv_state_cnt; i++) { in read_recv_state_cb()
618 if (handle != inst->recv_state_handles[i]) { in read_recv_state_cb()
622 if (i + 1 < ARRAY_SIZE(inst->recv_state_handles)) { in read_recv_state_cb()
623 cb_err = read_recv_state(inst, i + 1); in read_recv_state_cb()
627 if (atomic_test_bit(inst->flags, in read_recv_state_cb()
632 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in read_recv_state_cb()
645 static void discover_init(struct bap_broadcast_assistant_instance *inst) in discover_init() argument
647 k_work_init_delayable(&inst->bap_read_work, delayed_bap_read_handler); in discover_init()
649 atomic_set_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS); in discover_init()
663 struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn); in char_discover_func() local
665 if (inst == NULL) { in char_discover_func()
670 LOG_DBG("Found %u BASS receive states", inst->recv_state_cnt); in char_discover_func()
673 err = read_recv_state(inst, 0); in char_discover_func()
689 inst->cp_handle = attr->handle + 1; in char_discover_func()
691 if (inst->recv_state_cnt < in char_discover_func()
693 uint8_t idx = inst->recv_state_cnt++; in char_discover_func()
695 LOG_DBG("Receive State %u", inst->recv_state_cnt); in char_discover_func()
696 inst->recv_state_handles[idx] = in char_discover_func()
698 sub_params = &inst->recv_state_sub_params[idx]; in char_discover_func()
699 sub_params->disc_params = &inst->recv_state_disc_params[idx]; in char_discover_func()
704 sub_params->end_handle = inst->end_handle; in char_discover_func()
732 struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn); in service_discover_func() local
734 if (inst == NULL) { in service_discover_func()
753 inst->start_handle = attr->handle + 1; in service_discover_func()
754 inst->end_handle = prim_service->end_handle; in service_discover_func()
756 inst->disc_params.uuid = NULL; in service_discover_func()
757 inst->disc_params.start_handle = inst->start_handle; in service_discover_func()
758 inst->disc_params.end_handle = inst->end_handle; in service_discover_func()
759 inst->disc_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; in service_discover_func()
760 inst->disc_params.func = char_discover_func; in service_discover_func()
762 err = bt_gatt_discover(conn, &inst->disc_params); in service_discover_func()
777 struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn); in bap_broadcast_assistant_write_cp_cb() local
779 if (inst == NULL) { in bap_broadcast_assistant_write_cp_cb()
786 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bap_broadcast_assistant_write_cp_cb()
831 struct bap_broadcast_assistant_instance *inst; in bt_bap_broadcast_assistant_common_cp() local
839 inst = inst_by_conn(conn); in bt_bap_broadcast_assistant_common_cp()
841 if (inst == NULL) { in bt_bap_broadcast_assistant_common_cp()
845 if (inst->cp_handle == 0) { in bt_bap_broadcast_assistant_common_cp()
850 inst->write_params.offset = 0; in bt_bap_broadcast_assistant_common_cp()
851 inst->write_params.data = buf->data; in bt_bap_broadcast_assistant_common_cp()
852 inst->write_params.length = buf->len; in bt_bap_broadcast_assistant_common_cp()
853 inst->write_params.handle = inst->cp_handle; in bt_bap_broadcast_assistant_common_cp()
854 inst->write_params.func = bap_broadcast_assistant_write_cp_cb; in bt_bap_broadcast_assistant_common_cp()
856 err = bt_gatt_write(conn, &inst->write_params); in bt_bap_broadcast_assistant_common_cp()
858 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bt_bap_broadcast_assistant_common_cp()
925 static bool broadcast_src_is_duplicate(struct bap_broadcast_assistant_instance *inst, in broadcast_src_is_duplicate() argument
928 for (size_t i = 0; i < ARRAY_SIZE(inst->recv_states); i++) { in broadcast_src_is_duplicate()
930 &inst->recv_states[i]; in broadcast_src_is_duplicate()
945 static int broadcast_assistant_reset(struct bap_broadcast_assistant_instance *inst) in broadcast_assistant_reset() argument
947 inst->scanning = false; in broadcast_assistant_reset()
948 inst->pa_sync = 0U; in broadcast_assistant_reset()
949 inst->recv_state_cnt = 0U; in broadcast_assistant_reset()
950 inst->start_handle = 0U; in broadcast_assistant_reset()
951 inst->end_handle = 0U; in broadcast_assistant_reset()
952 inst->cp_handle = 0U; in broadcast_assistant_reset()
953 inst->long_read_handle = 0; in broadcast_assistant_reset()
954 (void)k_work_cancel_delayable(&inst->bap_read_work); in broadcast_assistant_reset()
957 memset(&inst->recv_states[i], 0, sizeof(inst->recv_states[i])); in broadcast_assistant_reset()
958 inst->recv_states[i].broadcast_id = BT_BAP_INVALID_BROADCAST_ID; in broadcast_assistant_reset()
959 inst->recv_states[i].adv_sid = BT_HCI_LE_EXT_ADV_SID_INVALID; in broadcast_assistant_reset()
960 inst->recv_states[i].past_avail = false; in broadcast_assistant_reset()
961 inst->recv_state_handles[i] = 0U; in broadcast_assistant_reset()
964 if (inst->conn != NULL) { in broadcast_assistant_reset()
965 struct bt_conn *conn = inst->conn; in broadcast_assistant_reset()
975 for (size_t i = 0U; i < ARRAY_SIZE(inst->recv_state_sub_params); i++) { in broadcast_assistant_reset()
979 err = bt_gatt_unsubscribe(conn, &inst->recv_state_sub_params[i]); in broadcast_assistant_reset()
989 inst->conn = NULL; in broadcast_assistant_reset()
993 memset(&inst->disc_params, 0, sizeof(inst->disc_params)); in broadcast_assistant_reset()
994 memset(&inst->recv_state_disc_params, 0, sizeof(inst->recv_state_disc_params)); in broadcast_assistant_reset()
995 memset(&inst->read_params, 0, sizeof(inst->read_params)); in broadcast_assistant_reset()
996 memset(&inst->write_params, 0, sizeof(inst->write_params)); in broadcast_assistant_reset()
1003 struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn); in disconnected_cb() local
1005 if (inst) { in disconnected_cb()
1006 (void)broadcast_assistant_reset(inst); in disconnected_cb()
1017 struct bap_broadcast_assistant_instance *inst; in bt_bap_broadcast_assistant_discover() local
1025 inst = &broadcast_assistants[bt_conn_index(conn)]; in bt_bap_broadcast_assistant_discover()
1028 if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in bt_bap_broadcast_assistant_discover()
1033 err = broadcast_assistant_reset(inst); in bt_bap_broadcast_assistant_discover()
1035 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bt_bap_broadcast_assistant_discover()
1042 inst->conn = bt_conn_ref(conn); in bt_bap_broadcast_assistant_discover()
1045 discover_init(inst); in bt_bap_broadcast_assistant_discover()
1048 inst->disc_params.func = service_discover_func; in bt_bap_broadcast_assistant_discover()
1049 inst->disc_params.uuid = &uuid.uuid; in bt_bap_broadcast_assistant_discover()
1050 inst->disc_params.type = BT_GATT_DISCOVER_PRIMARY; in bt_bap_broadcast_assistant_discover()
1051 inst->disc_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; in bt_bap_broadcast_assistant_discover()
1052 inst->disc_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; in bt_bap_broadcast_assistant_discover()
1053 err = bt_gatt_discover(conn, &inst->disc_params); in bt_bap_broadcast_assistant_discover()
1055 atomic_clear_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS); in bt_bap_broadcast_assistant_discover()
1056 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bt_bap_broadcast_assistant_discover()
1109 struct bap_broadcast_assistant_instance *inst; in bt_bap_broadcast_assistant_scan_start() local
1117 inst = inst_by_conn(conn); in bt_bap_broadcast_assistant_scan_start()
1118 if (inst == NULL) { in bt_bap_broadcast_assistant_scan_start()
1122 if (inst->cp_handle == 0) { in bt_bap_broadcast_assistant_scan_start()
1126 } else if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in bt_bap_broadcast_assistant_scan_start()
1138 if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_SCANNING)) { in bt_bap_broadcast_assistant_scan_start()
1141 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bt_bap_broadcast_assistant_scan_start()
1155 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bt_bap_broadcast_assistant_scan_start()
1156 atomic_clear_bit(inst->flags, BAP_BA_FLAG_SCANNING); in bt_bap_broadcast_assistant_scan_start()
1175 atomic_clear_bit(inst->flags, BAP_BA_FLAG_SCANNING); in bt_bap_broadcast_assistant_scan_start()
1186 atomic_clear_bit(inst->flags, BAP_BA_FLAG_SCANNING); in bt_bap_broadcast_assistant_scan_start()
1196 struct bap_broadcast_assistant_instance *inst; in bt_bap_broadcast_assistant_scan_stop() local
1204 inst = inst_by_conn(conn); in bt_bap_broadcast_assistant_scan_stop()
1205 if (inst == NULL) { in bt_bap_broadcast_assistant_scan_stop()
1209 if (inst->cp_handle == 0) { in bt_bap_broadcast_assistant_scan_stop()
1213 } else if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in bt_bap_broadcast_assistant_scan_stop()
1219 if (atomic_test_bit(inst->flags, BAP_BA_FLAG_SCANNING)) { in bt_bap_broadcast_assistant_scan_stop()
1224 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bt_bap_broadcast_assistant_scan_stop()
1229 atomic_clear_bit(inst->flags, BAP_BA_FLAG_SCANNING); in bt_bap_broadcast_assistant_scan_stop()
1351 struct bap_broadcast_assistant_instance *inst; in bt_bap_broadcast_assistant_add_src() local
1359 inst = inst_by_conn(conn); in bt_bap_broadcast_assistant_add_src()
1361 if (inst == NULL) { in bt_bap_broadcast_assistant_add_src()
1366 if (broadcast_src_is_duplicate(inst, param->broadcast_id, param->adv_sid, in bt_bap_broadcast_assistant_add_src()
1377 if (inst->cp_handle == 0) { in bt_bap_broadcast_assistant_add_src()
1381 } else if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in bt_bap_broadcast_assistant_add_src()
1419 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bt_bap_broadcast_assistant_add_src()
1486 struct bap_broadcast_assistant_instance *inst; in bt_bap_broadcast_assistant_mod_src() local
1498 inst = inst_by_conn(conn); in bt_bap_broadcast_assistant_mod_src()
1499 if (inst == NULL) { in bt_bap_broadcast_assistant_mod_src()
1503 if (inst->cp_handle == 0) { in bt_bap_broadcast_assistant_mod_src()
1507 } else if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in bt_bap_broadcast_assistant_mod_src()
1525 for (size_t i = 0; i < ARRAY_SIZE(inst->recv_states); i++) { in bt_bap_broadcast_assistant_mod_src()
1526 if (inst->recv_states[i].src_id == param->src_id) { in bt_bap_broadcast_assistant_mod_src()
1528 past_avail = inst->recv_states[i].past_avail; in bt_bap_broadcast_assistant_mod_src()
1562 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bt_bap_broadcast_assistant_mod_src()
1592 struct bap_broadcast_assistant_instance *inst; in bt_bap_broadcast_assistant_set_broadcast_code() local
1600 inst = inst_by_conn(conn); in bt_bap_broadcast_assistant_set_broadcast_code()
1601 if (inst == NULL) { in bt_bap_broadcast_assistant_set_broadcast_code()
1605 if (inst->cp_handle == 0) { in bt_bap_broadcast_assistant_set_broadcast_code()
1609 } else if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in bt_bap_broadcast_assistant_set_broadcast_code()
1632 struct bap_broadcast_assistant_instance *inst; in bt_bap_broadcast_assistant_rem_src() local
1640 inst = inst_by_conn(conn); in bt_bap_broadcast_assistant_rem_src()
1641 if (inst == NULL) { in bt_bap_broadcast_assistant_rem_src()
1645 if (inst->cp_handle == 0) { in bt_bap_broadcast_assistant_rem_src()
1649 } else if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in bt_bap_broadcast_assistant_rem_src()
1665 static int read_recv_state(struct bap_broadcast_assistant_instance *inst, uint8_t idx) in read_recv_state() argument
1669 inst->read_params.func = read_recv_state_cb; in read_recv_state()
1670 inst->read_params.handle_count = 1; in read_recv_state()
1671 inst->read_params.single.handle = inst->recv_state_handles[idx]; in read_recv_state()
1673 err = bt_gatt_read(inst->conn, &inst->read_params); in read_recv_state()
1675 (void)memset(&inst->read_params, 0, sizeof(inst->read_params)); in read_recv_state()
1685 struct bap_broadcast_assistant_instance *inst; in bt_bap_broadcast_assistant_read_recv_state() local
1693 inst = inst_by_conn(conn); in bt_bap_broadcast_assistant_read_recv_state()
1694 if (inst == NULL) { in bt_bap_broadcast_assistant_read_recv_state()
1698 CHECKIF(idx >= ARRAY_SIZE(inst->recv_state_handles)) { in bt_bap_broadcast_assistant_read_recv_state()
1704 if (inst->recv_state_handles[idx] == 0) { in bt_bap_broadcast_assistant_read_recv_state()
1708 } else if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { in bt_bap_broadcast_assistant_read_recv_state()
1714 err = read_recv_state(inst, idx); in bt_bap_broadcast_assistant_read_recv_state()
1716 (void)memset(&inst->read_params, 0, in bt_bap_broadcast_assistant_read_recv_state()
1717 sizeof(inst->read_params)); in bt_bap_broadcast_assistant_read_recv_state()
1718 atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY); in bt_bap_broadcast_assistant_read_recv_state()