Lines Matching refs:client
73 static int read_preset_response(struct has_client *client);
74 static int preset_list_changed(struct has_client *client);
75 static int preset_list_changed_generic_update_tail(struct has_client *client);
76 static int preset_list_changed_record_deleted_last(struct has_client *client);
261 static void client_free(struct has_client *client) in client_free() argument
267 (void)k_work_cancel_delayable(&client->notify_work); in client_free()
270 err = bt_conn_get_info(client->conn, &info); in client_free()
273 if (client->context != NULL && !bt_addr_le_is_bonded(info.id, info.le.dst)) { in client_free()
275 context_free(client->context); in client_free()
276 client->context = NULL; in client_free()
279 bt_conn_unref(client->conn); in client_free()
280 client->conn = NULL; in client_free()
286 struct has_client *client = NULL; in client_alloc() local
295 if (!client && has_client_list[i].conn == NULL) { in client_alloc()
296 client = &has_client_list[i]; in client_alloc()
300 __ASSERT(client, "failed to get client for conn %p", (void *)conn); in client_alloc()
302 memset(client, 0, sizeof(*client)); in client_alloc()
304 client->conn = bt_conn_ref(conn); in client_alloc()
307 k_work_init_delayable(&client->notify_work, notify_work_handler); in client_alloc()
317 client->context = context_find(info.le.dst); in client_alloc()
318 if (client->context == NULL) { in client_alloc()
319 client->context = context_alloc(info.le.dst); in client_alloc()
320 if (client->context == NULL) { in client_alloc()
324 client_free(client); in client_alloc()
332 return client; in client_alloc()
346 static void notify_work_reschedule(struct has_client *client, k_timeout_t delay) in notify_work_reschedule() argument
350 __ASSERT(client->conn, "Not connected"); in notify_work_reschedule()
352 if (k_work_delayable_remaining_get(&client->notify_work) > 0) { in notify_work_reschedule()
356 err = k_work_reschedule(&client->notify_work, delay); in notify_work_reschedule()
364 struct has_client *client; in security_changed() local
374 client = client_alloc(conn); in security_changed()
375 if (unlikely(!client)) { in security_changed()
380 ret = bt_conn_get_info(client->conn, &info); in security_changed()
390 if (atomic_get(client->context->flags) != 0) { in security_changed()
391 notify_work_reschedule(client, K_NO_WAIT); in security_changed()
397 struct has_client *client; in disconnected() local
401 client = client_find_by_conn(conn); in disconnected()
402 if (client) { in disconnected()
403 client_free(client); in disconnected()
410 struct has_client *client; in identity_resolved() local
414 client = client_find_by_conn(conn); in identity_resolved()
415 if (client == NULL) { in identity_resolved()
419 bt_addr_le_copy(&client->context->addr, identity); in identity_resolved()
431 struct has_client *client = CONTAINER_OF(dwork, struct has_client, notify_work); in notify_work_handler() local
435 atomic_test_and_clear_bit(client->context->flags, FLAG_FEATURES_CHANGED) && in notify_work_handler()
436 bt_gatt_is_subscribed(client->conn, hearing_aid_features_attr, BT_GATT_CCC_NOTIFY)) { in notify_work_handler()
437 err = bt_gatt_notify(client->conn, hearing_aid_features_attr, &has.features, in notify_work_handler()
440 atomic_set_bit(client->context->flags, FLAG_FEATURES_CHANGED); in notify_work_handler()
441 notify_work_reschedule(client, K_USEC(BT_AUDIO_NOTIFY_RETRY_DELAY_US)); in notify_work_handler()
448 if (atomic_test_and_clear_bit(client->context->flags, FLAG_PENDING_READ_PRESET_RESPONSE)) { in notify_work_handler()
449 err = read_preset_response(client); in notify_work_handler()
451 atomic_set_bit(client->context->flags, FLAG_PENDING_READ_PRESET_RESPONSE); in notify_work_handler()
452 notify_work_reschedule(client, K_USEC(BT_AUDIO_NOTIFY_RETRY_DELAY_US)); in notify_work_handler()
456 } else if (atomic_test_and_clear_bit(client->context->flags, FLAG_NOTIFY_PRESET_LIST)) { in notify_work_handler()
457 err = preset_list_changed(client); in notify_work_handler()
459 atomic_set_bit(client->context->flags, FLAG_NOTIFY_PRESET_LIST); in notify_work_handler()
460 notify_work_reschedule(client, K_USEC(BT_AUDIO_NOTIFY_RETRY_DELAY_US)); in notify_work_handler()
464 } else if (atomic_test_and_clear_bit(client->context->flags, in notify_work_handler()
466 err = preset_list_changed_generic_update_tail(client); in notify_work_handler()
468 atomic_set_bit(client->context->flags, in notify_work_handler()
470 notify_work_reschedule(client, K_USEC(BT_AUDIO_NOTIFY_RETRY_DELAY_US)); in notify_work_handler()
474 } else if (atomic_test_and_clear_bit(client->context->flags, in notify_work_handler()
476 err = preset_list_changed_record_deleted_last(client); in notify_work_handler()
478 atomic_set_bit(client->context->flags, in notify_work_handler()
480 notify_work_reschedule(client, K_USEC(BT_AUDIO_NOTIFY_RETRY_DELAY_US)); in notify_work_handler()
489 atomic_test_and_clear_bit(client->context->flags, FLAG_ACTIVE_INDEX_CHANGED) && in notify_work_handler()
490 bt_gatt_is_subscribed(client->conn, active_preset_index_attr, BT_GATT_CCC_NOTIFY)) { in notify_work_handler()
495 err = bt_gatt_notify(client->conn, active_preset_index_attr, in notify_work_handler()
498 atomic_set_bit(client->context->flags, FLAG_ACTIVE_INDEX_CHANGED); in notify_work_handler()
499 notify_work_reschedule(client, K_USEC(BT_AUDIO_NOTIFY_RETRY_DELAY_US)); in notify_work_handler()
506 static void notify(struct has_client *client, enum flag_internal flag) in notify() argument
508 if (client != NULL) { in notify()
509 atomic_set_bit(client->context->flags, flag); in notify()
510 notify_work_reschedule(client, K_NO_WAIT); in notify()
520 client = &has_client_list[i]; in notify()
522 if (client->conn == NULL) { in notify()
526 notify_work_reschedule(client, K_NO_WAIT); in notify()
729 struct has_client *client = client_find_by_conn(conn); in control_point_ntf_complete() local
734 if (client != NULL && atomic_get(client->context->flags) != 0) { in control_point_ntf_complete()
735 notify_work_reschedule(client, K_NO_WAIT); in control_point_ntf_complete()
751 static int control_point_send(struct has_client *client, struct net_buf_simple *buf) in control_point_send() argument
753 const uint16_t mtu_size = bt_gatt_get_mtu(client->conn); in control_point_send()
763 if (bt_eatt_count(client->conn) > 0 && in control_point_send()
764 bt_gatt_is_subscribed(client->conn, preset_control_point_attr, BT_GATT_CCC_NOTIFY)) { in control_point_send()
765 memset(&client->params.ntf, 0, sizeof(client->params.ntf)); in control_point_send()
766 client->params.ntf.attr = preset_control_point_attr; in control_point_send()
767 client->params.ntf.func = control_point_ntf_complete; in control_point_send()
768 client->params.ntf.data = buf->data; in control_point_send()
769 client->params.ntf.len = buf->len; in control_point_send()
771 return bt_gatt_notify_cb(client->conn, &client->params.ntf); in control_point_send()
775 if (bt_gatt_is_subscribed(client->conn, preset_control_point_attr, BT_GATT_CCC_INDICATE)) { in control_point_send()
776 memset(&client->params.ind, 0, sizeof(client->params.ind)); in control_point_send()
777 client->params.ind.attr = preset_control_point_attr; in control_point_send()
778 client->params.ind.func = control_point_ind_complete; in control_point_send()
779 client->params.ind.destroy = NULL; in control_point_send()
780 client->params.ind.data = buf->data; in control_point_send()
781 client->params.ind.len = buf->len; in control_point_send()
783 return bt_gatt_indicate(client->conn, &client->params.ind); in control_point_send()
795 struct has_client *client = NULL; in control_point_send_all() local
800 client = &has_client_list[j]; in control_point_send_all()
805 if (client == NULL || client->conn == NULL) { in control_point_send_all()
811 if (!bt_gatt_is_subscribed(client->conn, preset_control_point_attr, in control_point_send_all()
816 err = control_point_send(client, buf); in control_point_send_all()
826 static int bt_has_cp_read_preset_rsp(struct has_client *client, const struct has_preset *preset, in bt_has_cp_read_preset_rsp() argument
834 LOG_DBG("conn %p index 0x%02x prop 0x%02x %s is_last 0x%02x", (void *)client->conn, in bt_has_cp_read_preset_rsp()
845 return control_point_send(client, &buf); in bt_has_cp_read_preset_rsp()
860 static int bt_has_cp_generic_update(struct has_client *client, uint8_t prev_index, uint8_t index, in bt_has_cp_generic_update() argument
870 client, prev_index, index, properties, name, is_last); in bt_has_cp_generic_update()
880 if (client) { in bt_has_cp_generic_update()
881 return control_point_send(client, &buf); in bt_has_cp_generic_update()
961 static void update_last_preset_index_known(struct has_client *client, uint8_t index) in update_last_preset_index_known() argument
963 if (client != NULL && client->context != NULL && in update_last_preset_index_known()
964 client->context->last_preset_index_known != index) { in update_last_preset_index_known()
965 client->context->last_preset_index_known = index; in update_last_preset_index_known()
966 store_client_context(client->context); in update_last_preset_index_known()
971 client = &has_client_list[i]; in update_last_preset_index_known()
974 if (client->conn != NULL && client->context != NULL && in update_last_preset_index_known()
975 client->context->last_preset_index_known != index) { in update_last_preset_index_known()
976 client->context->last_preset_index_known = index; in update_last_preset_index_known()
977 store_client_context(client->context); in update_last_preset_index_known()
982 static int read_preset_response(struct has_client *client) in read_preset_response() argument
988 __ASSERT_NO_MSG(client != NULL); in read_preset_response()
990 preset_foreach(client->read_presets_req.start_index, BT_HAS_PRESET_INDEX_LAST, in read_preset_response()
994 return bt_has_cp_read_preset_rsp(client, NULL, BT_HAS_IS_LAST); in read_preset_response()
997 if (client->read_presets_req.num_presets > 1) { in read_preset_response()
1005 err = bt_has_cp_read_preset_rsp(client, preset, is_last); in read_preset_response()
1010 if (preset->index > client->context->last_preset_index_known) { in read_preset_response()
1011 update_last_preset_index_known(client, preset->index); in read_preset_response()
1015 client->read_presets_req.start_index = preset->index + 1; in read_preset_response()
1016 client->read_presets_req.num_presets--; in read_preset_response()
1018 atomic_set_bit(client->context->flags, FLAG_PENDING_READ_PRESET_RESPONSE); in read_preset_response()
1019 notify_work_reschedule(client, K_USEC(BT_AUDIO_NOTIFY_RETRY_DELAY_US)); in read_preset_response()
1025 static int bt_has_cp_preset_record_deleted(struct has_client *client, uint8_t index) in bt_has_cp_preset_record_deleted() argument
1030 LOG_DBG("client %p index 0x%02x", client, index); in bt_has_cp_preset_record_deleted()
1035 if (client != NULL) { in bt_has_cp_preset_record_deleted()
1036 return control_point_send(client, &buf); in bt_has_cp_preset_record_deleted()
1043 static int preset_list_changed_generic_update_tail(struct has_client *client) in preset_list_changed_generic_update_tail() argument
1048 .index = client->context->last_preset_index_known, in preset_list_changed_generic_update_tail()
1065 err = bt_has_cp_generic_update(client, prev ? prev->index : BT_HAS_PRESET_INDEX_NONE, in preset_list_changed_generic_update_tail()
1074 static int preset_list_changed_record_deleted_last(struct has_client *client) in preset_list_changed_record_deleted_last() argument
1079 err = bt_has_cp_preset_record_deleted(client, client->context->last_preset_index_known); in preset_list_changed_record_deleted_last()
1086 update_last_preset_index_known(client, last ? last->index : BT_HAS_PRESET_INDEX_NONE); in preset_list_changed_record_deleted_last()
1091 static int preset_list_changed(struct has_client *client) in preset_list_changed() argument
1100 atomic_set_bit(client->context->flags, in preset_list_changed()
1102 atomic_set_bit(client->context->flags, in preset_list_changed()
1104 notify_work_reschedule(client, K_USEC(BT_AUDIO_NOTIFY_RETRY_DELAY_US)); in preset_list_changed()
1109 preset_foreach(client->preset_changed_index_next, BT_HAS_PRESET_INDEX_LAST, in preset_list_changed()
1121 is_last = next == NULL && preset->index >= client->context->last_preset_index_known; in preset_list_changed()
1123 err = bt_has_cp_generic_update(client, preset_get_prev_index(preset), preset->index, in preset_list_changed()
1130 client->preset_changed_index_next = 0; in preset_list_changed()
1133 update_last_preset_index_known(client, preset->index); in preset_list_changed()
1146 atomic_set_bit(client->context->flags, in preset_list_changed()
1148 atomic_set_bit(client->context->flags, in preset_list_changed()
1151 client->preset_changed_index_next = preset->index + 1; in preset_list_changed()
1153 atomic_set_bit(client->context->flags, FLAG_NOTIFY_PRESET_LIST); in preset_list_changed()
1156 notify_work_reschedule(client, K_USEC(BT_AUDIO_NOTIFY_RETRY_DELAY_US)); in preset_list_changed()
1165 struct has_client *client; in handle_read_preset_req() local
1179 client = client_find_by_conn(conn); in handle_read_preset_req()
1180 if (client == NULL) { in handle_read_preset_req()
1196 if (atomic_test_bit(client->context->flags, FLAG_PENDING_READ_PRESET_RESPONSE)) { in handle_read_preset_req()
1201 client->read_presets_req.start_index = req->start_index; in handle_read_preset_req()
1202 client->read_presets_req.num_presets = req->num_presets; in handle_read_preset_req()
1204 notify(client, FLAG_PENDING_READ_PRESET_RESPONSE); in handle_read_preset_req()
1253 struct has_client *client; in handle_write_preset_name() local
1268 client = client_find_by_conn(conn); in handle_write_preset_name()
1269 if (!client) { in handle_write_preset_name()