Lines Matching +full:instance +full:- +full:id

4  * SPDX-License-Identifier: Apache-2.0
124 struct bt_ots *ots = (struct bt_ots *) attr->user_data; in ots_feature_read()
128 return bt_gatt_attr_read(conn, attr, buf, len, offset, &ots->features, in ots_feature_read()
129 sizeof(ots->features)); in ots_feature_read()
136 struct bt_ots *ots = (struct bt_ots *) attr->user_data; in ots_obj_name_read()
140 if (!ots->cur_obj) { in ots_obj_name_read()
146 ots->cur_obj->metadata.name, in ots_obj_name_read()
147 strlen(ots->cur_obj->metadata.name)); in ots_obj_name_read()
156 struct bt_ots *ots = (struct bt_ots *) attr->user_data; in ots_obj_name_write()
163 if (!ots->cur_obj) { in ots_obj_name_write()
169 ots->cur_obj->id == OTS_OBJ_ID_DIR_LIST) { in ots_obj_name_write()
188 rc = bt_gatt_ots_obj_manager_first_obj_get(ots->obj_manager, &obj); in ots_obj_name_write()
190 if (obj != ots->cur_obj && strcmp(name, obj->metadata.name) == 0) { in ots_obj_name_write()
194 rc = bt_gatt_ots_obj_manager_next_obj_get(ots->obj_manager, obj, &obj); in ots_obj_name_write()
198 if (ots->cb->obj_name_written) { in ots_obj_name_write()
199 ots->cb->obj_name_written(ots, conn, ots->cur_obj->id, in ots_obj_name_write()
200 ots->cur_obj->metadata.name, name); in ots_obj_name_write()
203 strcpy(ots->cur_obj->metadata.name, name); in ots_obj_name_write()
213 struct bt_ots *ots = (struct bt_ots *) attr->user_data; in ots_obj_type_read()
218 if (!ots->cur_obj) { in ots_obj_type_read()
223 obj_meta = &ots->cur_obj->metadata; in ots_obj_type_read()
224 switch (obj_meta->type.uuid.type) { in ots_obj_type_read()
227 &obj_meta->type.uuid_16.val, in ots_obj_type_read()
228 sizeof(obj_meta->type.uuid_16.val)); in ots_obj_type_read()
231 obj_meta->type.uuid_128.val, in ots_obj_type_read()
232 sizeof(obj_meta->type.uuid_128.val)); in ots_obj_type_read()
234 return -EINVAL; in ots_obj_type_read()
242 struct bt_ots *ots = (struct bt_ots *) attr->user_data; in ots_obj_size_read()
246 if (!ots->cur_obj) { in ots_obj_size_read()
252 &ots->cur_obj->metadata.size, in ots_obj_size_read()
253 sizeof(ots->cur_obj->metadata.size)); in ots_obj_size_read()
260 struct bt_ots *ots = (struct bt_ots *) attr->user_data; in ots_obj_id_read()
261 uint8_t id[BT_OTS_OBJ_ID_SIZE]; in ots_obj_id_read() local
264 LOG_DBG("OTS Object ID GATT Read Operation"); in ots_obj_id_read()
266 if (!ots->cur_obj) { in ots_obj_id_read()
271 sys_put_le48(ots->cur_obj->id, id); in ots_obj_id_read()
273 bt_ots_obj_id_to_str(ots->cur_obj->id, id_str, in ots_obj_id_read()
275 LOG_DBG("Current Object ID: %s", id_str); in ots_obj_id_read()
277 return bt_gatt_attr_read(conn, attr, buf, len, offset, id, sizeof(id)); in ots_obj_id_read()
284 struct bt_ots *ots = (struct bt_ots *) attr->user_data; in ots_obj_prop_read()
288 if (!ots->cur_obj) { in ots_obj_prop_read()
294 &ots->cur_obj->metadata.props, in ots_obj_prop_read()
295 sizeof(ots->cur_obj->metadata.props)); in ots_obj_prop_read()
306 if (IS_ENABLED(CONFIG_BT_OTS_DIR_LIST_OBJ) && ots->dir_list && in bt_ots_obj_add_internal()
307 !bt_ots_dir_list_is_idle(ots->dir_list)) { in bt_ots_obj_add_internal()
309 return -EBUSY; in bt_ots_obj_add_internal()
312 err = bt_gatt_ots_obj_manager_obj_add(ots->obj_manager, &new_obj); in bt_ots_obj_add_internal()
320 if (ots->cb->obj_created) { in bt_ots_obj_add_internal()
321 err = ots->cb->obj_created(ots, conn, new_obj->id, param, &created_desc); in bt_ots_obj_add_internal()
329 if (!ots_obj_validate_prop_against_oacp(created_desc.props, ots->features.oacp)) { in bt_ots_obj_add_internal()
331 created_desc.props, ots->features.oacp); in bt_ots_obj_add_internal()
333 (void)bt_ots_obj_delete(ots, new_obj->id); in bt_ots_obj_add_internal()
334 return -ECANCELED; in bt_ots_obj_add_internal()
340 (void)bt_ots_obj_delete(ots, new_obj->id); in bt_ots_obj_add_internal()
341 return -ECANCELED; in bt_ots_obj_add_internal()
344 if (created_desc.size.alloc < param->size) { in bt_ots_obj_add_internal()
347 (void)bt_ots_obj_delete(ots, new_obj->id); in bt_ots_obj_add_internal()
348 return -ECANCELED; in bt_ots_obj_add_internal()
352 new_obj->metadata.type = param->type; in bt_ots_obj_add_internal()
353 new_obj->metadata.name = created_desc.name; in bt_ots_obj_add_internal()
354 new_obj->metadata.size = created_desc.size; in bt_ots_obj_add_internal()
355 new_obj->metadata.props = created_desc.props; in bt_ots_obj_add_internal()
375 name_len = strlen(obj->metadata.name); in bt_ots_obj_add()
379 (void)bt_ots_obj_delete(ots, obj->id); in bt_ots_obj_add()
380 return -ECANCELED; in bt_ots_obj_add()
383 if (obj->metadata.size.cur > param->size) { in bt_ots_obj_add()
386 (void)bt_ots_obj_delete(ots, obj->id); in bt_ots_obj_add()
387 return -ECANCELED; in bt_ots_obj_add()
390 return obj->id; in bt_ots_obj_add()
393 int bt_ots_obj_delete(struct bt_ots *ots, uint64_t id) in bt_ots_obj_delete() argument
398 CHECKIF(!BT_OTS_VALID_OBJ_ID(id)) { in bt_ots_obj_delete()
399 LOG_DBG("Invalid object ID 0x%016llx", id); in bt_ots_obj_delete()
401 return -EINVAL; in bt_ots_obj_delete()
404 err = bt_gatt_ots_obj_manager_obj_get(ots->obj_manager, id, &obj); in bt_ots_obj_delete()
409 if (obj->state.type != BT_GATT_OTS_OBJECT_IDLE_STATE) { in bt_ots_obj_delete()
410 return -EBUSY; in bt_ots_obj_delete()
413 if (IS_ENABLED(CONFIG_BT_OTS_DIR_LIST_OBJ) && ots->dir_list && in bt_ots_obj_delete()
414 !bt_ots_dir_list_is_idle(ots->dir_list)) { in bt_ots_obj_delete()
416 return -EBUSY; in bt_ots_obj_delete()
419 if (ots->cb->obj_deleted) { in bt_ots_obj_delete()
420 err = ots->cb->obj_deleted(ots, NULL, obj->id); in bt_ots_obj_delete()
431 if (ots->cur_obj == obj) { in bt_ots_obj_delete()
432 ots->cur_obj = NULL; in bt_ots_obj_delete()
441 return ots->service->attrs; in bt_ots_svc_decl_get()
450 bt_gatt_indicate(NULL, &ots->oacp_ind.params); in oacp_indicate_work_handler()
458 bt_gatt_indicate(NULL, &ots->olcp_ind.params); in olcp_indicate_work_handler()
466 if (!ots || !ots_init || !ots_init->cb) { in bt_ots_init()
467 return -EINVAL; in bt_ots_init()
470 __ASSERT(ots_init->cb->obj_created || !BT_OTS_OACP_GET_FEAT_CREATE(ots_init->features.oacp), in bt_ots_init()
472 __ASSERT(ots_init->cb->obj_deleted || !BT_OTS_OACP_GET_FEAT_DELETE(ots_init->features.oacp), in bt_ots_init()
475 __ASSERT(ots_init->cb->obj_cal_checksum || in bt_ots_init()
476 !BT_OTS_OACP_GET_FEAT_CHECKSUM(ots_init->features.oacp), in bt_ots_init()
479 __ASSERT(ots_init->cb->obj_read || !BT_OTS_OACP_GET_FEAT_READ(ots_init->features.oacp), in bt_ots_init()
481 __ASSERT(ots_init->cb->obj_write || !BT_OTS_OACP_GET_FEAT_WRITE(ots_init->features.oacp), in bt_ots_init()
485 ots->cb = ots_init->cb; in bt_ots_init()
488 if (ots_init->features.oacp & (~((uint32_t) OACP_FEAT))) { in bt_ots_init()
489 return -ENOTSUP; in bt_ots_init()
492 __ASSERT(!BT_OTS_OACP_GET_FEAT_CREATE(ots_init->features.oacp) || in bt_ots_init()
493 BT_OTS_OACP_GET_FEAT_WRITE(ots_init->features.oacp), in bt_ots_init()
496 ots->features.oacp = ots_init->features.oacp; in bt_ots_init()
497 LOG_DBG("OACP features: 0x%04X", ots->features.oacp); in bt_ots_init()
500 if (ots_init->features.olcp & (~((uint32_t) OLCP_FEAT))) { in bt_ots_init()
501 return -ENOTSUP; in bt_ots_init()
503 ots->features.olcp = ots_init->features.olcp; in bt_ots_init()
504 LOG_DBG("OLCP features: 0x%04X", ots->features.olcp); in bt_ots_init()
507 err = bt_gatt_ots_l2cap_register(&ots->l2cap); in bt_ots_init()
512 err = bt_gatt_service_register(ots->service); in bt_ots_init()
514 bt_gatt_ots_l2cap_unregister(&ots->l2cap); in bt_ots_init()
520 bt_ots_dir_list_init(&ots->dir_list, ots->obj_manager); in bt_ots_init()
523 k_work_init(&ots->oacp_ind.work, oacp_indicate_work_handler); in bt_ots_init()
524 k_work_init(&ots->olcp_ind.work, olcp_indicate_work_handler); in bt_ots_init()
601 err = bt_gatt_ots_obj_manager_first_obj_get(ots->obj_manager, &next_obj); in ots_delete_empty_name_objects()
608 err = bt_gatt_ots_obj_manager_next_obj_get(ots->obj_manager, obj, &next_obj); in ots_delete_empty_name_objects()
610 if (strlen(obj->metadata.name) == 0) { in ots_delete_empty_name_objects()
611 bt_ots_obj_id_to_str(obj->id, id_str, sizeof(id_str)); in ots_delete_empty_name_objects()
612 LOG_DBG("Deleting object with %s ID due to empty name", id_str); in ots_delete_empty_name_objects()
614 if (ots->cb && ots->cb->obj_deleted) { in ots_delete_empty_name_objects()
615 ots->cb->obj_deleted(ots, conn, obj->id); in ots_delete_empty_name_objects()
619 LOG_ERR("Failed to remove object with %s ID from object manager", in ots_delete_empty_name_objects()
629 struct bt_ots *instance; in ots_conn_disconnected() local
631 for (instance = BT_GATT_OTS_INSTANCE_LIST_START, index = 0; in ots_conn_disconnected()
633 instance++, index++) { in ots_conn_disconnected()
635 LOG_DBG("Processing disconnect for OTS instance %u", index); in ots_conn_disconnected()
637 if (instance->cur_obj != NULL) { in ots_conn_disconnected()
638 __ASSERT(instance->cur_obj->state.type == BT_GATT_OTS_OBJECT_IDLE_STATE, in ots_conn_disconnected()
641 instance->cur_obj = NULL; in ots_conn_disconnected()
644 ots_delete_empty_name_objects(instance, conn); in ots_conn_disconnected()
664 struct bt_ots *instance; in bt_gatt_ots_instances_prepare() local
666 for (instance = BT_GATT_OTS_INSTANCE_LIST_START, index = 0; in bt_gatt_ots_instances_prepare()
667 instance != BT_GATT_OTS_INSTANCE_LIST_END; in bt_gatt_ots_instances_prepare()
668 instance++, index++) { in bt_gatt_ots_instances_prepare()
669 /* Assign an object pool to the OTS instance. */ in bt_gatt_ots_instances_prepare()
670 instance->obj_manager = bt_gatt_ots_obj_manager_assign(); in bt_gatt_ots_instances_prepare()
672 if (!instance->obj_manager) { in bt_gatt_ots_instances_prepare()
673 LOG_ERR("OTS Object manager instance not available"); in bt_gatt_ots_instances_prepare()
674 return -ENOMEM; in bt_gatt_ots_instances_prepare()
678 instance->service = &BT_GATT_OTS_SERVICE_LIST_START[index]; in bt_gatt_ots_instances_prepare()
683 instance->oacp_ind.ccc.cfg_changed = in bt_gatt_ots_instances_prepare()
685 instance->olcp_ind.ccc.cfg_changed = in bt_gatt_ots_instances_prepare()