Lines Matching full:inst

38 	struct bt_has_client *inst = &clients[bt_conn_index(conn)];  in inst_by_conn()  local
40 if (inst->conn == conn) { in inst_by_conn()
41 return inst; in inst_by_conn()
47 static void inst_cleanup(struct bt_has_client *inst) in inst_cleanup() argument
49 bt_conn_unref(inst->conn); in inst_cleanup()
51 (void)memset(inst, 0, sizeof(*inst)); in inst_cleanup()
54 static enum bt_has_capabilities get_capabilities(const struct bt_has_client *inst) in get_capabilities() argument
59 if (HANDLE_IS_VALID(inst->control_point_subscription.value_handle)) { in get_capabilities()
66 static void handle_read_preset_rsp(struct bt_has_client *inst, struct net_buf_simple *buf) in handle_read_preset_rsp() argument
73 LOG_DBG("conn %p buf %p", (void *)inst->conn, buf); in handle_read_preset_rsp()
99 client_cb->preset_read_rsp(&inst->has, 0, &record, !!pdu->is_last); in handle_read_preset_rsp()
102 static void handle_generic_update(struct bt_has_client *inst, struct net_buf_simple *buf, in handle_generic_update() argument
130 client_cb->preset_update(&inst->has, pdu->prev_index, &record, is_last); in handle_generic_update()
133 static void handle_preset_deleted(struct bt_has_client *inst, struct net_buf_simple *buf, in handle_preset_deleted() argument
141 client_cb->preset_deleted(&inst->has, net_buf_simple_pull_u8(buf), is_last); in handle_preset_deleted()
144 static void handle_preset_availability(struct bt_has_client *inst, struct net_buf_simple *buf, in handle_preset_availability() argument
152 client_cb->preset_availability(&inst->has, net_buf_simple_pull_u8(buf), available, in handle_preset_availability()
156 static void handle_preset_changed(struct bt_has_client *inst, struct net_buf_simple *buf) in handle_preset_changed() argument
160 LOG_DBG("conn %p buf %p", (void *)inst->conn, buf); in handle_preset_changed()
176 handle_generic_update(inst, buf, !!pdu->is_last); in handle_preset_changed()
181 handle_preset_deleted(inst, buf, !!pdu->is_last); in handle_preset_changed()
186 handle_preset_availability(inst, buf, !!pdu->is_last, true); in handle_preset_changed()
191 handle_preset_availability(inst, buf, !!pdu->is_last, false); in handle_preset_changed()
203 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, in control_point_notify_cb() local
230 handle_read_preset_rsp(inst, &buf); in control_point_notify_cb()
233 handle_preset_changed(inst, &buf); in control_point_notify_cb()
240 static void discover_complete(struct bt_has_client *inst) in discover_complete() argument
242 LOG_DBG("conn %p", (void *)inst->conn); in discover_complete()
244 atomic_clear_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS); in discover_complete()
246 client_cb->discover(inst->conn, 0, &inst->has, in discover_complete()
247 inst->has.features & BT_HAS_FEAT_HEARING_AID_TYPE_MASK, in discover_complete()
248 get_capabilities(inst)); in discover_complete()
252 HANDLE_IS_VALID(inst->active_index_subscription.value_handle)) { in discover_complete()
253 client_cb->preset_switch(&inst->has, 0, inst->has.active_index); in discover_complete()
264 static int cp_write(struct bt_has_client *inst, struct net_buf_simple *buf, in cp_write() argument
267 const uint16_t value_handle = inst->control_point_subscription.value_handle; in cp_write()
273 inst->params.write.func = func; in cp_write()
274 inst->params.write.handle = value_handle; in cp_write()
275 inst->params.write.offset = 0U; in cp_write()
276 inst->params.write.data = buf->data; in cp_write()
277 inst->params.write.length = buf->len; in cp_write()
279 return bt_gatt_write(inst->conn, &inst->params.write); in cp_write()
285 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.write); in read_presets_req_cb() local
289 atomic_clear_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS); in read_presets_req_cb()
292 client_cb->preset_read_rsp(&inst->has, err, NULL, true); in read_presets_req_cb()
296 static int read_presets_req(struct bt_has_client *inst, uint8_t start_index, uint8_t num_presets) in read_presets_req() argument
303 LOG_DBG("conn %p start_index 0x%02x num_presets %d", (void *)inst->conn, start_index, in read_presets_req()
312 return cp_write(inst, &buf, read_presets_req_cb); in read_presets_req()
318 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.write); in set_active_preset_cb() local
322 atomic_clear_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS); in set_active_preset_cb()
325 client_cb->preset_switch(&inst->has, err, inst->has.active_index); in set_active_preset_cb()
329 static int preset_set(struct bt_has_client *inst, uint8_t opcode, uint8_t index) in preset_set() argument
336 LOG_DBG("conn %p opcode 0x%02x index 0x%02x", (void *)inst->conn, opcode, index); in preset_set()
343 return cp_write(inst, &buf, set_active_preset_cb); in preset_set()
346 static int preset_set_next_or_prev(struct bt_has_client *inst, uint8_t opcode) in preset_set_next_or_prev() argument
352 LOG_DBG("conn %p opcode 0x%02x", (void *)inst->conn, opcode); in preset_set_next_or_prev()
357 return cp_write(inst, &buf, set_active_preset_cb); in preset_set_next_or_prev()
360 static uint8_t active_index_update(struct bt_has_client *inst, const void *data, uint16_t len) in active_index_update() argument
363 const uint8_t prev = inst->has.active_index; in active_index_update()
367 inst->has.active_index = net_buf_simple_pull_u8(&buf); in active_index_update()
369 LOG_DBG("conn %p index 0x%02x", (void *)inst->conn, inst->has.active_index); in active_index_update()
378 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, in active_preset_notify_cb() local
401 prev = active_index_update(inst, data, len); in active_preset_notify_cb()
403 if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS)) { in active_preset_notify_cb()
410 if (client_cb && client_cb->preset_switch && inst->has.active_index != prev) { in active_preset_notify_cb()
411 client_cb->preset_switch(&inst->has, 0, inst->has.active_index); in active_preset_notify_cb()
420 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, in active_index_subscribe_cb() local
423 LOG_DBG("conn %p att_err 0x%02x params %p", (void *)inst->conn, att_err, params); in active_index_subscribe_cb()
427 inst_cleanup(inst); in active_index_subscribe_cb()
431 discover_complete(inst); in active_index_subscribe_cb()
435 static int active_index_subscribe(struct bt_has_client *inst, uint16_t value_handle) in active_index_subscribe() argument
439 LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle); in active_index_subscribe()
441 inst->active_index_subscription.notify = active_preset_notify_cb; in active_index_subscribe()
442 inst->active_index_subscription.subscribe = active_index_subscribe_cb; in active_index_subscribe()
443 inst->active_index_subscription.value_handle = value_handle; in active_index_subscribe()
444 inst->active_index_subscription.ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE; in active_index_subscribe()
445 inst->active_index_subscription.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; in active_index_subscribe()
446 inst->active_index_subscription.disc_params = &inst->params.discover; in active_index_subscribe()
447 inst->active_index_subscription.value = BT_GATT_CCC_NOTIFY; in active_index_subscribe()
448 atomic_set_bit(inst->active_index_subscription.flags, BT_GATT_SUBSCRIBE_FLAG_VOLATILE); in active_index_subscribe()
450 err = bt_gatt_subscribe(inst->conn, &inst->active_index_subscription); in active_index_subscribe()
462 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.read); in active_index_read_cb() local
472 active_index_update(inst, data, len); in active_index_read_cb()
474 err = active_index_subscribe(inst, params->by_uuid.start_handle); in active_index_read_cb()
484 inst_cleanup(inst); in active_index_read_cb()
491 static int active_index_read(struct bt_has_client *inst) in active_index_read() argument
493 LOG_DBG("conn %p", (void *)inst->conn); in active_index_read()
495 (void)memset(&inst->params.read, 0, sizeof(inst->params.read)); in active_index_read()
497 (void)memcpy(&inst->params.uuid, BT_UUID_HAS_ACTIVE_PRESET_INDEX, in active_index_read()
498 sizeof(inst->params.uuid)); in active_index_read()
499 inst->params.read.func = active_index_read_cb; in active_index_read()
500 inst->params.read.handle_count = 0u; in active_index_read()
501 inst->params.read.by_uuid.uuid = &inst->params.uuid.uuid; in active_index_read()
502 inst->params.read.by_uuid.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; in active_index_read()
503 inst->params.read.by_uuid.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; in active_index_read()
505 return bt_gatt_read(inst->conn, &inst->params.read); in active_index_read()
511 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, in control_point_subscribe_cb() local
515 LOG_DBG("conn %p att_err 0x%02x", (void *)inst->conn, att_err); in control_point_subscribe_cb()
521 err = active_index_read(inst); in control_point_subscribe_cb()
531 inst_cleanup(inst); in control_point_subscribe_cb()
536 static int control_point_subscribe(struct bt_has_client *inst, uint16_t value_handle, in control_point_subscribe() argument
541 LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle); in control_point_subscribe()
543 inst->control_point_subscription.notify = control_point_notify_cb; in control_point_subscribe()
544 inst->control_point_subscription.subscribe = control_point_subscribe_cb; in control_point_subscribe()
545 inst->control_point_subscription.value_handle = value_handle; in control_point_subscribe()
546 inst->control_point_subscription.ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE; in control_point_subscribe()
547 inst->control_point_subscription.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; in control_point_subscribe()
548 inst->control_point_subscription.disc_params = &inst->params.discover; in control_point_subscribe()
549 atomic_set_bit(inst->control_point_subscription.flags, BT_GATT_SUBSCRIBE_FLAG_VOLATILE); in control_point_subscribe()
552 inst->control_point_subscription.value = BT_GATT_CCC_INDICATE | BT_GATT_CCC_NOTIFY; in control_point_subscribe()
554 inst->control_point_subscription.value = BT_GATT_CCC_INDICATE; in control_point_subscribe()
557 err = bt_gatt_subscribe(inst->conn, &inst->control_point_subscription); in control_point_subscribe()
568 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.discover); in control_point_discover_cb() local
576 discover_complete(inst); in control_point_discover_cb()
582 err = control_point_subscribe(inst, chrc->value_handle, chrc->properties); in control_point_discover_cb()
587 inst_cleanup(inst); in control_point_discover_cb()
595 static int control_point_discover(struct bt_has_client *inst) in control_point_discover() argument
597 LOG_DBG("conn %p", (void *)inst->conn); in control_point_discover()
599 (void)memset(&inst->params.discover, 0, sizeof(inst->params.discover)); in control_point_discover()
601 (void)memcpy(&inst->params.uuid, BT_UUID_HAS_PRESET_CONTROL_POINT, in control_point_discover()
602 sizeof(inst->params.uuid)); in control_point_discover()
603 inst->params.discover.uuid = &inst->params.uuid.uuid; in control_point_discover()
604 inst->params.discover.func = control_point_discover_cb; in control_point_discover()
605 inst->params.discover.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; in control_point_discover()
606 inst->params.discover.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; in control_point_discover()
607 inst->params.discover.type = BT_GATT_DISCOVER_CHARACTERISTIC; in control_point_discover()
609 return bt_gatt_discover(inst->conn, &inst->params.discover); in control_point_discover()
612 static void features_update(struct bt_has_client *inst, const void *data, uint16_t len) in features_update() argument
618 inst->has.features = net_buf_simple_pull_u8(&buf); in features_update()
620 LOG_DBG("conn %p features 0x%02x", (void *)inst->conn, inst->has.features); in features_update()
626 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.read); in features_read_cb() local
636 features_update(inst, data, len); in features_read_cb()
640 discover_complete(inst); in features_read_cb()
644 err = control_point_discover(inst); in features_read_cb()
654 inst_cleanup(inst); in features_read_cb()
661 static int features_read(struct bt_has_client *inst, uint16_t value_handle) in features_read() argument
663 LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle); in features_read()
665 (void)memset(&inst->params.read, 0, sizeof(inst->params.read)); in features_read()
667 inst->params.read.func = features_read_cb; in features_read()
668 inst->params.read.handle_count = 1u; in features_read()
669 inst->params.read.single.handle = value_handle; in features_read()
670 inst->params.read.single.offset = 0u; in features_read()
672 return bt_gatt_read(inst->conn, &inst->params.read); in features_read()
678 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, in features_subscribe_cb() local
688 err = features_read(inst, inst->features_subscription.value_handle); in features_subscribe_cb()
698 inst_cleanup(inst); in features_subscribe_cb()
706 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, in features_notify_cb() local
728 features_update(inst, data, len); in features_notify_cb()
733 static int features_subscribe(struct bt_has_client *inst, uint16_t value_handle) in features_subscribe() argument
737 LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle); in features_subscribe()
739 inst->features_subscription.notify = features_notify_cb; in features_subscribe()
740 inst->features_subscription.subscribe = features_subscribe_cb; in features_subscribe()
741 inst->features_subscription.value_handle = value_handle; in features_subscribe()
742 inst->features_subscription.ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE; in features_subscribe()
743 inst->features_subscription.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; in features_subscribe()
744 inst->features_subscription.disc_params = &inst->params.discover; in features_subscribe()
745 inst->features_subscription.value = BT_GATT_CCC_NOTIFY; in features_subscribe()
746 atomic_set_bit(inst->features_subscription.flags, BT_GATT_SUBSCRIBE_FLAG_VOLATILE); in features_subscribe()
748 err = bt_gatt_subscribe(inst->conn, &inst->features_subscription); in features_subscribe()
759 struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.discover); in features_discover_cb() local
774 err = features_subscribe(inst, chrc->value_handle); in features_discover_cb()
780 err = features_read(inst, chrc->value_handle); in features_discover_cb()
791 inst_cleanup(inst); in features_discover_cb()
798 static int features_discover(struct bt_has_client *inst) in features_discover() argument
800 LOG_DBG("conn %p", (void *)inst->conn); in features_discover()
802 (void)memset(&inst->params.discover, 0, sizeof(inst->params.discover)); in features_discover()
804 (void)memcpy(&inst->params.uuid, BT_UUID_HAS_HEARING_AID_FEATURES, in features_discover()
805 sizeof(inst->params.uuid)); in features_discover()
806 inst->params.discover.uuid = &inst->params.uuid.uuid; in features_discover()
807 inst->params.discover.func = features_discover_cb; in features_discover()
808 inst->params.discover.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; in features_discover()
809 inst->params.discover.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; in features_discover()
810 inst->params.discover.type = BT_GATT_DISCOVER_CHARACTERISTIC; in features_discover()
812 return bt_gatt_discover(inst->conn, &inst->params.discover); in features_discover()
840 struct bt_has_client *inst; in bt_has_client_discover() local
849 inst = &clients[bt_conn_index(conn)]; in bt_has_client_discover()
851 if (atomic_test_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS) || in bt_has_client_discover()
852 atomic_test_and_set_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS)) { in bt_has_client_discover()
856 if (inst->conn) { in bt_has_client_discover()
860 inst->conn = bt_conn_ref(conn); in bt_has_client_discover()
862 err = features_discover(inst); in bt_has_client_discover()
864 atomic_clear_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS); in bt_has_client_discover()
872 struct bt_has_client *inst = HAS_INST(has); in bt_has_client_conn_get() local
874 *conn = bt_conn_ref(inst->conn); in bt_has_client_conn_get()
881 struct bt_has_client *inst = HAS_INST(has); in bt_has_client_presets_read() local
884 LOG_DBG("conn %p start_index 0x%02x count %d", (void *)inst->conn, start_index, count); in bt_has_client_presets_read()
886 if (!inst->conn) { in bt_has_client_presets_read()
890 if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS) || in bt_has_client_presets_read()
891 atomic_test_and_set_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS)) { in bt_has_client_presets_read()
903 err = read_presets_req(inst, start_index, count); in bt_has_client_presets_read()
905 atomic_clear_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS); in bt_has_client_presets_read()
913 struct bt_has_client *inst = HAS_INST(has); in bt_has_client_preset_set() local
916 LOG_DBG("conn %p index 0x%02x", (void *)inst->conn, index); in bt_has_client_preset_set()
918 if (!inst->conn) { in bt_has_client_preset_set()
926 if (sync && (inst->has.features & BT_HAS_FEAT_PRESET_SYNC_SUPP) == 0) { in bt_has_client_preset_set()
930 if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS) || in bt_has_client_preset_set()
931 atomic_test_and_set_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS)) { in bt_has_client_preset_set()
937 return preset_set(inst, opcode, index); in bt_has_client_preset_set()
942 struct bt_has_client *inst = HAS_INST(has); in bt_has_client_preset_next() local
945 LOG_DBG("conn %p sync %d", (void *)inst->conn, sync); in bt_has_client_preset_next()
947 if (!inst->conn) { in bt_has_client_preset_next()
951 if (sync && (inst->has.features & BT_HAS_FEAT_PRESET_SYNC_SUPP) == 0) { in bt_has_client_preset_next()
955 if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS) || in bt_has_client_preset_next()
956 atomic_test_and_set_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS)) { in bt_has_client_preset_next()
962 return preset_set_next_or_prev(inst, opcode); in bt_has_client_preset_next()
967 struct bt_has_client *inst = HAS_INST(has); in bt_has_client_preset_prev() local
970 LOG_DBG("conn %p sync %d", (void *)inst->conn, sync); in bt_has_client_preset_prev()
972 if (!inst->conn) { in bt_has_client_preset_prev()
976 if (sync && (inst->has.features & BT_HAS_FEAT_PRESET_SYNC_SUPP) == 0) { in bt_has_client_preset_prev()
980 if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS) || in bt_has_client_preset_prev()
981 atomic_test_and_set_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS)) { in bt_has_client_preset_prev()
987 return preset_set_next_or_prev(inst, opcode); in bt_has_client_preset_prev()
992 struct bt_has_client *inst = inst_by_conn(conn); in disconnected() local
994 if (!inst) { in disconnected()
998 if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS)) { in disconnected()
1002 inst_cleanup(inst); in disconnected()