7#ifndef ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_OTS_H_
8#define ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_OTS_H_
37#define BT_OTS_OBJ_ID_SIZE 6
40#define BT_OTS_OBJ_ID_MIN 0x000000000100ULL
43#define BT_OTS_OBJ_ID_MAX 0xFFFFFFFFFFFFULL
46#define OTS_OBJ_ID_DIR_LIST 0x000000000000ULL
49#define BT_OTS_OBJ_ID_MASK BIT64_MASK(48)
52#define BT_OTS_OBJ_ID_STR_LEN 15
106#define BT_OTS_OBJ_SET_PROP_DELETE(prop) \
107 WRITE_BIT(prop, BT_OTS_OBJ_PROP_DELETE, 1)
113#define BT_OTS_OBJ_SET_PROP_EXECUTE(prop) \
114 WRITE_BIT(prop, BT_OTS_OBJ_PROP_EXECUTE, 1)
120#define BT_OTS_OBJ_SET_PROP_READ(prop) \
121 WRITE_BIT(prop, BT_OTS_OBJ_PROP_READ, 1)
127#define BT_OTS_OBJ_SET_PROP_WRITE(prop) \
128 WRITE_BIT(prop, BT_OTS_OBJ_PROP_WRITE, 1)
134#define BT_OTS_OBJ_SET_PROP_APPEND(prop) \
135 WRITE_BIT(prop, BT_OTS_OBJ_PROP_APPEND, 1)
141#define BT_OTS_OBJ_SET_PROP_TRUNCATE(prop) \
142 WRITE_BIT(prop, BT_OTS_OBJ_PROP_TRUNCATE, 1)
148#define BT_OTS_OBJ_SET_PROP_PATCH(prop) \
149 WRITE_BIT(prop, BT_OTS_OBJ_PROP_PATCH, 1)
155#define BT_OTS_OBJ_SET_PROP_MARKED(prop) \
156 WRITE_BIT(prop, BT_OTS_OBJ_PROP_MARKED, 1)
162#define BT_OTS_OBJ_GET_PROP_DELETE(prop) \
163 ((prop) & BIT(BT_OTS_OBJ_PROP_DELETE))
169#define BT_OTS_OBJ_GET_PROP_EXECUTE(prop) \
170 ((prop) & BIT(BT_OTS_OBJ_PROP_EXECUTE))
176#define BT_OTS_OBJ_GET_PROP_READ(prop) \
177 ((prop) & BIT(BT_OTS_OBJ_PROP_READ))
183#define BT_OTS_OBJ_GET_PROP_WRITE(prop) \
184 ((prop) & BIT(BT_OTS_OBJ_PROP_WRITE))
190#define BT_OTS_OBJ_GET_PROP_APPEND(prop) \
191 ((prop) & BIT(BT_OTS_OBJ_PROP_APPEND))
197#define BT_OTS_OBJ_GET_PROP_TRUNCATE(prop) \
198 ((prop) & BIT(BT_OTS_OBJ_PROP_TRUNCATE))
204#define BT_OTS_OBJ_GET_PROP_PATCH(prop) \
205 ((prop) & BIT(BT_OTS_OBJ_PROP_PATCH))
211#define BT_OTS_OBJ_GET_PROP_MARKED(prop) \
212 ((prop) & BIT(BT_OTS_OBJ_PROP_MARKED))
269#define BT_OTS_OACP_SET_FEAT_CREATE(feat) \
270 WRITE_BIT(feat, BT_OTS_OACP_FEAT_CREATE, 1)
276#define BT_OTS_OACP_SET_FEAT_DELETE(feat) \
277 WRITE_BIT(feat, BT_OTS_OACP_FEAT_DELETE, 1)
283#define BT_OTS_OACP_SET_FEAT_CHECKSUM(feat) \
284 WRITE_BIT(feat, BT_OTS_OACP_FEAT_CHECKSUM, 1)
290#define BT_OTS_OACP_SET_FEAT_EXECUTE(feat) \
291 WRITE_BIT(feat, BT_OTS_OACP_FEAT_EXECUTE, 1)
297#define BT_OTS_OACP_SET_FEAT_READ(feat) \
298 WRITE_BIT(feat, BT_OTS_OACP_FEAT_READ, 1)
304#define BT_OTS_OACP_SET_FEAT_WRITE(feat) \
305 WRITE_BIT(feat, BT_OTS_OACP_FEAT_WRITE, 1)
311#define BT_OTS_OACP_SET_FEAT_APPEND(feat) \
312 WRITE_BIT(feat, BT_OTS_OACP_FEAT_APPEND, 1)
318#define BT_OTS_OACP_SET_FEAT_TRUNCATE(feat) \
319 WRITE_BIT(feat, BT_OTS_OACP_FEAT_TRUNCATE, 1)
325#define BT_OTS_OACP_SET_FEAT_PATCH(feat) \
326 WRITE_BIT(feat, BT_OTS_OACP_FEAT_PATCH, 1)
332#define BT_OTS_OACP_SET_FEAT_ABORT(feat) \
333 WRITE_BIT(feat, BT_OTS_OACP_FEAT_ABORT, 1)
339#define BT_OTS_OACP_GET_FEAT_CREATE(feat) \
340 ((feat) & BIT(BT_OTS_OACP_FEAT_CREATE))
346#define BT_OTS_OACP_GET_FEAT_DELETE(feat) \
347 ((feat) & BIT(BT_OTS_OACP_FEAT_DELETE))
353#define BT_OTS_OACP_GET_FEAT_CHECKSUM(feat) \
354 ((feat) & BIT(BT_OTS_OACP_FEAT_CHECKSUM))
360#define BT_OTS_OACP_GET_FEAT_EXECUTE(feat) \
361 ((feat) & BIT(BT_OTS_OACP_FEAT_EXECUTE))
367#define BT_OTS_OACP_GET_FEAT_READ(feat) \
368 ((feat) & BIT(BT_OTS_OACP_FEAT_READ))
374#define BT_OTS_OACP_GET_FEAT_WRITE(feat) \
375 ((feat) & BIT(BT_OTS_OACP_FEAT_WRITE))
381#define BT_OTS_OACP_GET_FEAT_APPEND(feat) \
382 ((feat) & BIT(BT_OTS_OACP_FEAT_APPEND))
388#define BT_OTS_OACP_GET_FEAT_TRUNCATE(feat) \
389 ((feat) & BIT(BT_OTS_OACP_FEAT_TRUNCATE))
395#define BT_OTS_OACP_GET_FEAT_PATCH(feat) \
396 ((feat) & BIT(BT_OTS_OACP_FEAT_PATCH))
402#define BT_OTS_OACP_GET_FEAT_ABORT(feat) \
403 ((feat) & BIT(BT_OTS_OACP_FEAT_ABORT))
424#define BT_OTS_OLCP_SET_FEAT_GO_TO(feat) \
425 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_GO_TO, 1)
431#define BT_OTS_OLCP_SET_FEAT_ORDER(feat) \
432 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_ORDER, 1)
438#define BT_OTS_OLCP_SET_FEAT_NUM_REQ(feat) \
439 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_NUM_REQ, 1)
445#define BT_OTS_OLCP_SET_FEAT_CLEAR(feat) \
446 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_CLEAR, 1)
452#define BT_OTS_OLCP_GET_FEAT_GO_TO(feat) \
453 ((feat) & BIT(BT_OTS_OLCP_FEAT_GO_TO))
459#define BT_OTS_OLCP_GET_FEAT_ORDER(feat) \
460 ((feat) & BIT(BT_OTS_OLCP_FEAT_ORDER))
466#define BT_OTS_OLCP_GET_FEAT_NUM_REQ(feat) \
467 ((feat) & BIT(BT_OTS_OLCP_FEAT_NUM_REQ))
473#define BT_OTS_OLCP_GET_FEAT_CLEAR(feat) \
474 ((feat) & BIT(BT_OTS_OLCP_FEAT_CLEAR))
514#define BT_OTS_DATE_TIME_FIELD_SIZE 7
523#if defined(CONFIG_BT_OTS)
528#if defined(CONFIG_BT_OTS_CLIENT)
531 char name_c[CONFIG_BT_OTS_OBJ_MAX_NAME_LEN + 1];
540#if defined(CONFIG_BT_OTS_CLIENT)
684 uint64_t id,
void **data,
size_t len,
714 const void *data,
size_t len,
off_t offset,
730 uint64_t id,
const char *cur_name,
const char *new_name);
748 off_t offset,
size_t len,
void **data);
815#define BT_OTS_CONTINUE 1
861 struct bt_conn *conn,
int err);
881 struct bt_conn *conn,
uint32_t offset,
898 struct bt_conn *conn,
int err,
911 struct bt_conn *conn,
size_t len);
974 struct bt_conn *conn);
985 struct bt_conn *conn,
996 struct bt_conn *conn);
1006 struct bt_conn *conn);
1016 struct bt_conn *conn);
1026 struct bt_conn *conn);
1040 struct bt_conn *conn,
1056 struct bt_conn *conn);
1075 const void *buf,
size_t len,
off_t offset,
1094 off_t offset,
size_t len);
1137 return snprintk(str, len,
"0x%02X%02X%02X%02X%02X%02X",
1138 id[5],
id[4],
id[3],
id[2],
id[1],
id[0]);
1160#if defined(CONFIG_BT_OTS_OACP_CHECKSUM_SUPPORT)
1161static inline uint32_t bt_ots_client_calc_checksum(
const uint8_t *data,
size_t len)
Bluetooth connection handling.
CRC computation function.
Generic Attribute Profile handling.
int bt_ots_init(struct bt_ots *ots, struct bt_ots_init_param *ots_init)
Initialize the OTS instance.
int bt_ots_client_select_id(struct bt_ots_client *otc_inst, struct bt_conn *conn, uint64_t obj_id)
Select an object by its Object ID.
int bt_ots_client_select_first(struct bt_ots_client *otc_inst, struct bt_conn *conn)
Select the first object.
int bt_ots_client_select_next(struct bt_ots_client *otc_inst, struct bt_conn *conn)
Select the next object.
void bt_ots_metadata_display(struct bt_ots_obj_metadata *metadata, uint16_t count)
Displays one or more object metadata as text with LOG_INF.
int bt_ots_obj_delete(struct bt_ots *ots, uint64_t id)
Delete an object from the OTS instance.
int bt_ots_client_select_last(struct bt_ots_client *otc_inst, struct bt_conn *conn)
Select the last object.
int bt_ots_client_read_object_data(struct bt_ots_client *otc_inst, struct bt_conn *conn)
Read the data of the current selected object.
int bt_ots_client_read_object_metadata(struct bt_ots_client *otc_inst, struct bt_conn *conn, uint8_t metadata)
Read the metadata of the current object.
int bt_ots_client_write_object_data(struct bt_ots_client *otc_inst, struct bt_conn *conn, const void *buf, size_t len, off_t offset, enum bt_ots_oacp_write_op_mode mode)
Write the data of the current selected object.
int bt_ots_client_get_object_checksum(struct bt_ots_client *otc_inst, struct bt_conn *conn, off_t offset, size_t len)
Get the checksum of the current selected object.
int(* bt_ots_client_dirlisting_cb)(struct bt_ots_obj_metadata *meta)
Directory listing object metadata callback.
Definition ots.h:1106
int bt_ots_client_unregister(uint8_t index)
Unregister an Object Transfer Service Instance.
int bt_ots_client_decode_dirlisting(uint8_t *data, uint16_t length, bt_ots_client_dirlisting_cb cb)
Decode Directory Listing object into object metadata.
void * bt_ots_svc_decl_get(struct bt_ots *ots)
Get the service declaration attribute.
int bt_ots_obj_add(struct bt_ots *ots, const struct bt_ots_obj_add_param *param)
Add an object to the OTS instance.
uint8_t bt_ots_client_indicate_handler(struct bt_conn *conn, struct bt_gatt_subscribe_params *params, const void *data, uint16_t length)
OTS Indicate Handler function.
int bt_ots_client_select_prev(struct bt_ots_client *otc_inst, struct bt_conn *conn)
Select the previous object.
static int bt_ots_obj_id_to_str(uint64_t obj_id, char *str, size_t len)
Converts binary OTS Object ID to string.
Definition ots.h:1131
int bt_ots_client_register(struct bt_ots_client *ots_inst)
Register an Object Transfer Service Instance.
bt_ots_oacp_write_op_mode
Definition ots.h:260
int bt_ots_client_read_feature(struct bt_ots_client *otc_inst, struct bt_conn *conn)
Read the OTS feature characteristic.
struct bt_ots * bt_ots_free_instance_get(void)
Get a free instance of OTS from the pool.
@ BT_OTS_OACP_FEAT_ABORT
Bit 9 OACP Abort Op Code Supported.
Definition ots.h:253
@ BT_OTS_OACP_FEAT_DELETE
Bit 1 OACP Delete Op Code Supported
Definition ots.h:229
@ BT_OTS_OACP_FEAT_APPEND
Bit 6 Appending Additional Data to Objects Supported
Definition ots.h:244
@ BT_OTS_OACP_FEAT_READ
Bit 4 OACP Read Op Code Supported.
Definition ots.h:238
@ BT_OTS_OACP_FEAT_TRUNCATE
Bit 7 Truncation of Objects Supported.
Definition ots.h:247
@ BT_OTS_OACP_FEAT_CHECKSUM
Bit 2 OACP Calculate Checksum Op Code Supported.
Definition ots.h:232
@ BT_OTS_OACP_FEAT_WRITE
Bit 5 OACP Write Op Code Supported.
Definition ots.h:241
@ BT_OTS_OACP_FEAT_EXECUTE
Bit 3 OACP Execute Op Code Supported.
Definition ots.h:235
@ BT_OTS_OACP_FEAT_PATCH
Bit 8 Patching of Objects Supported
Definition ots.h:250
@ BT_OTS_OACP_FEAT_CREATE
Bit 0 OACP Create Op Code Supported.
Definition ots.h:226
@ BT_OTS_METADATA_REQ_ALL
Request all object metadata.
Definition ots.h:502
@ BT_OTS_METADATA_REQ_MODIFIED
Request object last modified time.
Definition ots.h:496
@ BT_OTS_METADATA_REQ_ID
Request object ID.
Definition ots.h:498
@ BT_OTS_METADATA_REQ_CREATED
Request object first created time.
Definition ots.h:494
@ BT_OTS_METADATA_REQ_SIZE
Request object size.
Definition ots.h:492
@ BT_OTS_METADATA_REQ_NAME
Request object name.
Definition ots.h:488
@ BT_OTS_METADATA_REQ_PROPS
Request object properties.
Definition ots.h:500
@ BT_OTS_METADATA_REQ_TYPE
Request object type.
Definition ots.h:490
@ BT_OTS_OLCP_FEAT_ORDER
Bit 1 OLCP Order Op Code Supported.
Definition ots.h:411
@ BT_OTS_OLCP_FEAT_NUM_REQ
Bit 2 OLCP Request Number of Objects Op Code Supported.
Definition ots.h:414
@ BT_OTS_OLCP_FEAT_CLEAR
Bit 3 OLCP Clear Marking Op Code Supported.
Definition ots.h:417
@ BT_OTS_OLCP_FEAT_GO_TO
Bit 0 OLCP Go To Op Code Supported.
Definition ots.h:408
@ BT_OTS_OACP_WRITE_OP_MODE_NONE
Definition ots.h:261
@ BT_OTS_OACP_WRITE_OP_MODE_TRUNCATE
Definition ots.h:262
@ BT_OTS_OBJ_PROP_MARKED
Bit 7 This object is a marked object.
Definition ots.h:99
@ BT_OTS_OBJ_PROP_DELETE
Bit 0 Deletion of this object is permitted.
Definition ots.h:71
@ BT_OTS_OBJ_PROP_TRUNCATE
Bit 5 Truncation of this object is permitted.
Definition ots.h:89
@ BT_OTS_OBJ_PROP_APPEND
Bit 4 Appending data to this object is permitted.
Definition ots.h:86
@ BT_OTS_OBJ_PROP_READ
Bit 2 Reading this object is permitted.
Definition ots.h:77
@ BT_OTS_OBJ_PROP_EXECUTE
Bit 1 Execution of this object is permitted.
Definition ots.h:74
@ BT_OTS_OBJ_PROP_PATCH
Bit 6 Patching this object is permitted.
Definition ots.h:96
@ BT_OTS_OBJ_PROP_WRITE
Bit 3 Writing data to this object is permitted.
Definition ots.h:80
uint32_t crc32_ieee(const uint8_t *data, size_t len)
Generate IEEE conform CRC32 checksum.
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
__SIZE_TYPE__ ssize_t
Definition types.h:28
__INTPTR_TYPE__ off_t
Definition types.h:36
int snprintk(char *str, size_t size, const char *fmt,...)
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
GATT Discover Attributes parameters.
Definition gatt.h:1648
GATT Read parameters.
Definition gatt.h:1739
GATT Subscribe parameters.
Definition gatt.h:2037
GATT Write parameters.
Definition gatt.h:1844
OTS callback structure.
Definition ots.h:601
int(* obj_created)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id, const struct bt_ots_obj_add_param *add_param, struct bt_ots_obj_created_desc *created_desc)
Object created callback.
Definition ots.h:624
int(* obj_cal_checksum)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id, off_t offset, size_t len, void **data)
Object Calculate checksum callback.
Definition ots.h:747
int(* obj_deleted)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id)
Object deleted callback.
Definition ots.h:649
void(* obj_name_written)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id, const char *cur_name, const char *new_name)
Object name written callback.
Definition ots.h:729
ssize_t(* obj_read)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id, void **data, size_t len, off_t offset)
Object read callback.
Definition ots.h:683
ssize_t(* obj_write)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id, const void *data, size_t len, off_t offset, size_t rem)
Object write callback.
Definition ots.h:713
void(* obj_selected)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id)
Object selected callback.
Definition ots.h:660
OTS client callback structure.
Definition ots.h:848
void(* obj_data_written)(struct bt_ots_client *ots_inst, struct bt_conn *conn, size_t len)
Callback function for the data of the write object.
Definition ots.h:910
void(* obj_metadata_read)(struct bt_ots_client *ots_inst, struct bt_conn *conn, int err, uint8_t metadata_read)
Callback function for metadata of the selected object.
Definition ots.h:897
void(* obj_selected)(struct bt_ots_client *ots_inst, struct bt_conn *conn, int err)
Callback function when a new object is selected.
Definition ots.h:860
void(* obj_checksum_calculated)(struct bt_ots_client *ots_inst, struct bt_conn *conn, int err, uint32_t checksum)
Callback function when checksum indication is received.
Definition ots.h:924
int(* obj_data_read)(struct bt_ots_client *ots_inst, struct bt_conn *conn, uint32_t offset, uint32_t len, uint8_t *data_p, bool is_complete)
Callback function for the data of the selected object.
Definition ots.h:880
OTS client instance.
Definition ots.h:819
struct bt_gatt_write_params write_params
Definition ots.h:838
uint16_t start_handle
Definition ots.h:820
struct bt_ots_client_cb * cb
Definition ots.h:840
uint16_t feature_handle
Definition ots.h:822
uint16_t obj_id_handle
Definition ots.h:829
struct bt_gatt_subscribe_params olcp_sub_params
Definition ots.h:835
uint16_t obj_size_handle
Definition ots.h:825
uint16_t obj_modified_handle
Definition ots.h:828
struct bt_gatt_read_params read_proc
Definition ots.h:839
struct bt_gatt_discover_params oacp_sub_disc_params
Definition ots.h:834
struct bt_ots_feat features
Definition ots.h:842
struct bt_gatt_subscribe_params oacp_sub_params
Definition ots.h:833
uint16_t end_handle
Definition ots.h:821
uint16_t olcp_handle
Definition ots.h:831
uint16_t obj_properties_handle
Definition ots.h:826
struct bt_ots_obj_metadata cur_object
Definition ots.h:844
struct bt_gatt_discover_params olcp_sub_disc_params
Definition ots.h:836
uint16_t oacp_handle
Definition ots.h:830
uint16_t obj_type_handle
Definition ots.h:824
uint16_t obj_name_handle
Definition ots.h:823
uint16_t obj_created_handle
Definition ots.h:827
Date and Time structure.
Definition ots.h:506
uint8_t day
Definition ots.h:509
uint8_t seconds
Definition ots.h:512
uint8_t month
Definition ots.h:508
uint8_t minutes
Definition ots.h:511
uint8_t hours
Definition ots.h:510
uint16_t year
Definition ots.h:507
Features of the OTS.
Definition ots.h:477
uint32_t olcp
Definition ots.h:482
uint32_t oacp
Definition ots.h:479
Descriptor for OTS initialization.
Definition ots.h:752
struct bt_ots_cb * cb
Definition ots.h:757
struct bt_ots_feat features
Definition ots.h:754
Descriptor for OTS object addition.
Definition ots.h:559
uint32_t size
Object size to allocate.
Definition ots.h:561
struct bt_ots_obj_type type
Object type.
Definition ots.h:564
Descriptor for OTS created object.
Definition ots.h:573
uint32_t props
Object properties.
Definition ots.h:597
struct bt_ots_obj_size size
Object size.
Definition ots.h:594
char * name
Object name.
Definition ots.h:583
Descriptor for OTS Object Size parameter.
Definition ots.h:215
uint32_t cur
Current Size.
Definition ots.h:217
uint32_t alloc
Allocated Size.
Definition ots.h:220
Type of an OTS object.
Definition ots.h:55
struct bt_uuid uuid
Definition ots.h:58
struct bt_uuid_16 uuid_16
Definition ots.h:61
struct bt_uuid_128 uuid_128
Definition ots.h:64
This is a 'tentative' type and should be used as a pointer only.
Definition uuid.h:49
static void sys_put_le48(uint64_t val, uint8_t dst[6])
Put a 48-bit integer as little-endian to arbitrary location.
Definition byteorder.h:470