Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
inst.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Croxel, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_NUS_INST_H_
8#define ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_NUS_INST_H_
9
12#include <zephyr/sys/slist.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
25
26#define BT_UUID_NUS_SERVICE BT_UUID_DECLARE_128(BT_UUID_NUS_SRV_VAL)
27#define BT_UUID_NUS_TX_CHAR BT_UUID_DECLARE_128(BT_UUID_NUS_TX_CHAR_VAL)
28#define BT_UUID_NUS_RX_CHAR BT_UUID_DECLARE_128(BT_UUID_NUS_RX_CHAR_VAL)
29
34#define BT_NUS_PERM_WRITE \
35 COND_CODE_1(IS_ENABLED(CONFIG_BT_ZEPHYR_NUS_SECURITY_AUTHEN), (BT_GATT_PERM_WRITE_AUTHEN), \
36 (COND_CODE_1(IS_ENABLED(CONFIG_BT_ZEPHYR_NUS_SECURITY_ENCRYPT), \
37 (BT_GATT_PERM_WRITE_ENCRYPT), (BT_GATT_PERM_WRITE))))
38
43#define BT_NUS_PERM_NOTIFY \
44 COND_CODE_1(IS_ENABLED(CONFIG_BT_ZEPHYR_NUS_SECURITY_AUTHEN), (BT_GATT_PERM_READ_AUTHEN), \
45 (COND_CODE_1(IS_ENABLED(CONFIG_BT_ZEPHYR_NUS_SECURITY_ENCRYPT), \
46 (BT_GATT_PERM_READ_ENCRYPT), (BT_GATT_PERM_NONE))))
47
49ssize_t nus_bt_chr_write(struct bt_conn *conn, const struct bt_gatt_attr *attr,
50 const void *buf, uint16_t len, uint16_t offset, uint8_t flags);
51void nus_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value);
52
53#define Z_INTERNAL_BT_NUS_INST_DEFINE(_name) \
54 \
55BT_GATT_SERVICE_DEFINE(_name##_svc, \
56 BT_GATT_PRIMARY_SERVICE(BT_UUID_NUS_SERVICE), \
57 BT_GATT_CHARACTERISTIC(BT_UUID_NUS_TX_CHAR, \
58 BT_GATT_CHRC_NOTIFY, \
59 BT_NUS_PERM_NOTIFY, \
60 NULL, NULL, NULL), \
61 BT_GATT_CCC(nus_ccc_cfg_changed, \
62 BT_GATT_PERM_READ | BT_NUS_PERM_NOTIFY | \
63 BT_NUS_PERM_WRITE), \
64 BT_GATT_CHARACTERISTIC(BT_UUID_NUS_RX_CHAR, \
65 BT_GATT_CHRC_WRITE | \
66 BT_GATT_CHRC_WRITE_WITHOUT_RESP, \
67 BT_NUS_PERM_WRITE, \
68 NULL, nus_bt_chr_write, NULL), \
69); \
70 \
71sys_slist_t _name##_cbs = SYS_SLIST_STATIC_INIT(&_name##_cbs); \
72 \
73STRUCT_SECTION_ITERABLE(bt_nus_inst, _name) = { \
74 .svc = &_name##_svc, \
75 .cbs = &_name##_cbs, \
76}
77
78#ifdef __cplusplus
79}
80#endif
81
82#endif /* ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_NUS_INST_H_ */
Generic Attribute Profile handling.
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:54
ssize_t nus_bt_chr_write(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
Required as the service may be instantiated outside of the module.
void nus_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
__SIZE_TYPE__ ssize_t
Definition types.h:28
flags
Definition parser.h:86
Header file for the single-linked list API.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Opaque type representing a connection to a remote device.
GATT Attribute.
Definition gatt.h:262
Static GATT Service structure.
Definition gatt.h:354
Definition inst.h:18
const struct bt_gatt_service_static * svc
Pointer to the NUS Service Instance.
Definition inst.h:20
sys_slist_t * cbs
List of subscribers to invoke callbacks on asynchronous events.
Definition inst.h:23
Iterable sections helpers.