Lines Matching refs:cli

45 		if (aics_insts[i].cli.conn == conn &&  in lookup_aics_by_handle()
46 atomic_test_bit(aics_insts[i].cli.flags, BT_AICS_CLIENT_FLAG_ACTIVE) && in lookup_aics_by_handle()
47 aics_insts[i].cli.start_handle <= handle && in lookup_aics_by_handle()
48 aics_insts[i].cli.end_handle >= handle) { in lookup_aics_by_handle()
81 if (handle == inst->cli.state_handle) { in aics_client_notify_handler()
87 inst->cli.change_counter = state->change_counter; in aics_client_notify_handler()
89 if (inst->cli.cb && inst->cli.cb->state) { in aics_client_notify_handler()
90 inst->cli.cb->state(inst, 0, state->gain, in aics_client_notify_handler()
95 } else if (handle == inst->cli.status_handle) { in aics_client_notify_handler()
99 if (inst->cli.cb && inst->cli.cb->status) { in aics_client_notify_handler()
100 inst->cli.cb->status(inst, 0, *status); in aics_client_notify_handler()
103 } else if (handle == inst->cli.desc_handle) { in aics_client_notify_handler()
116 if (inst->cli.cb && inst->cli.cb->description) { in aics_client_notify_handler()
117 inst->cli.cb->description(inst, 0, desc); in aics_client_notify_handler()
140 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in aics_client_read_state_cb()
144 if (inst->cli.cb && inst->cli.cb->state) { in aics_client_read_state_cb()
145 inst->cli.cb->state(inst, cb_err, 0, 0, 0); in aics_client_read_state_cb()
155 inst->cli.change_counter = state->change_counter; in aics_client_read_state_cb()
165 if (inst->cli.cb && inst->cli.cb->state) { in aics_client_read_state_cb()
166 inst->cli.cb->state(inst, cb_err, state->gain, in aics_client_read_state_cb()
189 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in aics_client_read_gain_settings_cb()
193 if (inst->cli.cb && inst->cli.cb->gain_setting) { in aics_client_read_gain_settings_cb()
194 inst->cli.cb->gain_setting(inst, cb_err, 0, 0, 0); in aics_client_read_gain_settings_cb()
212 if (inst->cli.cb && inst->cli.cb->gain_setting) { in aics_client_read_gain_settings_cb()
213 inst->cli.cb->gain_setting(inst, cb_err, gain_settings->units, in aics_client_read_gain_settings_cb()
237 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in aics_client_read_type_cb()
241 if (inst->cli.cb && inst->cli.cb->type) { in aics_client_read_type_cb()
242 inst->cli.cb->type(inst, cb_err, 0); in aics_client_read_type_cb()
259 if (inst->cli.cb && inst->cli.cb->type) { in aics_client_read_type_cb()
260 inst->cli.cb->type(inst, cb_err, *type); in aics_client_read_type_cb()
282 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in aics_client_read_status_cb()
286 if (inst->cli.cb && inst->cli.cb->status) { in aics_client_read_status_cb()
287 inst->cli.cb->status(inst, cb_err, 0); in aics_client_read_status_cb()
304 if (inst->cli.cb && inst->cli.cb->status) { in aics_client_read_status_cb()
305 inst->cli.cb->status(inst, cb_err, *status); in aics_client_read_status_cb()
313 if (!inst->cli.cb) { in aics_cp_notify_app()
317 switch (inst->cli.cp_val.cp.opcode) { in aics_cp_notify_app()
319 if (inst->cli.cb->set_gain) { in aics_cp_notify_app()
320 inst->cli.cb->set_gain(inst, err); in aics_cp_notify_app()
324 if (inst->cli.cb->unmute) { in aics_cp_notify_app()
325 inst->cli.cb->unmute(inst, err); in aics_cp_notify_app()
329 if (inst->cli.cb->mute) { in aics_cp_notify_app()
330 inst->cli.cb->mute(inst, err); in aics_cp_notify_app()
334 if (inst->cli.cb->set_manual_mode) { in aics_cp_notify_app()
335 inst->cli.cb->set_manual_mode(inst, err); in aics_cp_notify_app()
339 if (inst->cli.cb->set_auto_mode) { in aics_cp_notify_app()
340 inst->cli.cb->set_auto_mode(inst, err); in aics_cp_notify_app()
344 LOG_DBG("Unknown opcode 0x%02x", inst->cli.cp_val.cp.opcode); in aics_cp_notify_app()
372 inst->cli.change_counter = state->change_counter; in internal_read_state_cb()
375 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in internal_read_state_cb()
377 if (inst->cli.cp_val.cp.opcode == BT_AICS_OPCODE_SET_GAIN) { in internal_read_state_cb()
379 inst->cli.cp_val.gain_setting); in internal_read_state_cb()
381 write_err = aics_client_common_control(inst->cli.cp_val.cp.opcode, in internal_read_state_cb()
395 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in internal_read_state_cb()
425 atomic_test_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_CP_RETRIED)) { in aics_client_write_aics_cp_cb()
427 } else if (cb_err == BT_AICS_ERR_INVALID_COUNTER && inst->cli.state_handle) { in aics_client_write_aics_cp_cb()
428 inst->cli.read_params.func = internal_read_state_cb; in aics_client_write_aics_cp_cb()
429 inst->cli.read_params.handle_count = 1; in aics_client_write_aics_cp_cb()
430 inst->cli.read_params.single.handle = inst->cli.state_handle; in aics_client_write_aics_cp_cb()
431 inst->cli.read_params.single.offset = 0U; in aics_client_write_aics_cp_cb()
433 atomic_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_CP_RETRIED); in aics_client_write_aics_cp_cb()
435 cb_err = bt_gatt_read(conn, &inst->cli.read_params); in aics_client_write_aics_cp_cb()
444 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_CP_RETRIED); in aics_client_write_aics_cp_cb()
445 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in aics_client_write_aics_cp_cb()
464 CHECKIF(inst->cli.conn == NULL) { in aics_client_common_control()
469 if (!inst->cli.control_handle) { in aics_client_common_control()
472 } else if (atomic_test_and_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY)) { in aics_client_common_control()
476 inst->cli.cp_val.cp.opcode = opcode; in aics_client_common_control()
477 inst->cli.cp_val.cp.counter = inst->cli.change_counter; in aics_client_common_control()
479 inst->cli.write_params.offset = 0; in aics_client_common_control()
480 inst->cli.write_params.data = &inst->cli.cp_val.cp; in aics_client_common_control()
481 inst->cli.write_params.length = sizeof(inst->cli.cp_val.cp); in aics_client_common_control()
482 inst->cli.write_params.handle = inst->cli.control_handle; in aics_client_common_control()
483 inst->cli.write_params.func = aics_client_write_aics_cp_cb; in aics_client_common_control()
485 err = bt_gatt_write(inst->cli.conn, &inst->cli.write_params); in aics_client_common_control()
487 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in aics_client_common_control()
508 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in aics_client_read_desc_cb()
512 if (inst->cli.cb && inst->cli.cb->description) { in aics_client_read_desc_cb()
513 inst->cli.cb->description(inst, cb_err, NULL); in aics_client_read_desc_cb()
536 if (inst->cli.cb && inst->cli.cb->description) { in aics_client_read_desc_cb()
537 inst->cli.cb->description(inst, cb_err, desc); in aics_client_read_desc_cb()
545 return inst->cli.state_handle && in valid_inst_discovered()
546 inst->cli.gain_handle && in valid_inst_discovered()
547 inst->cli.type_handle && in valid_inst_discovered()
548 inst->cli.status_handle && in valid_inst_discovered()
549 inst->cli.control_handle && in valid_inst_discovered()
550 inst->cli.desc_handle; in valid_inst_discovered()
559 struct bt_aics *inst = CONTAINER_OF(client_inst, struct bt_aics, cli); in aics_discover_func()
566 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in aics_discover_func()
568 if (inst->cli.cb && inst->cli.cb->discover) { in aics_discover_func()
571 inst->cli.cb->discover(inst, err); in aics_discover_func()
584 if (inst->cli.start_handle == 0) { in aics_discover_func()
585 inst->cli.start_handle = chrc->value_handle; in aics_discover_func()
587 inst->cli.end_handle = chrc->value_handle; in aics_discover_func()
591 inst->cli.state_handle = chrc->value_handle; in aics_discover_func()
592 sub_params = &inst->cli.state_sub_params; in aics_discover_func()
595 inst->cli.gain_handle = chrc->value_handle; in aics_discover_func()
598 inst->cli.type_handle = chrc->value_handle; in aics_discover_func()
601 inst->cli.status_handle = chrc->value_handle; in aics_discover_func()
602 sub_params = &inst->cli.status_sub_params; in aics_discover_func()
605 inst->cli.control_handle = chrc->value_handle; in aics_discover_func()
608 inst->cli.desc_handle = chrc->value_handle; in aics_discover_func()
610 sub_params = &inst->cli.desc_sub_params; in aics_discover_func()
614 atomic_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_DESC_WRITABLE); in aics_discover_func()
635 if (inst->cli.cb && inst->cli.cb->discover) { in aics_discover_func()
636 inst->cli.cb->discover(inst, err); in aics_discover_func()
649 inst->cli.change_counter = 0; in aics_client_reset()
650 inst->cli.gain_mode = 0; in aics_client_reset()
651 inst->cli.start_handle = 0; in aics_client_reset()
652 inst->cli.end_handle = 0; in aics_client_reset()
653 inst->cli.state_handle = 0; in aics_client_reset()
654 inst->cli.gain_handle = 0; in aics_client_reset()
655 inst->cli.type_handle = 0; in aics_client_reset()
656 inst->cli.status_handle = 0; in aics_client_reset()
657 inst->cli.control_handle = 0; in aics_client_reset()
658 inst->cli.desc_handle = 0; in aics_client_reset()
660 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_DESC_WRITABLE); in aics_client_reset()
661 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_CP_RETRIED); in aics_client_reset()
663 if (inst->cli.conn != NULL) { in aics_client_reset()
664 struct bt_conn *conn = inst->cli.conn; in aics_client_reset()
667 inst->cli.conn = NULL; in aics_client_reset()
674 if (aics_insts[i].cli.conn == conn) { in disconnected()
702 CHECKIF(!atomic_test_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_ACTIVE)) { in bt_aics_discover()
707 if (atomic_test_and_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY)) { in bt_aics_discover()
714 (void)memset(&inst->cli.discover_params, 0, sizeof(inst->cli.discover_params)); in bt_aics_discover()
716 inst->cli.discover_params.start_handle = param->start_handle; in bt_aics_discover()
717 inst->cli.discover_params.end_handle = param->end_handle; in bt_aics_discover()
718 inst->cli.discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; in bt_aics_discover()
719 inst->cli.discover_params.func = aics_discover_func; in bt_aics_discover()
721 err = bt_gatt_discover(conn, &inst->cli.discover_params); in bt_aics_discover()
723 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in bt_aics_discover()
726 inst->cli.conn = bt_conn_ref(conn); in bt_aics_discover()
735 if (!atomic_test_and_set_bit(aics_insts[i].cli.flags, BT_AICS_CLIENT_FLAG_ACTIVE)) { in bt_aics_client_free_instance_get()
756 if (aics->cli.conn == NULL) { in bt_aics_client_conn_get()
762 *conn = aics->cli.conn; in bt_aics_client_conn_get()
780 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_state_get()
785 if (!inst->cli.state_handle) { in bt_aics_client_state_get()
788 } else if (atomic_test_and_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY)) { in bt_aics_client_state_get()
792 inst->cli.read_params.func = aics_client_read_state_cb; in bt_aics_client_state_get()
793 inst->cli.read_params.handle_count = 1; in bt_aics_client_state_get()
794 inst->cli.read_params.single.handle = inst->cli.state_handle; in bt_aics_client_state_get()
796 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_state_get()
798 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in bt_aics_client_state_get()
818 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_gain_setting_get()
823 if (!inst->cli.gain_handle) { in bt_aics_client_gain_setting_get()
826 } else if (atomic_test_and_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY)) { in bt_aics_client_gain_setting_get()
830 inst->cli.read_params.func = aics_client_read_gain_settings_cb; in bt_aics_client_gain_setting_get()
831 inst->cli.read_params.handle_count = 1; in bt_aics_client_gain_setting_get()
832 inst->cli.read_params.single.handle = inst->cli.gain_handle; in bt_aics_client_gain_setting_get()
834 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_gain_setting_get()
836 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in bt_aics_client_gain_setting_get()
856 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_type_get()
861 if (!inst->cli.type_handle) { in bt_aics_client_type_get()
864 } else if (atomic_test_and_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY)) { in bt_aics_client_type_get()
868 inst->cli.read_params.func = aics_client_read_type_cb; in bt_aics_client_type_get()
869 inst->cli.read_params.handle_count = 1; in bt_aics_client_type_get()
870 inst->cli.read_params.single.handle = inst->cli.type_handle; in bt_aics_client_type_get()
872 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_type_get()
874 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in bt_aics_client_type_get()
894 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_status_get()
899 if (!inst->cli.status_handle) { in bt_aics_client_status_get()
902 } else if (atomic_test_and_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY)) { in bt_aics_client_status_get()
906 inst->cli.read_params.func = aics_client_read_status_cb; in bt_aics_client_status_get()
907 inst->cli.read_params.handle_count = 1; in bt_aics_client_status_get()
908 inst->cli.read_params.single.handle = inst->cli.status_handle; in bt_aics_client_status_get()
910 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_status_get()
912 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in bt_aics_client_status_get()
952 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_gain_set()
957 if (!inst->cli.control_handle) { in bt_aics_client_gain_set()
960 } else if (atomic_test_and_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY)) { in bt_aics_client_gain_set()
964 inst->cli.cp_val.cp.opcode = BT_AICS_OPCODE_SET_GAIN; in bt_aics_client_gain_set()
965 inst->cli.cp_val.cp.counter = inst->cli.change_counter; in bt_aics_client_gain_set()
966 inst->cli.cp_val.gain_setting = gain; in bt_aics_client_gain_set()
968 inst->cli.write_params.data = &inst->cli.cp_val; in bt_aics_client_gain_set()
969 inst->cli.write_params.length = sizeof(inst->cli.cp_val); in bt_aics_client_gain_set()
970 inst->cli.write_params.handle = inst->cli.control_handle; in bt_aics_client_gain_set()
971 inst->cli.write_params.func = aics_client_write_aics_cp_cb; in bt_aics_client_gain_set()
973 err = bt_gatt_write(inst->cli.conn, &inst->cli.write_params); in bt_aics_client_gain_set()
975 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in bt_aics_client_gain_set()
995 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_description_get()
1000 if (!inst->cli.desc_handle) { in bt_aics_client_description_get()
1003 } else if (atomic_test_and_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY)) { in bt_aics_client_description_get()
1007 inst->cli.read_params.func = aics_client_read_desc_cb; in bt_aics_client_description_get()
1008 inst->cli.read_params.handle_count = 1; in bt_aics_client_description_get()
1009 inst->cli.read_params.single.handle = inst->cli.desc_handle; in bt_aics_client_description_get()
1011 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_description_get()
1013 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in bt_aics_client_description_get()
1034 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_description_set()
1039 if (!inst->cli.desc_handle) { in bt_aics_client_description_set()
1042 } else if (!atomic_test_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_DESC_WRITABLE)) { in bt_aics_client_description_set()
1045 } else if (atomic_test_and_set_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY)) { in bt_aics_client_description_set()
1049 err = bt_gatt_write_without_response(inst->cli.conn, inst->cli.desc_handle, description, in bt_aics_client_description_set()
1052 atomic_clear_bit(inst->cli.flags, BT_AICS_CLIENT_FLAG_BUSY); in bt_aics_client_description_set()
1065 inst->cli.cb = cb; in bt_aics_client_cb_register()