Lines Matching refs:inst
32 static int aics_client_common_control(uint8_t opcode, struct bt_aics *inst);
54 struct bt_aics *inst; in aics_client_notify_handler() local
62 inst = lookup_aics_by_handle(conn, handle); in aics_client_notify_handler()
64 if (!inst) { in aics_client_notify_handler()
73 if (handle == inst->cli.state_handle) { in aics_client_notify_handler()
76 LOG_DBG("Inst %p: Gain %d, mute %u, gain_mode %u, counter %u", inst, in aics_client_notify_handler()
79 inst->cli.change_counter = state->change_counter; in aics_client_notify_handler()
81 if (inst->cli.cb && inst->cli.cb->state) { in aics_client_notify_handler()
82 inst->cli.cb->state(inst, 0, state->gain, in aics_client_notify_handler()
87 } else if (handle == inst->cli.status_handle) { in aics_client_notify_handler()
90 LOG_DBG("Inst %p: Status %u", inst, *status); in aics_client_notify_handler()
91 if (inst->cli.cb && inst->cli.cb->status) { in aics_client_notify_handler()
92 inst->cli.cb->status(inst, 0, *status); in aics_client_notify_handler()
95 } else if (handle == inst->cli.desc_handle) { in aics_client_notify_handler()
107 LOG_DBG("Inst %p: Input description: %s", inst, desc); in aics_client_notify_handler()
108 if (inst->cli.cb && inst->cli.cb->description) { in aics_client_notify_handler()
109 inst->cli.cb->description(inst, 0, desc); in aics_client_notify_handler()
121 struct bt_aics *inst = lookup_aics_by_handle(conn, params->single.handle); in aics_client_read_state_cb() local
126 if (!inst) { in aics_client_read_state_cb()
131 LOG_DBG("Inst %p: err: 0x%02X", inst, err); in aics_client_read_state_cb()
132 inst->cli.busy = false; in aics_client_read_state_cb()
136 if (inst->cli.cb && inst->cli.cb->state) { in aics_client_read_state_cb()
137 inst->cli.cb->state(inst, cb_err, 0, 0, 0); in aics_client_read_state_cb()
147 inst->cli.change_counter = state->change_counter; in aics_client_read_state_cb()
157 if (inst->cli.cb && inst->cli.cb->state) { in aics_client_read_state_cb()
158 inst->cli.cb->state(inst, cb_err, state->gain, in aics_client_read_state_cb()
170 struct bt_aics *inst = lookup_aics_by_handle(conn, params->single.handle); in aics_client_read_gain_settings_cb() local
175 if (!inst) { in aics_client_read_gain_settings_cb()
180 LOG_DBG("Inst %p: err: 0x%02X", inst, err); in aics_client_read_gain_settings_cb()
181 inst->cli.busy = false; in aics_client_read_gain_settings_cb()
185 if (inst->cli.cb && inst->cli.cb->gain_setting) { in aics_client_read_gain_settings_cb()
186 inst->cli.cb->gain_setting(inst, cb_err, 0, 0, 0); in aics_client_read_gain_settings_cb()
204 if (inst->cli.cb && inst->cli.cb->gain_setting) { in aics_client_read_gain_settings_cb()
205 inst->cli.cb->gain_setting(inst, cb_err, gain_settings->units, in aics_client_read_gain_settings_cb()
219 struct bt_aics *inst = lookup_aics_by_handle(conn, params->single.handle); in aics_client_read_type_cb() local
223 if (!inst) { in aics_client_read_type_cb()
228 LOG_DBG("Inst %p: err: 0x%02X", inst, err); in aics_client_read_type_cb()
229 inst->cli.busy = false; in aics_client_read_type_cb()
233 if (inst->cli.cb && inst->cli.cb->type) { in aics_client_read_type_cb()
234 inst->cli.cb->type(inst, cb_err, 0); in aics_client_read_type_cb()
251 if (inst->cli.cb && inst->cli.cb->type) { in aics_client_read_type_cb()
252 inst->cli.cb->type(inst, cb_err, *type); in aics_client_read_type_cb()
264 struct bt_aics *inst = lookup_aics_by_handle(conn, params->single.handle); in aics_client_read_status_cb() local
268 if (!inst) { in aics_client_read_status_cb()
273 LOG_DBG("Inst %p: err: 0x%02X", inst, err); in aics_client_read_status_cb()
274 inst->cli.busy = false; in aics_client_read_status_cb()
278 if (inst->cli.cb && inst->cli.cb->status) { in aics_client_read_status_cb()
279 inst->cli.cb->status(inst, cb_err, 0); in aics_client_read_status_cb()
296 if (inst->cli.cb && inst->cli.cb->status) { in aics_client_read_status_cb()
297 inst->cli.cb->status(inst, cb_err, *status); in aics_client_read_status_cb()
303 static void aics_cp_notify_app(struct bt_aics *inst, uint8_t err) in aics_cp_notify_app() argument
305 if (!inst->cli.cb) { in aics_cp_notify_app()
309 switch (inst->cli.cp_val.cp.opcode) { in aics_cp_notify_app()
311 if (inst->cli.cb->set_gain) { in aics_cp_notify_app()
312 inst->cli.cb->set_gain(inst, err); in aics_cp_notify_app()
316 if (inst->cli.cb->unmute) { in aics_cp_notify_app()
317 inst->cli.cb->unmute(inst, err); in aics_cp_notify_app()
321 if (inst->cli.cb->mute) { in aics_cp_notify_app()
322 inst->cli.cb->mute(inst, err); in aics_cp_notify_app()
326 if (inst->cli.cb->set_manual_mode) { in aics_cp_notify_app()
327 inst->cli.cb->set_manual_mode(inst, err); in aics_cp_notify_app()
331 if (inst->cli.cb->set_auto_mode) { in aics_cp_notify_app()
332 inst->cli.cb->set_auto_mode(inst, err); in aics_cp_notify_app()
336 LOG_DBG("Unknown opcode 0x%02x", inst->cli.cp_val.cp.opcode); in aics_cp_notify_app()
346 struct bt_aics *inst = lookup_aics_by_handle(conn, params->single.handle); in internal_read_state_cb() local
351 if (!inst) { in internal_read_state_cb()
364 inst->cli.change_counter = state->change_counter; in internal_read_state_cb()
367 inst->cli.busy = false; in internal_read_state_cb()
369 if (inst->cli.cp_val.cp.opcode == BT_AICS_OPCODE_SET_GAIN) { in internal_read_state_cb()
370 write_err = bt_aics_client_gain_set(inst, in internal_read_state_cb()
371 inst->cli.cp_val.gain_setting); in internal_read_state_cb()
373 write_err = aics_client_common_control(inst->cli.cp_val.cp.opcode, in internal_read_state_cb()
374 inst); in internal_read_state_cb()
387 inst->cli.busy = false; in internal_read_state_cb()
388 aics_cp_notify_app(inst, cb_err); in internal_read_state_cb()
399 struct bt_aics *inst = lookup_aics_by_handle(conn, params->handle); in aics_client_write_aics_cp_cb() local
403 if (!inst) { in aics_client_write_aics_cp_cb()
408 LOG_DBG("Inst %p: err: %d", inst, cb_err); in aics_client_write_aics_cp_cb()
416 if (cb_err == BT_AICS_ERR_INVALID_COUNTER && inst->cli.cp_retried) { in aics_client_write_aics_cp_cb()
418 } else if (cb_err == BT_AICS_ERR_INVALID_COUNTER && inst->cli.state_handle) { in aics_client_write_aics_cp_cb()
419 inst->cli.read_params.func = internal_read_state_cb; in aics_client_write_aics_cp_cb()
420 inst->cli.read_params.handle_count = 1; in aics_client_write_aics_cp_cb()
421 inst->cli.read_params.single.handle = inst->cli.state_handle; in aics_client_write_aics_cp_cb()
422 inst->cli.read_params.single.offset = 0U; in aics_client_write_aics_cp_cb()
424 cb_err = bt_gatt_read(conn, &inst->cli.read_params); in aics_client_write_aics_cp_cb()
429 inst->cli.cp_retried = true; in aics_client_write_aics_cp_cb()
435 inst->cli.busy = false; in aics_client_write_aics_cp_cb()
436 inst->cli.cp_retried = false; in aics_client_write_aics_cp_cb()
438 aics_cp_notify_app(inst, cb_err); in aics_client_write_aics_cp_cb()
441 static int aics_client_common_control(uint8_t opcode, struct bt_aics *inst) in aics_client_common_control() argument
445 CHECKIF(!inst) { in aics_client_common_control()
450 CHECKIF(!inst->client_instance) { in aics_client_common_control()
455 CHECKIF(inst->cli.conn == NULL) { in aics_client_common_control()
460 if (!inst->cli.control_handle) { in aics_client_common_control()
463 } else if (inst->cli.busy) { in aics_client_common_control()
467 inst->cli.cp_val.cp.opcode = opcode; in aics_client_common_control()
468 inst->cli.cp_val.cp.counter = inst->cli.change_counter; in aics_client_common_control()
470 inst->cli.write_params.offset = 0; in aics_client_common_control()
471 inst->cli.write_params.data = &inst->cli.cp_val.cp; in aics_client_common_control()
472 inst->cli.write_params.length = sizeof(inst->cli.cp_val.cp); in aics_client_common_control()
473 inst->cli.write_params.handle = inst->cli.control_handle; in aics_client_common_control()
474 inst->cli.write_params.func = aics_client_write_aics_cp_cb; in aics_client_common_control()
476 err = bt_gatt_write(inst->cli.conn, &inst->cli.write_params); in aics_client_common_control()
478 inst->cli.busy = true; in aics_client_common_control()
491 struct bt_aics *inst = lookup_aics_by_handle(conn, params->single.handle); in aics_client_read_desc_cb() local
495 if (!inst) { in aics_client_read_desc_cb()
500 inst->cli.busy = false; in aics_client_read_desc_cb()
504 if (inst->cli.cb && inst->cli.cb->description) { in aics_client_read_desc_cb()
505 inst->cli.cb->description(inst, cb_err, NULL); in aics_client_read_desc_cb()
528 if (inst->cli.cb && inst->cli.cb->description) { in aics_client_read_desc_cb()
529 inst->cli.cb->description(inst, cb_err, desc); in aics_client_read_desc_cb()
535 static bool valid_inst_discovered(struct bt_aics *inst) in valid_inst_discovered() argument
537 return inst->cli.state_handle && in valid_inst_discovered()
538 inst->cli.gain_handle && in valid_inst_discovered()
539 inst->cli.type_handle && in valid_inst_discovered()
540 inst->cli.status_handle && in valid_inst_discovered()
541 inst->cli.control_handle && in valid_inst_discovered()
542 inst->cli.desc_handle; in valid_inst_discovered()
551 struct bt_aics *inst = CONTAINER_OF(client_inst, struct bt_aics, cli); in aics_discover_func() local
554 LOG_DBG("Discovery complete for AICS %p", inst); in aics_discover_func()
558 inst->cli.busy = false; in aics_discover_func()
560 if (inst->cli.cb && inst->cli.cb->discover) { in aics_discover_func()
561 int err = valid_inst_discovered(inst) ? 0 : -ENOENT; in aics_discover_func()
563 inst->cli.cb->discover(inst, err); in aics_discover_func()
576 if (inst->cli.start_handle == 0) { in aics_discover_func()
577 inst->cli.start_handle = chrc->value_handle; in aics_discover_func()
579 inst->cli.end_handle = chrc->value_handle; in aics_discover_func()
583 inst->cli.state_handle = chrc->value_handle; in aics_discover_func()
584 sub_params = &inst->cli.state_sub_params; in aics_discover_func()
587 inst->cli.gain_handle = chrc->value_handle; in aics_discover_func()
590 inst->cli.type_handle = chrc->value_handle; in aics_discover_func()
593 inst->cli.status_handle = chrc->value_handle; in aics_discover_func()
594 sub_params = &inst->cli.status_sub_params; in aics_discover_func()
597 inst->cli.control_handle = chrc->value_handle; in aics_discover_func()
600 inst->cli.desc_handle = chrc->value_handle; in aics_discover_func()
602 sub_params = &inst->cli.desc_sub_params; in aics_discover_func()
606 inst->cli.desc_writable = true; in aics_discover_func()
627 if (inst->cli.cb && inst->cli.cb->discover) { in aics_discover_func()
628 inst->cli.cb->discover(inst, err); in aics_discover_func()
639 static void aics_client_reset(struct bt_aics *inst) in aics_client_reset() argument
641 inst->cli.desc_writable = 0; in aics_client_reset()
642 inst->cli.change_counter = 0; in aics_client_reset()
643 inst->cli.gain_mode = 0; in aics_client_reset()
644 inst->cli.start_handle = 0; in aics_client_reset()
645 inst->cli.end_handle = 0; in aics_client_reset()
646 inst->cli.state_handle = 0; in aics_client_reset()
647 inst->cli.gain_handle = 0; in aics_client_reset()
648 inst->cli.type_handle = 0; in aics_client_reset()
649 inst->cli.status_handle = 0; in aics_client_reset()
650 inst->cli.control_handle = 0; in aics_client_reset()
651 inst->cli.desc_handle = 0; in aics_client_reset()
653 if (inst->cli.conn != NULL) { in aics_client_reset()
654 struct bt_conn *conn = inst->cli.conn; in aics_client_reset()
657 inst->cli.conn = NULL; in aics_client_reset()
674 int bt_aics_discover(struct bt_conn *conn, struct bt_aics *inst, in bt_aics_discover() argument
679 CHECKIF(!inst || !conn || !param) { in bt_aics_discover()
680 LOG_DBG("%s cannot be NULL", inst == NULL ? "inst" in bt_aics_discover()
692 CHECKIF(!inst->cli.active) { in bt_aics_discover()
697 if (inst->cli.busy) { in bt_aics_discover()
702 aics_client_reset(inst); in bt_aics_discover()
704 (void)memset(&inst->cli.discover_params, 0, sizeof(inst->cli.discover_params)); in bt_aics_discover()
706 inst->cli.discover_params.start_handle = param->start_handle; in bt_aics_discover()
707 inst->cli.discover_params.end_handle = param->end_handle; in bt_aics_discover()
708 inst->cli.discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; in bt_aics_discover()
709 inst->cli.discover_params.func = aics_discover_func; in bt_aics_discover()
711 err = bt_gatt_discover(conn, &inst->cli.discover_params); in bt_aics_discover()
715 inst->cli.busy = true; in bt_aics_discover()
716 inst->cli.conn = bt_conn_ref(conn); in bt_aics_discover()
757 int bt_aics_client_state_get(struct bt_aics *inst) in bt_aics_client_state_get() argument
761 CHECKIF(!inst) { in bt_aics_client_state_get()
766 CHECKIF(!inst->client_instance) { in bt_aics_client_state_get()
771 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_state_get()
776 if (!inst->cli.state_handle) { in bt_aics_client_state_get()
779 } else if (inst->cli.busy) { in bt_aics_client_state_get()
783 inst->cli.read_params.func = aics_client_read_state_cb; in bt_aics_client_state_get()
784 inst->cli.read_params.handle_count = 1; in bt_aics_client_state_get()
785 inst->cli.read_params.single.handle = inst->cli.state_handle; in bt_aics_client_state_get()
787 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_state_get()
789 inst->cli.busy = true; in bt_aics_client_state_get()
795 int bt_aics_client_gain_setting_get(struct bt_aics *inst) in bt_aics_client_gain_setting_get() argument
799 CHECKIF(!inst) { in bt_aics_client_gain_setting_get()
804 CHECKIF(!inst->client_instance) { in bt_aics_client_gain_setting_get()
809 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_gain_setting_get()
814 if (!inst->cli.gain_handle) { in bt_aics_client_gain_setting_get()
817 } else if (inst->cli.busy) { in bt_aics_client_gain_setting_get()
821 inst->cli.read_params.func = aics_client_read_gain_settings_cb; in bt_aics_client_gain_setting_get()
822 inst->cli.read_params.handle_count = 1; in bt_aics_client_gain_setting_get()
823 inst->cli.read_params.single.handle = inst->cli.gain_handle; in bt_aics_client_gain_setting_get()
825 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_gain_setting_get()
827 inst->cli.busy = true; in bt_aics_client_gain_setting_get()
833 int bt_aics_client_type_get(struct bt_aics *inst) in bt_aics_client_type_get() argument
837 CHECKIF(!inst) { in bt_aics_client_type_get()
842 CHECKIF(!inst->client_instance) { in bt_aics_client_type_get()
847 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_type_get()
852 if (!inst->cli.type_handle) { in bt_aics_client_type_get()
855 } else if (inst->cli.busy) { in bt_aics_client_type_get()
859 inst->cli.read_params.func = aics_client_read_type_cb; in bt_aics_client_type_get()
860 inst->cli.read_params.handle_count = 1; in bt_aics_client_type_get()
861 inst->cli.read_params.single.handle = inst->cli.type_handle; in bt_aics_client_type_get()
863 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_type_get()
865 inst->cli.busy = true; in bt_aics_client_type_get()
871 int bt_aics_client_status_get(struct bt_aics *inst) in bt_aics_client_status_get() argument
875 CHECKIF(!inst) { in bt_aics_client_status_get()
880 CHECKIF(!inst->client_instance) { in bt_aics_client_status_get()
885 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_status_get()
890 if (!inst->cli.status_handle) { in bt_aics_client_status_get()
893 } else if (inst->cli.busy) { in bt_aics_client_status_get()
897 inst->cli.read_params.func = aics_client_read_status_cb; in bt_aics_client_status_get()
898 inst->cli.read_params.handle_count = 1; in bt_aics_client_status_get()
899 inst->cli.read_params.single.handle = inst->cli.status_handle; in bt_aics_client_status_get()
901 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_status_get()
903 inst->cli.busy = true; in bt_aics_client_status_get()
909 int bt_aics_client_unmute(struct bt_aics *inst) in bt_aics_client_unmute() argument
911 return aics_client_common_control(BT_AICS_OPCODE_UNMUTE, inst); in bt_aics_client_unmute()
914 int bt_aics_client_mute(struct bt_aics *inst) in bt_aics_client_mute() argument
916 return aics_client_common_control(BT_AICS_OPCODE_MUTE, inst); in bt_aics_client_mute()
919 int bt_aics_client_manual_gain_set(struct bt_aics *inst) in bt_aics_client_manual_gain_set() argument
921 return aics_client_common_control(BT_AICS_OPCODE_SET_MANUAL, inst); in bt_aics_client_manual_gain_set()
924 int bt_aics_client_automatic_gain_set(struct bt_aics *inst) in bt_aics_client_automatic_gain_set() argument
926 return aics_client_common_control(BT_AICS_OPCODE_SET_AUTO, inst); in bt_aics_client_automatic_gain_set()
929 int bt_aics_client_gain_set(struct bt_aics *inst, int8_t gain) in bt_aics_client_gain_set() argument
933 CHECKIF(!inst) { in bt_aics_client_gain_set()
938 CHECKIF(!inst->client_instance) { in bt_aics_client_gain_set()
943 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_gain_set()
948 if (!inst->cli.control_handle) { in bt_aics_client_gain_set()
951 } else if (inst->cli.busy) { in bt_aics_client_gain_set()
955 inst->cli.cp_val.cp.opcode = BT_AICS_OPCODE_SET_GAIN; in bt_aics_client_gain_set()
956 inst->cli.cp_val.cp.counter = inst->cli.change_counter; in bt_aics_client_gain_set()
957 inst->cli.cp_val.gain_setting = gain; in bt_aics_client_gain_set()
959 inst->cli.write_params.data = &inst->cli.cp_val; in bt_aics_client_gain_set()
960 inst->cli.write_params.length = sizeof(inst->cli.cp_val); in bt_aics_client_gain_set()
961 inst->cli.write_params.handle = inst->cli.control_handle; in bt_aics_client_gain_set()
962 inst->cli.write_params.func = aics_client_write_aics_cp_cb; in bt_aics_client_gain_set()
964 err = bt_gatt_write(inst->cli.conn, &inst->cli.write_params); in bt_aics_client_gain_set()
966 inst->cli.busy = true; in bt_aics_client_gain_set()
972 int bt_aics_client_description_get(struct bt_aics *inst) in bt_aics_client_description_get() argument
976 CHECKIF(!inst) { in bt_aics_client_description_get()
981 CHECKIF(!inst->client_instance) { in bt_aics_client_description_get()
986 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_description_get()
991 if (!inst->cli.desc_handle) { in bt_aics_client_description_get()
994 } else if (inst->cli.busy) { in bt_aics_client_description_get()
998 inst->cli.read_params.func = aics_client_read_desc_cb; in bt_aics_client_description_get()
999 inst->cli.read_params.handle_count = 1; in bt_aics_client_description_get()
1000 inst->cli.read_params.single.handle = inst->cli.desc_handle; in bt_aics_client_description_get()
1002 err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params); in bt_aics_client_description_get()
1004 inst->cli.busy = true; in bt_aics_client_description_get()
1010 int bt_aics_client_description_set(struct bt_aics *inst, in bt_aics_client_description_set() argument
1013 CHECKIF(!inst) { in bt_aics_client_description_set()
1018 CHECKIF(!inst->client_instance) { in bt_aics_client_description_set()
1023 CHECKIF(inst->cli.conn == NULL) { in bt_aics_client_description_set()
1028 if (!inst->cli.desc_handle) { in bt_aics_client_description_set()
1031 } else if (inst->cli.busy) { in bt_aics_client_description_set()
1033 } else if (!inst->cli.desc_writable) { in bt_aics_client_description_set()
1038 return bt_gatt_write_without_response(inst->cli.conn, inst->cli.desc_handle, in bt_aics_client_description_set()
1043 void bt_aics_client_cb_register(struct bt_aics *inst, struct bt_aics_cb *cb) in bt_aics_client_cb_register() argument
1045 CHECKIF(!inst) { in bt_aics_client_cb_register()
1050 inst->cli.cb = cb; in bt_aics_client_cb_register()