Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ots.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_OTS_H_
8#define ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_OTS_H_
9
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <zephyr/types.h>
25#include <sys/byteorder.h>
26#include <sys/types.h>
27#include <sys/util.h>
28#include <bluetooth/conn.h>
29#include <bluetooth/uuid.h>
30
32#define BT_OTS_OBJ_ID_SIZE 6
33
35#define BT_OTS_OBJ_ID_MIN 0x000000000100
36
38#define BT_OTS_OBJ_ID_MAX 0xFFFFFFFFFFFF
39
41#define OTS_OBJ_ID_DIR_LIST 0x000000000000
42
44#define BT_OTS_OBJ_ID_MASK BIT64_MASK(48)
45
47#define BT_OTS_OBJ_ID_STR_LEN 15
48
51 union {
52 /* Used to indicate UUID type */
53 struct bt_uuid uuid;
54
55 /* 16-bit UUID value */
57
58 /* 128-bit UUID value */
60 };
61};
62
64enum {
67
70
73
76
82
85
92
95};
96
101#define BT_OTS_OBJ_SET_PROP_DELETE(prop) \
102 WRITE_BIT(prop, BT_OTS_OBJ_PROP_DELETE, 1)
103
108#define BT_OTS_OBJ_SET_PROP_EXECUTE(prop) \
109 WRITE_BIT(prop, BT_OTS_OBJ_PROP_EXECUTE, 1)
110
115#define BT_OTS_OBJ_SET_PROP_READ(prop) \
116 WRITE_BIT(prop, BT_OTS_OBJ_PROP_READ, 1)
117
122#define BT_OTS_OBJ_SET_PROP_WRITE(prop) \
123 WRITE_BIT(prop, BT_OTS_OBJ_PROP_WRITE, 1)
124
129#define BT_OTS_OBJ_SET_PROP_APPEND(prop) \
130 WRITE_BIT(prop, BT_OTS_OBJ_PROP_APPEND, 1)
131
136#define BT_OTS_OBJ_SET_PROP_TRUNCATE(prop) \
137 WRITE_BIT(prop, BT_OTS_OBJ_PROP_TRUNCATE, 1)
138
143#define BT_OTS_OBJ_SET_PROP_PATCH(prop) \
144 WRITE_BIT(prop, BT_OTS_OBJ_PROP_PATCH, 1)
145
150#define BT_OTS_OBJ_SET_PROP_MARKED(prop) \
151 WRITE_BIT(prop, BT_OTS_OBJ_PROP_MARKED, 1)
152
157#define BT_OTS_OBJ_GET_PROP_DELETE(prop) \
158 ((prop) & BIT(BT_OTS_OBJ_PROP_DELETE))
159
164#define BT_OTS_OBJ_GET_PROP_EXECUTE(prop) \
165 ((prop) & BIT(BT_OTS_OBJ_PROP_EXECUTE))
166
171#define BT_OTS_OBJ_GET_PROP_READ(prop) \
172 ((prop) & BIT(BT_OTS_OBJ_PROP_READ))
173
178#define BT_OTS_OBJ_GET_PROP_WRITE(prop) \
179 ((prop) & BIT(BT_OTS_OBJ_PROP_WRITE))
180
185#define BT_OTS_OBJ_GET_PROP_APPEND(prop) \
186 ((prop) & BIT(BT_OTS_OBJ_PROP_APPEND))
187
192#define BT_OTS_OBJ_GET_PROP_TRUNCATE(prop) \
193 ((prop) & BIT(BT_OTS_OBJ_PROP_TRUNCATE))
194
199#define BT_OTS_OBJ_GET_PROP_PATCH(prop) \
200 ((prop) & BIT(BT_OTS_OBJ_PROP_PATCH))
201
206#define BT_OTS_OBJ_GET_PROP_MARKED(prop) \
207 ((prop) & BIT(BT_OTS_OBJ_PROP_MARKED))
208
211 /* Current Size */
213
214 /* Allocated Size */
216} __packed;
217
219enum {
222
225
228
231
234
237
240
243
246
249};
250
255#define BT_OTS_OACP_SET_FEAT_CREATE(feat) \
256 WRITE_BIT(feat, BT_OTS_OACP_FEAT_CREATE, 1)
257
262#define BT_OTS_OACP_SET_FEAT_DELETE(feat) \
263 WRITE_BIT(feat, BT_OTS_OACP_FEAT_DELETE, 1)
264
269#define BT_OTS_OACP_SET_FEAT_CHECKSUM(feat) \
270 WRITE_BIT(feat, BT_OTS_OACP_FEAT_CHECKSUM, 1)
271
276#define BT_OTS_OACP_SET_FEAT_EXECUTE(feat) \
277 WRITE_BIT(feat, BT_OTS_OACP_FEAT_EXECUTE, 1)
278
283#define BT_OTS_OACP_SET_FEAT_READ(feat) \
284 WRITE_BIT(feat, BT_OTS_OACP_FEAT_READ, 1)
285
290#define BT_OTS_OACP_SET_FEAT_WRITE(feat) \
291 WRITE_BIT(feat, BT_OTS_OACP_FEAT_WRITE, 1)
292
297#define BT_OTS_OACP_SET_FEAT_APPEND(feat) \
298 WRITE_BIT(feat, BT_OTS_OACP_FEAT_APPEND, 1)
299
304#define BT_OTS_OACP_SET_FEAT_TRUNCATE(feat) \
305 WRITE_BIT(feat, BT_OTS_OACP_FEAT_TRUNCATE, 1)
306
311#define BT_OTS_OACP_SET_FEAT_PATCH(feat) \
312 WRITE_BIT(feat, BT_OTS_OACP_FEAT_PATCH, 1)
313
318#define BT_OTS_OACP_SET_FEAT_ABORT(feat) \
319 WRITE_BIT(feat, BT_OTS_OACP_FEAT_ABORT, 1)
320
325#define BT_OTS_OACP_GET_FEAT_CREATE(feat) \
326 ((feat) & BIT(BT_OTS_OACP_FEAT_CREATE))
327
332#define BT_OTS_OACP_GET_FEAT_DELETE(feat) \
333 ((feat) & BIT(BT_OTS_OACP_FEAT_DELETE))
334
339#define BT_OTS_OACP_GET_FEAT_CHECKSUM(feat) \
340 ((feat) & BIT(BT_OTS_OACP_FEAT_CHECKSUM))
341
346#define BT_OTS_OACP_GET_FEAT_EXECUTE(feat) \
347 ((feat) & BIT(BT_OTS_OACP_FEAT_EXECUTE))
348
353#define BT_OTS_OACP_GET_FEAT_READ(feat) \
354 ((feat) & BIT(BT_OTS_OACP_FEAT_READ))
355
360#define BT_OTS_OACP_GET_FEAT_WRITE(feat) \
361 ((feat) & BIT(BT_OTS_OACP_FEAT_WRITE))
362
367#define BT_OTS_OACP_GET_FEAT_APPEND(feat) \
368 ((feat) & BIT(BT_OTS_OACP_FEAT_APPEND))
369
374#define BT_OTS_OACP_GET_FEAT_TRUNCATE(feat) \
375 ((feat) & BIT(BT_OTS_OACP_FEAT_TRUNCATE))
376
381#define BT_OTS_OACP_GET_FEAT_PATCH(feat) \
382 ((feat) & BIT(BT_OTS_OACP_FEAT_PATCH))
383
388#define BT_OTS_OACP_GET_FEAT_ABORT(feat) \
389 ((feat) & BIT(BT_OTS_OACP_FEAT_ABORT))
390
392enum {
395
398
401
404};
405
410#define BT_OTS_OLCP_SET_FEAT_GO_TO(feat) \
411 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_GO_TO, 1)
412
417#define BT_OTS_OLCP_SET_FEAT_ORDER(feat) \
418 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_ORDER, 1)
419
424#define BT_OTS_OLCP_SET_FEAT_NUM_REQ(feat) \
425 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_NUM_REQ, 1)
426
431#define BT_OTS_OLCP_SET_FEAT_CLEAR(feat) \
432 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_CLEAR, 1)
433
438#define BT_OTS_OLCP_GET_FEAT_GO_TO(feat) \
439 ((feat) & BIT(BT_OTS_OLCP_FEAT_GO_TO))
440
445#define BT_OTS_OLCP_GET_FEAT_ORDER(feat) \
446 ((feat) & BIT(BT_OTS_OLCP_FEAT_ORDER))
447
452#define BT_OTS_OLCP_GET_FEAT_NUM_REQ(feat) \
453 ((feat) & BIT(BT_OTS_OLCP_FEAT_NUM_REQ))
454
459#define BT_OTS_OLCP_GET_FEAT_CLEAR(feat) \
460 ((feat) & BIT(BT_OTS_OLCP_FEAT_CLEAR))
461
464 /* OACP Features */
466
467 /* OLCP Features */
469} __packed;
470
472struct bt_ots;
473
478
481};
482
499 char *name;
500
511
514};
515
517struct bt_ots_cb {
540 int (*obj_created)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id,
541 const struct bt_ots_obj_add_param *add_param,
542 struct bt_ots_obj_created_desc *created_desc);
543
565 int (*obj_deleted)(struct bt_ots *ots, struct bt_conn *conn,
566 uint64_t id);
567
576 void (*obj_selected)(struct bt_ots *ots, struct bt_conn *conn,
577 uint64_t id);
578
599 ssize_t (*obj_read)(struct bt_ots *ots, struct bt_conn *conn,
600 uint64_t id, void **data, size_t len,
601 off_t offset);
602
629 ssize_t (*obj_write)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id,
630 const void *data, size_t len, off_t offset,
631 size_t rem);
632
644 void (*obj_name_written)(struct bt_ots *ots, struct bt_conn *conn,
645 uint64_t id, const char *name);
646};
647
650 /* OTS features */
652
653 /* Callbacks */
654 struct bt_ots_cb *cb;
655};
656
669int bt_ots_obj_add(struct bt_ots *ots, const struct bt_ots_obj_add_param *param);
670
683int bt_ots_obj_delete(struct bt_ots *ots, uint64_t id);
684
694void *bt_ots_svc_decl_get(struct bt_ots *ots);
695
703int bt_ots_init(struct bt_ots *ots, struct bt_ots_init *ots_init);
704
709struct bt_ots *bt_ots_free_instance_get(void);
710
722static inline int bt_ots_obj_id_to_str(uint64_t obj_id, char *str, size_t len)
723{
724 uint8_t id[6];
725
726 sys_put_le48(obj_id, id);
727
728 return snprintk(str, len, "0x%02X%02X%02X%02X%02X%02X",
729 id[5], id[4], id[3], id[2], id[1], id[0]);
730}
731
732#ifdef __cplusplus
733}
734#endif
735
740#endif /* ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_OTS_H_ */
Byte order helpers.
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:346
Bluetooth connection handling.
int bt_ots_obj_delete(struct bt_ots *ots, uint64_t id)
Delete an object from the OTS instance.
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.
int bt_ots_init(struct bt_ots *ots, struct bt_ots_init *ots_init)
Initialize the OTS instance.
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:722
struct bt_ots * bt_ots_free_instance_get(void)
Get a free instance of OTS from the pool.
@ BT_OTS_OACP_FEAT_ABORT
Definition: ots.h:248
@ BT_OTS_OACP_FEAT_DELETE
Definition: ots.h:224
@ BT_OTS_OACP_FEAT_APPEND
Definition: ots.h:239
@ BT_OTS_OACP_FEAT_READ
Definition: ots.h:233
@ BT_OTS_OACP_FEAT_TRUNCATE
Definition: ots.h:242
@ BT_OTS_OACP_FEAT_CHECKSUM
Definition: ots.h:227
@ BT_OTS_OACP_FEAT_WRITE
Definition: ots.h:236
@ BT_OTS_OACP_FEAT_EXECUTE
Definition: ots.h:230
@ BT_OTS_OACP_FEAT_PATCH
Definition: ots.h:245
@ BT_OTS_OACP_FEAT_CREATE
Definition: ots.h:221
@ BT_OTS_OBJ_PROP_MARKED
Definition: ots.h:94
@ BT_OTS_OBJ_PROP_DELETE
Definition: ots.h:66
@ BT_OTS_OBJ_PROP_TRUNCATE
Definition: ots.h:84
@ BT_OTS_OBJ_PROP_APPEND
Bit 4 Appending data to this object is permitted.
Definition: ots.h:81
@ BT_OTS_OBJ_PROP_READ
Definition: ots.h:72
@ BT_OTS_OBJ_PROP_EXECUTE
Definition: ots.h:69
@ BT_OTS_OBJ_PROP_PATCH
Bit 6 Patching this object is permitted.
Definition: ots.h:91
@ BT_OTS_OBJ_PROP_WRITE
Definition: ots.h:75
@ BT_OTS_OLCP_FEAT_ORDER
Definition: ots.h:397
@ BT_OTS_OLCP_FEAT_NUM_REQ
Definition: ots.h:400
@ BT_OTS_OLCP_FEAT_CLEAR
Definition: ots.h:403
@ BT_OTS_OLCP_FEAT_GO_TO
Definition: ots.h:394
__SIZE_TYPE__ ssize_t
Definition: types.h:28
int snprintk(char *str, size_t size, const char *fmt,...)
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
OTS callback structure.
Definition: ots.h:517
void(* obj_name_written)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id, const char *name)
Object name written callback.
Definition: ots.h:644
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:540
int(* obj_deleted)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id)
Object deleted callback.
Definition: ots.h:565
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:599
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:629
void(* obj_selected)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id)
Object selected callback.
Definition: ots.h:576
Features of the OTS.
Definition: ots.h:463
uint32_t olcp
Definition: ots.h:468
uint32_t oacp
Definition: ots.h:465
Descriptor for OTS initialization.
Definition: ots.h:649
struct bt_ots_feat features
Definition: ots.h:651
struct bt_ots_cb * cb
Definition: ots.h:654
Descriptor for OTS object addition.
Definition: ots.h:475
uint32_t size
Object size to allocate.
Definition: ots.h:477
struct bt_ots_obj_type type
Object type.
Definition: ots.h:480
Descriptor for OTS created object.
Definition: ots.h:489
uint32_t props
Object properties.
Definition: ots.h:513
struct bt_ots_obj_size size
Object size.
Definition: ots.h:510
char * name
Object name.
Definition: ots.h:499
Descriptor for OTS Object Size parameter.
Definition: ots.h:210
uint32_t cur
Definition: ots.h:212
uint32_t alloc
Definition: ots.h:215
Type of an OTS object.
Definition: ots.h:50
struct bt_uuid uuid
Definition: ots.h:53
struct bt_uuid_16 uuid_16
Definition: ots.h:56
struct bt_uuid_128 uuid_128
Definition: ots.h:59
Definition: uuid.h:64
Definition: uuid.h:50
This is a 'tentative' type and should be used as a pointer only.
Definition: uuid.h:46
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
Misc utilities.
Bluetooth UUID handling.