Lines Matching full:inst
61 struct bt_vocs_client *inst; in vocs_client_notify_handler() local
67 inst = lookup_vocs_by_handle(conn, handle); in vocs_client_notify_handler()
69 if (!inst) { in vocs_client_notify_handler()
78 if (handle == inst->state_handle) { in vocs_client_notify_handler()
79 if (length == sizeof(inst->state)) { in vocs_client_notify_handler()
80 memcpy(&inst->state, data, length); in vocs_client_notify_handler()
81 LOG_DBG("Inst %p: Offset %d, counter %u", inst, inst->state.offset, in vocs_client_notify_handler()
82 inst->state.change_counter); in vocs_client_notify_handler()
83 if (inst->cb && inst->cb->state) { in vocs_client_notify_handler()
84 inst->cb->state(&inst->vocs, 0, inst->state.offset); in vocs_client_notify_handler()
89 } else if (handle == inst->desc_handle) { in vocs_client_notify_handler()
102 LOG_DBG("Inst %p: Output description: %s", inst, desc); in vocs_client_notify_handler()
103 if (inst->cb && inst->cb->description) { in vocs_client_notify_handler()
104 inst->cb->description(&inst->vocs, 0, desc); in vocs_client_notify_handler()
106 } else if (handle == inst->location_handle) { in vocs_client_notify_handler()
107 if (length == sizeof(inst->location)) { in vocs_client_notify_handler()
108 memcpy(&inst->location, data, length); in vocs_client_notify_handler()
109 LOG_DBG("Inst %p: Location %u", inst, inst->location); in vocs_client_notify_handler()
110 if (inst->cb && inst->cb->location) { in vocs_client_notify_handler()
111 inst->cb->location(&inst->vocs, 0, inst->location); in vocs_client_notify_handler()
126 struct bt_vocs_client *inst = lookup_vocs_by_handle(conn, params->single.handle); in vocs_client_read_offset_state_cb() local
130 if (!inst) { in vocs_client_read_offset_state_cb()
135 LOG_DBG("Inst %p: err: 0x%02X", inst, err); in vocs_client_read_offset_state_cb()
136 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in vocs_client_read_offset_state_cb()
141 if (length == sizeof(inst->state)) { in vocs_client_read_offset_state_cb()
142 memcpy(&inst->state, data, length); in vocs_client_read_offset_state_cb()
143 LOG_DBG("Offset %d, counter %u", inst->state.offset, in vocs_client_read_offset_state_cb()
144 inst->state.change_counter); in vocs_client_read_offset_state_cb()
147 sizeof(inst->state)); in vocs_client_read_offset_state_cb()
155 if (inst->cb && inst->cb->state) { in vocs_client_read_offset_state_cb()
156 inst->cb->state(&inst->vocs, cb_err, cb_err ? 0 : inst->state.offset); in vocs_client_read_offset_state_cb()
167 struct bt_vocs_client *inst = lookup_vocs_by_handle(conn, params->single.handle); in vocs_client_read_location_cb() local
171 if (!inst) { in vocs_client_read_location_cb()
176 LOG_DBG("Inst %p: err: 0x%02X", inst, err); in vocs_client_read_location_cb()
177 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in vocs_client_read_location_cb()
182 if (length == sizeof(inst->location)) { in vocs_client_read_location_cb()
183 memcpy(&inst->location, data, length); in vocs_client_read_location_cb()
184 LOG_DBG("Location %u", inst->location); in vocs_client_read_location_cb()
187 sizeof(inst->location)); in vocs_client_read_location_cb()
195 if (inst->cb && inst->cb->location) { in vocs_client_read_location_cb()
196 inst->cb->location(&inst->vocs, cb_err, cb_err ? 0 : inst->location); in vocs_client_read_location_cb()
207 struct bt_vocs_client *inst = lookup_vocs_by_handle(conn, params->single.handle); in internal_read_volume_offset_state_cb() local
211 if (!inst) { in internal_read_volume_offset_state_cb()
220 if (length == sizeof(inst->state)) { in internal_read_volume_offset_state_cb()
223 memcpy(&inst->state, data, length); in internal_read_volume_offset_state_cb()
224 LOG_DBG("Offset %d, counter %u", inst->state.offset, in internal_read_volume_offset_state_cb()
225 inst->state.change_counter); in internal_read_volume_offset_state_cb()
228 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in internal_read_volume_offset_state_cb()
229 write_err = bt_vocs_client_state_set(inst, inst->cp.offset); in internal_read_volume_offset_state_cb()
235 sizeof(inst->state)); in internal_read_volume_offset_state_cb()
244 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in internal_read_volume_offset_state_cb()
246 if (inst->cb && inst->cb->set_offset) { in internal_read_volume_offset_state_cb()
247 inst->cb->set_offset(&inst->vocs, err); in internal_read_volume_offset_state_cb()
258 struct bt_vocs_client *inst = lookup_vocs_by_handle(conn, params->handle); in vocs_client_write_vocs_cp_cb() local
262 if (!inst) { in vocs_client_write_vocs_cp_cb()
267 LOG_DBG("Inst %p: err: 0x%02X", inst, err); in vocs_client_write_vocs_cp_cb()
275 atomic_test_bit(inst->flags, BT_VOCS_CLIENT_FLAG_CP_RETRIED)) { in vocs_client_write_vocs_cp_cb()
277 } else if (cb_err == BT_VOCS_ERR_INVALID_COUNTER && inst->state_handle) { in vocs_client_write_vocs_cp_cb()
280 inst->read_params.func = internal_read_volume_offset_state_cb; in vocs_client_write_vocs_cp_cb()
281 inst->read_params.handle_count = 1; in vocs_client_write_vocs_cp_cb()
282 inst->read_params.single.handle = inst->state_handle; in vocs_client_write_vocs_cp_cb()
284 atomic_set_bit(inst->flags, BT_VOCS_CLIENT_FLAG_CP_RETRIED); in vocs_client_write_vocs_cp_cb()
286 cb_err = bt_gatt_read(conn, &inst->read_params); in vocs_client_write_vocs_cp_cb()
295 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_CP_RETRIED); in vocs_client_write_vocs_cp_cb()
296 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in vocs_client_write_vocs_cp_cb()
298 if (inst->cb && inst->cb->set_offset) { in vocs_client_write_vocs_cp_cb()
299 inst->cb->set_offset(&inst->vocs, cb_err); in vocs_client_write_vocs_cp_cb()
308 struct bt_vocs_client *inst = lookup_vocs_by_handle(conn, params->single.handle); in vocs_client_read_output_desc_cb() local
313 if (!inst) { in vocs_client_read_output_desc_cb()
318 LOG_DBG("Inst %p: err: 0x%02X", inst, err); in vocs_client_read_output_desc_cb()
319 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in vocs_client_read_output_desc_cb()
340 if (inst->cb && inst->cb->description) { in vocs_client_read_output_desc_cb()
341 inst->cb->description(&inst->vocs, cb_err, cb_err ? NULL : desc); in vocs_client_read_output_desc_cb()
347 static bool valid_inst_discovered(struct bt_vocs_client *inst) in valid_inst_discovered() argument
349 return inst->state_handle && in valid_inst_discovered()
350 inst->control_handle && in valid_inst_discovered()
351 inst->location_handle && in valid_inst_discovered()
352 inst->desc_handle; in valid_inst_discovered()
358 struct bt_vocs_client *inst = CONTAINER_OF(params, struct bt_vocs_client, discover_params); in vocs_discover_func() local
361 LOG_DBG("Discovery complete for VOCS %p", inst); in vocs_discover_func()
362 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in vocs_discover_func()
365 if (inst->cb && inst->cb->discover) { in vocs_discover_func()
366 int err = valid_inst_discovered(inst) ? 0 : -ENOENT; in vocs_discover_func()
368 inst->cb->discover(&inst->vocs, err); in vocs_discover_func()
381 if (inst->start_handle == 0) { in vocs_discover_func()
382 inst->start_handle = chrc->value_handle; in vocs_discover_func()
384 inst->end_handle = chrc->value_handle; in vocs_discover_func()
388 inst->state_handle = chrc->value_handle; in vocs_discover_func()
389 sub_params = &inst->state_sub_params; in vocs_discover_func()
392 inst->location_handle = chrc->value_handle; in vocs_discover_func()
394 sub_params = &inst->location_sub_params; in vocs_discover_func()
397 atomic_set_bit(inst->flags, BT_VOCS_CLIENT_FLAG_LOC_WRITABLE); in vocs_discover_func()
401 inst->control_handle = chrc->value_handle; in vocs_discover_func()
404 inst->desc_handle = chrc->value_handle; in vocs_discover_func()
406 sub_params = &inst->desc_sub_params; in vocs_discover_func()
409 atomic_set_bit(inst->flags, BT_VOCS_CLIENT_FLAG_DESC_WRITABLE); in vocs_discover_func()
430 inst->cb->discover(&inst->vocs, err); in vocs_discover_func()
440 int bt_vocs_client_state_get(struct bt_vocs_client *inst) in bt_vocs_client_state_get() argument
444 CHECKIF(!inst) { in bt_vocs_client_state_get()
449 CHECKIF(inst->conn == NULL) { in bt_vocs_client_state_get()
454 if (!inst->state_handle) { in bt_vocs_client_state_get()
459 if (atomic_test_and_set_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY)) { in bt_vocs_client_state_get()
464 inst->read_params.func = vocs_client_read_offset_state_cb; in bt_vocs_client_state_get()
465 inst->read_params.handle_count = 1; in bt_vocs_client_state_get()
466 inst->read_params.single.handle = inst->state_handle; in bt_vocs_client_state_get()
467 inst->read_params.single.offset = 0U; in bt_vocs_client_state_get()
469 err = bt_gatt_read(inst->conn, &inst->read_params); in bt_vocs_client_state_get()
471 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in bt_vocs_client_state_get()
477 int bt_vocs_client_location_set(struct bt_vocs_client *inst, uint32_t location) in bt_vocs_client_location_set() argument
479 CHECKIF(!inst) { in bt_vocs_client_location_set()
484 CHECKIF(inst->conn == NULL) { in bt_vocs_client_location_set()
494 if (!inst->location_handle) { in bt_vocs_client_location_set()
497 } else if (!atomic_test_bit(inst->flags, BT_VOCS_CLIENT_FLAG_LOC_WRITABLE)) { in bt_vocs_client_location_set()
500 } else if (atomic_test_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY)) { in bt_vocs_client_location_set()
507 return bt_gatt_write_without_response(inst->conn, in bt_vocs_client_location_set()
508 inst->location_handle, in bt_vocs_client_location_set()
513 int bt_vocs_client_location_get(struct bt_vocs_client *inst) in bt_vocs_client_location_get() argument
517 CHECKIF(!inst) { in bt_vocs_client_location_get()
522 CHECKIF(inst->conn == NULL) { in bt_vocs_client_location_get()
527 if (!inst->location_handle) { in bt_vocs_client_location_get()
530 } else if (atomic_test_and_set_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY)) { in bt_vocs_client_location_get()
535 inst->read_params.func = vocs_client_read_location_cb; in bt_vocs_client_location_get()
536 inst->read_params.handle_count = 1; in bt_vocs_client_location_get()
537 inst->read_params.single.handle = inst->location_handle; in bt_vocs_client_location_get()
538 inst->read_params.single.offset = 0U; in bt_vocs_client_location_get()
540 err = bt_gatt_read(inst->conn, &inst->read_params); in bt_vocs_client_location_get()
542 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in bt_vocs_client_location_get()
548 int bt_vocs_client_state_set(struct bt_vocs_client *inst, int16_t offset) in bt_vocs_client_state_set() argument
552 CHECKIF(!inst) { in bt_vocs_client_state_set()
557 CHECKIF(inst->conn == NULL) { in bt_vocs_client_state_set()
567 if (!inst->control_handle) { in bt_vocs_client_state_set()
570 } else if (atomic_test_and_set_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY)) { in bt_vocs_client_state_set()
575 inst->cp.opcode = BT_VOCS_OPCODE_SET_OFFSET; in bt_vocs_client_state_set()
576 inst->cp.counter = inst->state.change_counter; in bt_vocs_client_state_set()
577 inst->cp.offset = offset; in bt_vocs_client_state_set()
579 inst->write_params.offset = 0; in bt_vocs_client_state_set()
580 inst->write_params.data = &inst->cp; in bt_vocs_client_state_set()
581 inst->write_params.length = sizeof(inst->cp); in bt_vocs_client_state_set()
582 inst->write_params.handle = inst->control_handle; in bt_vocs_client_state_set()
583 inst->write_params.func = vocs_client_write_vocs_cp_cb; in bt_vocs_client_state_set()
585 err = bt_gatt_write(inst->conn, &inst->write_params); in bt_vocs_client_state_set()
587 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in bt_vocs_client_state_set()
593 int bt_vocs_client_description_get(struct bt_vocs_client *inst) in bt_vocs_client_description_get() argument
597 CHECKIF(!inst) { in bt_vocs_client_description_get()
602 CHECKIF(inst->conn == NULL) { in bt_vocs_client_description_get()
607 if (!inst->desc_handle) { in bt_vocs_client_description_get()
610 } else if (atomic_test_and_set_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY)) { in bt_vocs_client_description_get()
615 inst->read_params.func = vocs_client_read_output_desc_cb; in bt_vocs_client_description_get()
616 inst->read_params.handle_count = 1; in bt_vocs_client_description_get()
617 inst->read_params.single.handle = inst->desc_handle; in bt_vocs_client_description_get()
618 inst->read_params.single.offset = 0U; in bt_vocs_client_description_get()
620 err = bt_gatt_read(inst->conn, &inst->read_params); in bt_vocs_client_description_get()
622 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in bt_vocs_client_description_get()
628 int bt_vocs_client_description_set(struct bt_vocs_client *inst, in bt_vocs_client_description_set() argument
631 CHECKIF(!inst) { in bt_vocs_client_description_set()
636 CHECKIF(inst->conn == NULL) { in bt_vocs_client_description_set()
641 if (!inst->desc_handle) { in bt_vocs_client_description_set()
644 } else if (!atomic_test_bit(inst->flags, BT_VOCS_CLIENT_FLAG_DESC_WRITABLE)) { in bt_vocs_client_description_set()
647 } else if (atomic_test_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY)) { in bt_vocs_client_description_set()
654 return bt_gatt_write_without_response(inst->conn, in bt_vocs_client_description_set()
655 inst->desc_handle, in bt_vocs_client_description_set()
674 struct bt_vocs_client *inst; in bt_vocs_client_conn_get() local
686 inst = CONTAINER_OF(vocs, struct bt_vocs_client, vocs); in bt_vocs_client_conn_get()
688 if (inst->conn == NULL) { in bt_vocs_client_conn_get()
694 *conn = inst->conn; in bt_vocs_client_conn_get()
698 static void vocs_client_reset(struct bt_vocs_client *inst) in vocs_client_reset() argument
700 memset(&inst->state, 0, sizeof(inst->state)); in vocs_client_reset()
701 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_LOC_WRITABLE); in vocs_client_reset()
702 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_DESC_WRITABLE); in vocs_client_reset()
703 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_CP_RETRIED); in vocs_client_reset()
705 inst->location = 0; in vocs_client_reset()
706 inst->start_handle = 0; in vocs_client_reset()
707 inst->end_handle = 0; in vocs_client_reset()
708 inst->state_handle = 0; in vocs_client_reset()
709 inst->location_handle = 0; in vocs_client_reset()
710 inst->control_handle = 0; in vocs_client_reset()
711 inst->desc_handle = 0; in vocs_client_reset()
713 if (inst->conn != NULL) { in vocs_client_reset()
714 struct bt_conn *conn = inst->conn; in vocs_client_reset()
717 inst->conn = NULL; in vocs_client_reset()
724 struct bt_vocs_client *inst; in bt_vocs_discover() local
745 inst = CONTAINER_OF(vocs, struct bt_vocs_client, vocs); in bt_vocs_discover()
747 if (!atomic_test_bit(inst->flags, BT_VOCS_CLIENT_FLAG_ACTIVE)) { in bt_vocs_discover()
750 } else if (atomic_test_and_set_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY)) { in bt_vocs_discover()
755 vocs_client_reset(inst); in bt_vocs_discover()
757 inst->conn = bt_conn_ref(conn); in bt_vocs_discover()
758 inst->discover_params.start_handle = param->start_handle; in bt_vocs_discover()
759 inst->discover_params.end_handle = param->end_handle; in bt_vocs_discover()
760 inst->discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; in bt_vocs_discover()
761 inst->discover_params.func = vocs_discover_func; in bt_vocs_discover()
763 err = bt_gatt_discover(conn, &inst->discover_params); in bt_vocs_discover()
766 atomic_clear_bit(inst->flags, BT_VOCS_CLIENT_FLAG_BUSY); in bt_vocs_discover()
774 struct bt_vocs_client *inst; in bt_vocs_client_cb_register() local
777 LOG_DBG("inst cannot be NULL"); in bt_vocs_client_cb_register()
786 inst = CONTAINER_OF(vocs, struct bt_vocs_client, vocs); in bt_vocs_client_cb_register()
788 inst->cb = cb; in bt_vocs_client_cb_register()