Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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
220 /* Object Name */
221 char *name;
222
223 /* Object Type */
225
226 /* Object Size */
228
229 /* Object Properties */
231};
232
234enum {
237
240
243
246
249
252
255
258
261
264};
265
270#define BT_OTS_OACP_SET_FEAT_CREATE(feat) \
271 WRITE_BIT(feat, BT_OTS_OACP_FEAT_CREATE, 1)
272
277#define BT_OTS_OACP_SET_FEAT_DELETE(feat) \
278 WRITE_BIT(feat, BT_OTS_OACP_FEAT_DELETE, 1)
279
284#define BT_OTS_OACP_SET_FEAT_CHECKSUM(feat) \
285 WRITE_BIT(feat, BT_OTS_OACP_FEAT_CHECKSUM, 1)
286
291#define BT_OTS_OACP_SET_FEAT_EXECUTE(feat) \
292 WRITE_BIT(feat, BT_OTS_OACP_FEAT_EXECUTE, 1)
293
298#define BT_OTS_OACP_SET_FEAT_READ(feat) \
299 WRITE_BIT(feat, BT_OTS_OACP_FEAT_READ, 1)
300
305#define BT_OTS_OACP_SET_FEAT_WRITE(feat) \
306 WRITE_BIT(feat, BT_OTS_OACP_FEAT_WRITE, 1)
307
312#define BT_OTS_OACP_SET_FEAT_APPEND(feat) \
313 WRITE_BIT(feat, BT_OTS_OACP_FEAT_APPEND, 1)
314
319#define BT_OTS_OACP_SET_FEAT_TRUNCATE(feat) \
320 WRITE_BIT(feat, BT_OTS_OACP_FEAT_TRUNCATE, 1)
321
326#define BT_OTS_OACP_SET_FEAT_PATCH(feat) \
327 WRITE_BIT(feat, BT_OTS_OACP_FEAT_PATCH, 1)
328
333#define BT_OTS_OACP_SET_FEAT_ABORT(feat) \
334 WRITE_BIT(feat, BT_OTS_OACP_FEAT_ABORT, 1)
335
340#define BT_OTS_OACP_GET_FEAT_CREATE(feat) \
341 ((feat) & BIT(BT_OTS_OACP_FEAT_CREATE))
342
347#define BT_OTS_OACP_GET_FEAT_DELETE(feat) \
348 ((feat) & BIT(BT_OTS_OACP_FEAT_DELETE))
349
354#define BT_OTS_OACP_GET_FEAT_CHECKSUM(feat) \
355 ((feat) & BIT(BT_OTS_OACP_FEAT_CHECKSUM))
356
361#define BT_OTS_OACP_GET_FEAT_EXECUTE(feat) \
362 ((feat) & BIT(BT_OTS_OACP_FEAT_EXECUTE))
363
368#define BT_OTS_OACP_GET_FEAT_READ(feat) \
369 ((feat) & BIT(BT_OTS_OACP_FEAT_READ))
370
375#define BT_OTS_OACP_GET_FEAT_WRITE(feat) \
376 ((feat) & BIT(BT_OTS_OACP_FEAT_WRITE))
377
382#define BT_OTS_OACP_GET_FEAT_APPEND(feat) \
383 ((feat) & BIT(BT_OTS_OACP_FEAT_APPEND))
384
389#define BT_OTS_OACP_GET_FEAT_TRUNCATE(feat) \
390 ((feat) & BIT(BT_OTS_OACP_FEAT_TRUNCATE))
391
396#define BT_OTS_OACP_GET_FEAT_PATCH(feat) \
397 ((feat) & BIT(BT_OTS_OACP_FEAT_PATCH))
398
403#define BT_OTS_OACP_GET_FEAT_ABORT(feat) \
404 ((feat) & BIT(BT_OTS_OACP_FEAT_ABORT))
405
407enum {
410
413
416
419};
420
425#define BT_OTS_OLCP_SET_FEAT_GO_TO(feat) \
426 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_GO_TO, 1)
427
432#define BT_OTS_OLCP_SET_FEAT_ORDER(feat) \
433 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_ORDER, 1)
434
439#define BT_OTS_OLCP_SET_FEAT_NUM_REQ(feat) \
440 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_NUM_REQ, 1)
441
446#define BT_OTS_OLCP_SET_FEAT_CLEAR(feat) \
447 WRITE_BIT(feat, BT_OTS_OLCP_FEAT_CLEAR, 1)
448
453#define BT_OTS_OLCP_GET_FEAT_GO_TO(feat) \
454 ((feat) & BIT(BT_OTS_OLCP_FEAT_GO_TO))
455
460#define BT_OTS_OLCP_GET_FEAT_ORDER(feat) \
461 ((feat) & BIT(BT_OTS_OLCP_FEAT_ORDER))
462
467#define BT_OTS_OLCP_GET_FEAT_NUM_REQ(feat) \
468 ((feat) & BIT(BT_OTS_OLCP_FEAT_NUM_REQ))
469
474#define BT_OTS_OLCP_GET_FEAT_CLEAR(feat) \
475 ((feat) & BIT(BT_OTS_OLCP_FEAT_CLEAR))
476
479 /* OACP Features */
481
482 /* OLCP Features */
484} __packed;
485
487struct bt_ots;
488
490struct bt_ots_cb {
510 int (*obj_created)(struct bt_ots *ots, struct bt_conn *conn,
511 uint64_t id,
512 const struct bt_ots_obj_metadata *init);
513
525 void (*obj_deleted)(struct bt_ots *ots, struct bt_conn *conn,
526 uint64_t id);
527
536 void (*obj_selected)(struct bt_ots *ots, struct bt_conn *conn,
537 uint64_t id);
538
559 ssize_t (*obj_read)(struct bt_ots *ots, struct bt_conn *conn,
560 uint64_t id, void **data, size_t len,
561 off_t offset);
562
589 ssize_t (*obj_write)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id,
590 const void *data, size_t len, off_t offset,
591 size_t rem);
592
604 void (*obj_name_written)(struct bt_ots *ots, struct bt_conn *conn,
605 uint64_t id, const char *name);
606};
607
610 /* OTS features */
612
613 /* Callbacks */
614 struct bt_ots_cb *cb;
615};
616
628int bt_ots_obj_add(struct bt_ots *ots, struct bt_ots_obj_metadata *obj_init);
629
642int bt_ots_obj_delete(struct bt_ots *ots, uint64_t id);
643
653void *bt_ots_svc_decl_get(struct bt_ots *ots);
654
662int bt_ots_init(struct bt_ots *ots, struct bt_ots_init *ots_init);
663
668struct bt_ots *bt_ots_free_instance_get(void);
669
681static inline int bt_ots_obj_id_to_str(uint64_t obj_id, char *str, size_t len)
682{
683 uint8_t id[6];
684
685 sys_put_le48(obj_id, id);
686
687 return snprintk(str, len, "0x%02X%02X%02X%02X%02X%02X",
688 id[5], id[4], id[3], id[2], id[1], id[0]);
689}
690
691#ifdef __cplusplus
692}
693#endif
694
699#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.
void
Definition: eswifi_shell.c:15
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_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:681
struct bt_ots * bt_ots_free_instance_get(void)
Get a free instance of OTS from the pool.
int bt_ots_obj_add(struct bt_ots *ots, struct bt_ots_obj_metadata *obj_init)
Add an object to the OTS instance.
@ BT_OTS_OACP_FEAT_ABORT
Definition: ots.h:263
@ BT_OTS_OACP_FEAT_DELETE
Definition: ots.h:239
@ BT_OTS_OACP_FEAT_APPEND
Definition: ots.h:254
@ BT_OTS_OACP_FEAT_READ
Definition: ots.h:248
@ BT_OTS_OACP_FEAT_TRUNCATE
Definition: ots.h:257
@ BT_OTS_OACP_FEAT_CHECKSUM
Definition: ots.h:242
@ BT_OTS_OACP_FEAT_WRITE
Definition: ots.h:251
@ BT_OTS_OACP_FEAT_EXECUTE
Definition: ots.h:245
@ BT_OTS_OACP_FEAT_PATCH
Definition: ots.h:260
@ BT_OTS_OACP_FEAT_CREATE
Definition: ots.h:236
@ 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:412
@ BT_OTS_OLCP_FEAT_NUM_REQ
Definition: ots.h:415
@ BT_OTS_OLCP_FEAT_CLEAR
Definition: ots.h:418
@ BT_OTS_OLCP_FEAT_GO_TO
Definition: ots.h:409
__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:490
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:604
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:559
int(* obj_created)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id, const struct bt_ots_obj_metadata *init)
Object created callback.
Definition: ots.h:510
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:589
void(* obj_selected)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id)
Object selected callback.
Definition: ots.h:536
void(* obj_deleted)(struct bt_ots *ots, struct bt_conn *conn, uint64_t id)
Object deleted callback.
Definition: ots.h:525
Features of the OTS.
Definition: ots.h:478
uint32_t olcp
Definition: ots.h:483
uint32_t oacp
Definition: ots.h:480
Descriptor for OTS initialization.
Definition: ots.h:609
struct bt_ots_feat features
Definition: ots.h:611
struct bt_ots_cb * cb
Definition: ots.h:614
Descriptor for OTS object initialization.
Definition: ots.h:219
char * name
Definition: ots.h:221
uint32_t props
Definition: ots.h:230
struct bt_ots_obj_type type
Definition: ots.h:224
struct bt_ots_obj_size size
Definition: ots.h:227
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.