17#include <zephyr/kernel.h>
18#include <zephyr/types.h>
19#include <zephyr/bluetooth/conn.h>
20#include <zephyr/bluetooth/uuid.h>
21#include <zephyr/bluetooth/gatt.h>
28#define BT_UUID_NSMS_VAL \
29 BT_UUID_128_ENCODE(0x57a70000, 0x9350, 0x11ed, 0xa1eb, 0x0242ac120002)
32#define BT_UUID_NSMS_STATUS_VAL \
33 BT_UUID_128_ENCODE(0x57a70001, 0x9350, 0x11ed, 0xa1eb, 0x0242ac120002)
35#define BT_UUID_NSMS_SERVICE BT_UUID_DECLARE_128(BT_UUID_NSMS_VAL)
36#define BT_UUID_NSMS_STATUS BT_UUID_DECLARE_128(BT_UUID_NSMS_STATUS_VAL)
66 struct bt_gatt_attr
const *attr,
67 void *buf, uint16_t len, uint16_t offset);
69#define BT_NSMS_SECURITY_LEVEL_NONE 0
70#define BT_NSMS_SECURITY_LEVEL_ENCRYPT 1
71#define BT_NSMS_SECURITY_LEVEL_AUTHEN 2
73#define _BT_NSMS_CH_READ_PERM(_slevel) ((_slevel == BT_NSMS_SECURITY_LEVEL_AUTHEN) ? \
74 (BT_GATT_PERM_READ_AUTHEN) : \
75 (_slevel == BT_NSMS_SECURITY_LEVEL_ENCRYPT) ? \
76 (BT_GATT_PERM_READ_ENCRYPT) : \
80#define _BT_NSMS_CH_WRITE_PERM(_slevel) ((_slevel == BT_NSMS_SECURITY_LEVEL_AUTHEN) ? \
81 (BT_GATT_PERM_WRITE_AUTHEN) : \
82 (_slevel == BT_NSMS_SECURITY_LEVEL_ENCRYPT) ? \
83 (BT_GATT_PERM_WRITE_ENCRYPT) : \
84 (BT_GATT_PERM_WRITE) \
91#define BT_NSMS_SERVICE_DEF(_name, ...) \
92 BT_GATT_SERVICE_DEFINE(_name, __VA_ARGS__)
109#define BT_NSMS_DEF(_nsms, _name, _slevel, _status_init, _len_max) \
110 static K_MUTEX_DEFINE(_CONCAT(_nsms, _status_mtx)); \
111 static char _CONCAT(_nsms, _status_buf)[_len_max] = _status_init; \
112 static const struct bt_nsms_status_str _CONCAT(_nsms, _status_str) = { \
113 .mtx = &_CONCAT(_nsms, _status_mtx), \
114 .size = (_len_max), \
115 .buf = _CONCAT(_nsms, _status_buf) \
117 BT_NSMS_SERVICE_DEF(_CONCAT(_nsms, _svc), \
118 BT_GATT_PRIMARY_SERVICE(BT_UUID_NSMS_SERVICE), \
119 BT_GATT_CHARACTERISTIC(BT_UUID_NSMS_STATUS, \
120 BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
121 _BT_NSMS_CH_READ_PERM(_slevel), \
122 bt_nsms_status_read, \
124 (void *)&_CONCAT(_nsms, _status_str)), \
125 BT_GATT_CCC(NULL, _BT_NSMS_CH_READ_PERM(_slevel) | \
126 _BT_NSMS_CH_WRITE_PERM(_slevel)), \
127 BT_GATT_CUD(_name, _BT_NSMS_CH_READ_PERM(_slevel)), \
129 static const struct bt_nsms _nsms = { \
130 .status_attr = &_CONCAT(_nsms, _svc).attrs[2], \
int bt_nsms_set_status(const struct bt_nsms *nsms_obj, const char *status)
Set status.
ssize_t bt_nsms_status_read(struct bt_conn *conn, struct bt_gatt_attr const *attr, void *buf, uint16_t len, uint16_t offset)
Nordic Status Message Service reading command.
struct k_mutex * mtx
Definition: nsms.h:42
size_t size
Definition: nsms.h:44
char * buf
Definition: nsms.h:46
The status.
Definition: nsms.h:40
const struct bt_gatt_attr * status_attr
Definition: nsms.h:55
Nordic Status Message Service structure.
Definition: nsms.h:53